From d0921a2897cd1aa62b8d19074941b7c67e976069 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 16 Apr 2001 16:34:16 +0000 Subject: [PATCH] Added an example audio mixer. Original commit message from CVS: Added an example audio mixer. --- examples/autoplug/autoplug.c | 6 +- examples/mixer/.gitignore | 1 + examples/mixer/Makefile.am | 4 + examples/mixer/mixer.c | 168 +++++++++++++++++++++++++++++++++ tests/old/examples/autoplug/autoplug.c | 6 +- tests/old/examples/mixer/.gitignore | 1 + tests/old/examples/mixer/Makefile.am | 4 + tests/old/examples/mixer/mixer.c | 168 +++++++++++++++++++++++++++++++++ 8 files changed, 354 insertions(+), 4 deletions(-) create mode 100644 examples/mixer/.gitignore create mode 100644 examples/mixer/Makefile.am create mode 100644 examples/mixer/mixer.c create mode 100644 tests/old/examples/mixer/.gitignore create mode 100644 tests/old/examples/mixer/Makefile.am create mode 100644 tests/old/examples/mixer/mixer.c diff --git a/examples/autoplug/autoplug.c b/examples/autoplug/autoplug.c index 23acf5c..ce3b00e 100644 --- a/examples/autoplug/autoplug.c +++ b/examples/autoplug/autoplug.c @@ -9,8 +9,10 @@ gst_play_have_type (GstElement *sink, GstElement *sink2, gpointer data) *(gboolean *)data = TRUE; } -gboolean idle_func(gpointer data) { - return gst_bin_iterate(GST_BIN(data)); +gboolean +idle_func (gpointer data) +{ + return gst_bin_iterate (GST_BIN (data)); } static GstCaps* diff --git a/examples/mixer/.gitignore b/examples/mixer/.gitignore new file mode 100644 index 0000000..31e0fce --- /dev/null +++ b/examples/mixer/.gitignore @@ -0,0 +1 @@ +helloworld diff --git a/examples/mixer/Makefile.am b/examples/mixer/Makefile.am new file mode 100644 index 0000000..9c5573b --- /dev/null +++ b/examples/mixer/Makefile.am @@ -0,0 +1,4 @@ +noinst_PROGRAMS = mixer + +LIBS += $(GST_LIBS) +CFLAGS += $(GST_CFLAGS) diff --git a/examples/mixer/mixer.c b/examples/mixer/mixer.c new file mode 100644 index 0000000..8d3a54a --- /dev/null +++ b/examples/mixer/mixer.c @@ -0,0 +1,168 @@ +#include +#include + +gboolean playing; + +/* example based on helloworld by thomas@apestaart.org + demonstrates the adder plugin and the volume envelope plugin */ + +/* eos will be called when the src element has an end of stream */ +void eos(GstElement *element) +{ + g_print("have eos, quitting\n"); + + playing = FALSE; +} + +int main(int argc,char *argv[]) +{ + GstElement *bin_in1, *bin_in2, *main_bin; + GstElement *disksrc1, *decoder1, *volenv1; + GstElement *disksrc2, *decoder2, *volenv2; + GstElement *adder; + GstElement *audiosink; + + GstPad *pad; /* to request pads for the adder */ + + gst_init(&argc,&argv); + + if (argc != 3) { + g_print("usage: %s \n", argv[0]); + exit(-1); + } + + /* create input bins */ + + /* create bins to hold the input elements */ + bin_in1 = gst_bin_new("bin"); + bin_in2 = gst_bin_new("bin"); + + /* first input bin */ + + /* create elements */ + + disksrc1 = gst_elementfactory_make("disksrc", "disk_source1"); + gtk_object_set(GTK_OBJECT(disksrc1),"location", argv[1],NULL); + gtk_signal_connect(GTK_OBJECT(disksrc1),"eos", + GTK_SIGNAL_FUNC(eos),NULL); + decoder1 = gst_elementfactory_make("mad","decoder1"); + volenv1 = gst_elementfactory_make("volenv", "volume1"); + + /* add to the bin */ + + gst_bin_add(GST_BIN(bin_in1), disksrc1); + gst_bin_add(GST_BIN(bin_in1), decoder1); + gst_bin_add(GST_BIN(bin_in1), volenv1); + + /* connect elements */ + gst_pad_connect(gst_element_get_pad(disksrc1,"src"), + gst_element_get_pad(decoder1,"sink")); + gst_pad_connect(gst_element_get_pad(decoder1,"src"), + gst_element_get_pad(volenv1,"sink")); + + /* add a ghost pad */ + gst_element_add_ghost_pad (bin_in1, gst_element_get_pad (volenv1, "src"), "channel1"); + + /* second input bin */ + + /* create elements */ + + disksrc2 = gst_elementfactory_make("disksrc", "disk_source2"); + gtk_object_set(GTK_OBJECT(disksrc2),"location", argv[2],NULL); + gtk_signal_connect(GTK_OBJECT(disksrc2),"eos", + GTK_SIGNAL_FUNC(eos),NULL); + decoder2 = gst_elementfactory_make("mad","decoder2"); + volenv2 = gst_elementfactory_make("volenv", "volume2"); + + /* add to the bin */ + + gst_bin_add(GST_BIN(bin_in2), disksrc2); + gst_bin_add(GST_BIN(bin_in2), decoder2); + gst_bin_add(GST_BIN(bin_in2), volenv2); + + /* connect elements */ + gst_pad_connect(gst_element_get_pad(disksrc2,"src"), + gst_element_get_pad(decoder2,"sink")); + gst_pad_connect(gst_element_get_pad(decoder2,"src"), + gst_element_get_pad(volenv2,"sink")); + + /* add a ghost pad */ + gst_element_add_ghost_pad (bin_in2, gst_element_get_pad (volenv2, "src"), "channel2"); + + + /* create adder */ + adder = gst_elementfactory_make("adder", "adderel"); + + /* create an audio sink */ + audiosink = gst_elementfactory_make("esdsink", "play_audio"); + + /* now create main bin */ + main_bin = gst_bin_new("bin"); + + gst_bin_add(GST_BIN(main_bin), bin_in1); + gst_bin_add(GST_BIN(main_bin), bin_in2); + gst_bin_add(GST_BIN(main_bin), adder); + gst_bin_add(GST_BIN(main_bin), audiosink); + + /* request pads and connect to adder */ + + pad = gst_element_request_pad_by_name (adder, "sink%d"); + g_print ("new pad %s\n", gst_pad_get_name (pad)); + gst_pad_connect (gst_element_get_pad (bin_in1, "channel1"), pad); + pad = gst_element_request_pad_by_name (adder, "sink%d"); + g_print ("new pad %s\n", gst_pad_get_name (pad)); + gst_pad_connect (gst_element_get_pad (bin_in2, "channel2"), pad); + + /* connect adder and audiosink */ + + gst_pad_connect(gst_element_get_pad(adder,"src"), + gst_element_get_pad(audiosink,"sink")); + + /* register the volume envelope */ + + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "0:0.0001", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "2:1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "4:1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "5:.1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "6:1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "7:.1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "8:1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "15:0.8", NULL); + + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "0:0.001", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "4:0.001", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "5:1", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "6:.1", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "7:1", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "8:.1", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "15:0.001", NULL); + + /* start playing */ + gst_element_set_state(main_bin, GST_STATE_PLAYING); + + playing = TRUE; + + while (playing) { + gst_bin_iterate(GST_BIN(main_bin)); + } + + /* stop the bin */ + gst_element_set_state(main_bin, GST_STATE_NULL); + + gst_object_destroy(GST_OBJECT(audiosink)); + + gst_object_destroy(GST_OBJECT(disksrc1)); + gst_object_destroy(GST_OBJECT(decoder1)); + gst_object_destroy(GST_OBJECT(volenv1)); + + gst_object_destroy(GST_OBJECT(disksrc2)); + gst_object_destroy(GST_OBJECT(decoder2)); + gst_object_destroy(GST_OBJECT(volenv2)); + + gst_object_destroy(GST_OBJECT(bin_in1)); + gst_object_destroy(GST_OBJECT(bin_in2)); + gst_object_destroy(GST_OBJECT(main_bin)); + + exit(0); +} + diff --git a/tests/old/examples/autoplug/autoplug.c b/tests/old/examples/autoplug/autoplug.c index 23acf5c..ce3b00e 100644 --- a/tests/old/examples/autoplug/autoplug.c +++ b/tests/old/examples/autoplug/autoplug.c @@ -9,8 +9,10 @@ gst_play_have_type (GstElement *sink, GstElement *sink2, gpointer data) *(gboolean *)data = TRUE; } -gboolean idle_func(gpointer data) { - return gst_bin_iterate(GST_BIN(data)); +gboolean +idle_func (gpointer data) +{ + return gst_bin_iterate (GST_BIN (data)); } static GstCaps* diff --git a/tests/old/examples/mixer/.gitignore b/tests/old/examples/mixer/.gitignore new file mode 100644 index 0000000..31e0fce --- /dev/null +++ b/tests/old/examples/mixer/.gitignore @@ -0,0 +1 @@ +helloworld diff --git a/tests/old/examples/mixer/Makefile.am b/tests/old/examples/mixer/Makefile.am new file mode 100644 index 0000000..9c5573b --- /dev/null +++ b/tests/old/examples/mixer/Makefile.am @@ -0,0 +1,4 @@ +noinst_PROGRAMS = mixer + +LIBS += $(GST_LIBS) +CFLAGS += $(GST_CFLAGS) diff --git a/tests/old/examples/mixer/mixer.c b/tests/old/examples/mixer/mixer.c new file mode 100644 index 0000000..8d3a54a --- /dev/null +++ b/tests/old/examples/mixer/mixer.c @@ -0,0 +1,168 @@ +#include +#include + +gboolean playing; + +/* example based on helloworld by thomas@apestaart.org + demonstrates the adder plugin and the volume envelope plugin */ + +/* eos will be called when the src element has an end of stream */ +void eos(GstElement *element) +{ + g_print("have eos, quitting\n"); + + playing = FALSE; +} + +int main(int argc,char *argv[]) +{ + GstElement *bin_in1, *bin_in2, *main_bin; + GstElement *disksrc1, *decoder1, *volenv1; + GstElement *disksrc2, *decoder2, *volenv2; + GstElement *adder; + GstElement *audiosink; + + GstPad *pad; /* to request pads for the adder */ + + gst_init(&argc,&argv); + + if (argc != 3) { + g_print("usage: %s \n", argv[0]); + exit(-1); + } + + /* create input bins */ + + /* create bins to hold the input elements */ + bin_in1 = gst_bin_new("bin"); + bin_in2 = gst_bin_new("bin"); + + /* first input bin */ + + /* create elements */ + + disksrc1 = gst_elementfactory_make("disksrc", "disk_source1"); + gtk_object_set(GTK_OBJECT(disksrc1),"location", argv[1],NULL); + gtk_signal_connect(GTK_OBJECT(disksrc1),"eos", + GTK_SIGNAL_FUNC(eos),NULL); + decoder1 = gst_elementfactory_make("mad","decoder1"); + volenv1 = gst_elementfactory_make("volenv", "volume1"); + + /* add to the bin */ + + gst_bin_add(GST_BIN(bin_in1), disksrc1); + gst_bin_add(GST_BIN(bin_in1), decoder1); + gst_bin_add(GST_BIN(bin_in1), volenv1); + + /* connect elements */ + gst_pad_connect(gst_element_get_pad(disksrc1,"src"), + gst_element_get_pad(decoder1,"sink")); + gst_pad_connect(gst_element_get_pad(decoder1,"src"), + gst_element_get_pad(volenv1,"sink")); + + /* add a ghost pad */ + gst_element_add_ghost_pad (bin_in1, gst_element_get_pad (volenv1, "src"), "channel1"); + + /* second input bin */ + + /* create elements */ + + disksrc2 = gst_elementfactory_make("disksrc", "disk_source2"); + gtk_object_set(GTK_OBJECT(disksrc2),"location", argv[2],NULL); + gtk_signal_connect(GTK_OBJECT(disksrc2),"eos", + GTK_SIGNAL_FUNC(eos),NULL); + decoder2 = gst_elementfactory_make("mad","decoder2"); + volenv2 = gst_elementfactory_make("volenv", "volume2"); + + /* add to the bin */ + + gst_bin_add(GST_BIN(bin_in2), disksrc2); + gst_bin_add(GST_BIN(bin_in2), decoder2); + gst_bin_add(GST_BIN(bin_in2), volenv2); + + /* connect elements */ + gst_pad_connect(gst_element_get_pad(disksrc2,"src"), + gst_element_get_pad(decoder2,"sink")); + gst_pad_connect(gst_element_get_pad(decoder2,"src"), + gst_element_get_pad(volenv2,"sink")); + + /* add a ghost pad */ + gst_element_add_ghost_pad (bin_in2, gst_element_get_pad (volenv2, "src"), "channel2"); + + + /* create adder */ + adder = gst_elementfactory_make("adder", "adderel"); + + /* create an audio sink */ + audiosink = gst_elementfactory_make("esdsink", "play_audio"); + + /* now create main bin */ + main_bin = gst_bin_new("bin"); + + gst_bin_add(GST_BIN(main_bin), bin_in1); + gst_bin_add(GST_BIN(main_bin), bin_in2); + gst_bin_add(GST_BIN(main_bin), adder); + gst_bin_add(GST_BIN(main_bin), audiosink); + + /* request pads and connect to adder */ + + pad = gst_element_request_pad_by_name (adder, "sink%d"); + g_print ("new pad %s\n", gst_pad_get_name (pad)); + gst_pad_connect (gst_element_get_pad (bin_in1, "channel1"), pad); + pad = gst_element_request_pad_by_name (adder, "sink%d"); + g_print ("new pad %s\n", gst_pad_get_name (pad)); + gst_pad_connect (gst_element_get_pad (bin_in2, "channel2"), pad); + + /* connect adder and audiosink */ + + gst_pad_connect(gst_element_get_pad(adder,"src"), + gst_element_get_pad(audiosink,"sink")); + + /* register the volume envelope */ + + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "0:0.0001", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "2:1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "4:1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "5:.1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "6:1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "7:.1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "8:1", NULL); + gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "15:0.8", NULL); + + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "0:0.001", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "4:0.001", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "5:1", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "6:.1", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "7:1", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "8:.1", NULL); + gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "15:0.001", NULL); + + /* start playing */ + gst_element_set_state(main_bin, GST_STATE_PLAYING); + + playing = TRUE; + + while (playing) { + gst_bin_iterate(GST_BIN(main_bin)); + } + + /* stop the bin */ + gst_element_set_state(main_bin, GST_STATE_NULL); + + gst_object_destroy(GST_OBJECT(audiosink)); + + gst_object_destroy(GST_OBJECT(disksrc1)); + gst_object_destroy(GST_OBJECT(decoder1)); + gst_object_destroy(GST_OBJECT(volenv1)); + + gst_object_destroy(GST_OBJECT(disksrc2)); + gst_object_destroy(GST_OBJECT(decoder2)); + gst_object_destroy(GST_OBJECT(volenv2)); + + gst_object_destroy(GST_OBJECT(bin_in1)); + gst_object_destroy(GST_OBJECT(bin_in2)); + gst_object_destroy(GST_OBJECT(main_bin)); + + exit(0); +} + -- 2.7.4