controller: remove convenience api for control sources
[platform/upstream/gstreamer.git] / tests / examples / controller / audio-example.c
1 /*
2  * audio-example.c
3  *
4  * Builds a pipeline with [ audiotestsource ! autoaudiosink ] and sweeps
5  * frequency and volume.
6  *
7  * Needs gst-plugin-base + gst-plugins-good installed.
8  */
9
10 #include <gst/gst.h>
11 #include <gst/controller/gstinterpolationcontrolsource.h>
12
13 gint
14 main (gint argc, gchar ** argv)
15 {
16   gint res = 1;
17   GstElement *src, *sink;
18   GstElement *bin;
19   GstInterpolationControlSource *csource1, *csource2;
20   GstTimedValueControlSource *cs;
21   GstClock *clock;
22   GstClockID clock_id;
23   GstClockReturn wait_ret;
24
25   gst_init (&argc, &argv);
26
27   /* build pipeline */
28   bin = gst_pipeline_new ("pipeline");
29   clock = gst_pipeline_get_clock (GST_PIPELINE (bin));
30   src = gst_element_factory_make ("audiotestsrc", NULL);
31   if (!src) {
32     GST_WARNING ("need audiotestsrc from gst-plugins-base");
33     goto Error;
34   }
35   sink = gst_element_factory_make ("autoaudiosink", NULL);
36   if (!sink) {
37     GST_WARNING ("need autoaudiosink from gst-plugins-good");
38     goto Error;
39   }
40
41   gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
42   if (!gst_element_link (src, sink)) {
43     GST_WARNING ("can't link elements");
44     goto Error;
45   }
46
47   /* setup control sources */
48   csource1 = gst_interpolation_control_source_new ();
49   csource2 = gst_interpolation_control_source_new ();
50
51   gst_object_set_control_binding (GST_OBJECT_CAST (src),
52       gst_control_binding_new (GST_OBJECT_CAST (src), "volume",
53           GST_CONTROL_SOURCE (csource1)));
54   gst_object_set_control_binding (GST_OBJECT_CAST (src),
55       gst_control_binding_new (GST_OBJECT_CAST (src), "freq",
56           GST_CONTROL_SOURCE (csource2)));
57
58   /* set interpolation mode */
59
60   g_object_set (csource1, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
61   g_object_set (csource2, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
62
63   /* set control values */
64   cs = (GstTimedValueControlSource *) csource1;
65   gst_timed_value_control_source_set (cs, 0 * GST_SECOND, 0.0);
66   gst_timed_value_control_source_set (cs, 5 * GST_SECOND, 1.0);
67
68   gst_object_unref (csource1);
69
70   cs = (GstTimedValueControlSource *) csource2;
71   gst_timed_value_control_source_set (cs, 0 * GST_SECOND, 220.0 / 20000.0);
72   gst_timed_value_control_source_set (cs, 3 * GST_SECOND, 3520.0 / 20000.0);
73   gst_timed_value_control_source_set (cs, 6 * GST_SECOND, 440.0 / 20000.0);
74
75   gst_object_unref (csource2);
76
77   /* run for 7 seconds */
78   clock_id =
79       gst_clock_new_single_shot_id (clock,
80       gst_clock_get_time (clock) + (7 * GST_SECOND));
81
82   if (gst_element_set_state (bin, GST_STATE_PLAYING)) {
83     if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
84       GST_WARNING ("clock_id_wait returned: %d", wait_ret);
85     }
86     gst_element_set_state (bin, GST_STATE_NULL);
87   }
88
89   /* cleanup */
90   gst_clock_id_unref (clock_id);
91   gst_object_unref (G_OBJECT (clock));
92   gst_object_unref (G_OBJECT (bin));
93   res = 0;
94 Error:
95   return (res);
96 }