mixer.c 5.02 KB
Newer Older
Wim Taymans's avatar
Wim Taymans committed
1 2 3 4 5 6
#include <stdlib.h>
#include <gst/gst.h>

gboolean playing;

/* example based on helloworld by thomas@apestaart.org
7 8
   demonstrates the adder plugin and the volume envelope plugin 
   work in progress but do try it out */
Wim Taymans's avatar
Wim Taymans committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

/* 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 <filename1> <filename2>\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 */

124 125 126 127 128 129 130
  gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "0:0.000001", NULL);
  gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "5:0.000001", NULL);
  gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "10:1", NULL);
  gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "15:1", NULL);
  gtk_object_set(GTK_OBJECT(volenv1), "controlpoint", "20:0.000001", NULL);

  gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "0:1", NULL);
Wim Taymans's avatar
Wim Taymans committed
131
  gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "5:1", NULL);
132 133 134
  gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "10:0.000001", NULL);
  gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "15:0.000001", NULL);
  gtk_object_set(GTK_OBJECT(volenv2), "controlpoint", "20:1", NULL);
Wim Taymans's avatar
Wim Taymans committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

  /* 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);
}