whitespace fixes
[platform/upstream/gstreamer.git] / tests / old / examples / controller / audio-example.c
1 /*
2  * audio-example.c
3  *
4  * Build a pipeline with testaudiosource->alsasink
5  * and sweep frequency and volume
6  *
7  */
8
9 #include <gst/gst.h>
10 #include <gst/controller/gst-controller.h>
11
12 gint
13 main (gint argc, gchar ** argv)
14 {
15   gint res = 1;
16   GstElement *src, *sink;
17   GstElement *bin;
18   GstController *ctrl;
19   GstClock *clock;
20   GstClockID clock_id;
21   GstClockReturn wait_ret;
22   GValue vol = { 0, };
23
24   gst_init (&argc, &argv);
25   gst_controller_init (&argc, &argv);
26
27   // build pipeline
28   bin = gst_pipeline_new ("pipeline");
29   clock = gst_pipeline_get_clock (GST_PIPELINE (bin));
30   /* TODO make this "testaudiosrc", when its ready */
31   src = gst_element_factory_make ("sinesrc", "gen_audio");
32   sink = gst_element_factory_make ("alsasink", "play_audio");
33   gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
34   if (!gst_element_link (src, sink)) {
35     GST_WARNING ("can't link elements");
36     goto Error;
37   }
38   // add a controller to the source
39   if (!(ctrl = gst_controller_new (G_OBJECT (src), "freq", "volume", NULL))) {
40     GST_WARNING ("can't control source element");
41     goto Error;
42   }
43   // set interpolation
44   gst_controller_set_interpolation_mode (ctrl, "volume",
45       GST_INTERPOLATE_LINEAR);
46   gst_controller_set_interpolation_mode (ctrl, "freq", GST_INTERPOLATE_LINEAR);
47
48   // set control values
49   g_value_init (&vol, G_TYPE_DOUBLE);
50   g_value_set_double (&vol, 0.0);
51   gst_controller_set (ctrl, "volume", 0 * GST_SECOND, &vol);
52   g_value_set_double (&vol, 1.0);
53   gst_controller_set (ctrl, "volume", 5 * GST_SECOND, &vol);
54   g_value_set_double (&vol, 440.0);
55   gst_controller_set (ctrl, "freq", 0 * GST_SECOND, &vol);
56   g_value_set_double (&vol, 3520.0);
57   gst_controller_set (ctrl, "freq", 3 * GST_SECOND, &vol);
58   g_value_set_double (&vol, 880.0);
59   gst_controller_set (ctrl, "freq", 6 * GST_SECOND, &vol);
60
61   clock_id =
62       gst_clock_new_single_shot_id (clock,
63       gst_clock_get_time (clock) + (7 * GST_SECOND));
64
65   // run for 7 seconds
66   if (gst_element_set_state (bin, GST_STATE_PLAYING)) {
67     if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
68       GST_WARNING ("clock_id_wait returned: %d", wait_ret);
69     }
70     gst_element_set_state (bin, GST_STATE_NULL);
71   }
72   // cleanup
73   g_object_unref (G_OBJECT (ctrl));
74   g_object_unref (G_OBJECT (clock));
75   g_object_unref (G_OBJECT (bin));
76   res = 0;
77 Error:
78   return (res);
79 }