Swapping Channels with Audioconvert's mix-matrix

Mariano Koremblum nicolas.koremblum at globant.com
Tue Jul 28 15:49:07 UTC 2020


Hi devs!

I am struggling with the audioconvert's mix-matrix property. I have a two
channel input wav file and the idea is to swap the channels in the middle of
the stream, but I am not even able of swapping them in the start, don't know
why. 

First I tried to do this: 
g_object_set(convert, "mix-matrix", "<<(float)1.0, (float)0.0>, <(float)0.0,
(float)1.0>>", NULL);
But I've only got "core dump" error when doing so. Then I tried the way it
shows on this link:
https://gstreamer.freedesktop.org/documentation/audioconvert/index.html?gi-language=c
and this is the result:

/
int main(void)
{
    GMainLoop   *mainloop = NULL;
    GstElement  *pipeline = NULL;
    GstElement  *source = NULL, *sink = NULL;
    GstElement  *decode = NULL, *encode = NULL;
    GstElement  *convert = NULL;

    GValue matrix = G_VALUE_INIT;
    GValue vector = G_VALUE_INIT;
    GValue value = G_VALUE_INIT;

    gboolean res;

    gst_init(NULL, NULL);

    /* we need to run a GLib main mainloop to get the messages */
    mainloop = g_main_loop_new(NULL, FALSE);

    pipeline = gst_pipeline_new(NULL);
    g_assert(pipeline);

    source = gst_element_factory_make("filesrc", "source");
    g_assert(source);
    g_object_set(source, "location", "2-channels.wav", NULL);

    decode = gst_element_factory_make("wavparse", "decode");
    g_assert(decode);

    convert = gst_element_factory_make("audioconvert", "convert");
    g_assert(convert);

    /* ********** MIX-MATRIX SETUP & CONFIG ********** */

    g_value_init (&matrix, GST_TYPE_ARRAY);
    g_value_init (&vector, GST_TYPE_ARRAY);
    g_value_init (&value, G_TYPE_FLOAT);

    g_value_set_float (&value, 0.0);
    gst_value_array_append_value (&vector, &value);
    g_value_set_float (&value, 1.0);
    gst_value_array_append_value (&vector, &value);

    gst_value_array_append_value (&matrix, &vector);
    g_value_unset (&vector);

    g_value_init (&vector, GST_TYPE_ARRAY);

    g_value_set_float (&value, 1.0);
    gst_value_array_append_value (&vector, &value);
    g_value_set_float (&value, 0.0);
    gst_value_array_append_value (&vector, &value);
    g_value_unset (&value);
    
    gst_value_array_append_value (&matrix, &vector);
    g_value_unset (&vector);

    g_object_set_property (G_OBJECT (convert), "mix-matrix", &matrix);
    g_value_unset (&matrix);

    /* ********** END OF MIX-MATRIX ********** */

    encode = gst_element_factory_make("wavenc", "encode");
    g_assert(encode);

    sink = gst_element_factory_make("filesink", "sink");
    g_assert(sink);
    g_object_set(sink, "location", "out.wav", "sync", true, NULL);

    gst_bin_add_many(GST_BIN(pipeline), source, decode, convert, encode,
sink, NULL);

    res = gst_element_link_many(source, decode, convert, encode, sink,
NULL);
    g_assert(res == TRUE);

    g_print("Starting pipeline\n\n");
    gst_element_set_state(pipeline, GST_STATE_PLAYING);

    g_main_loop_run(mainloop);

    g_print("Stopping pipeline\n");
    gst_element_set_state(pipeline, GST_STATE_NULL);

    gst_object_unref(pipeline);

    return 0;
}
/


Does anyone know if I am doing something wrong? I really appreciate your
advises and tips :D

Thanks in Advance!!



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/


More information about the gstreamer-devel mailing list