sleort
sleort

Reputation: 193

How to swap left/right audio output dynamically in Gstreamer

I have a fixed positioned stereo microphone and a rotating camera.

How can I swap audio-channels dynamically in GStreamer, so that LEFT/RIGHT outputs either LEFT/RIGHT or RIGHT/LEFT in the earphones.

Currently I am able to swap them at startup, but once the stream is started, I cannot change it.

My pipeline in C would look like this:

gst-launch-1.0 alsasrc device=plughw:1,0  buffer-time=35000 ! 
    audio/x-raw,channels=2 ! audioamplify amplification=10.0 ! 
    deinterleave name=d interleave name=i ! pulsesink  d.src_0 ! 
    queue ! volume volume=1 ! i.sink_0 d.src_1 ! queue ! 
    volume volume=1 ! i.sink_1

This all works fine. Now if I want to swap the sinks, so that LEFT/RIGHT output becomes RIGHT/LEFT nothing happens. I can see on the documentation, that this probably wont work, by where it says_ "Changing the input caps is _not_ supported yet."

If for some reason you would like to see the code where it should change:

void cb_interleave_pad(GstElement *element, GstPad *pad, dizzy_elements *data) {
    gst_element_unlink(data->volume_1, data->interleave);
    gst_element_unlink(data->volume_2, data->interleave);
    gst_element_link_pads(data->volume_1, "src", data->interleave, "sink_1");
    gst_element_link_pads(data->volume_2, "src", data->interleave, "sink_0");
}

void cb_interleave_pad_reverse(GstElement *element, GstPad *pad, dizzy_elements *data) {
    gst_element_unlink(data->volume_1, data->interleave);
    gst_element_unlink(data->volume_2, data->interleave);
    gst_element_link_pads(data->volume_1, "src", data->interleave, "sink_0");
    gst_element_link_pads(data->volume_2, "src", data->interleave, "sink_1");
}

But of course, if this feature is not supported, it doesn't make sense to follow that route.

Therefore, is there another plugin/element that allows me to swap the left and right audio channels dynamically?

Upvotes: 0

Views: 1703

Answers (1)

Florian Zwoch
Florian Zwoch

Reputation: 7403

The audioconvert element has a mix-matrix property. This looks like you can do with it what you want. Check out it's documentation about that property:

https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-audioconvert.html

For stereo switching I believe this would look like this:

mix-matrix="<<(float)0.0, (float)1.0>, <(float)1.0, (float)0.0>>"

I haven't tried it though.

Upvotes: 2

Related Questions