2 * Copyright (C) 2009 Stefan Kost <ensonic@users.sf.net>
4 * controller.c: benchmark for interpolation control-source
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include <gst/controller/gstcontroller.h>
24 #include <gst/controller/gstinterpolationcontrolsource.h>
26 /* a song in buzztard can easily reach 30000 here */
31 event_loop (GstElement * pipe)
34 GstMessage *message = NULL;
36 bus = gst_element_get_bus (GST_ELEMENT (pipe));
39 message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
41 g_assert (message != NULL);
43 switch (message->type) {
45 gst_message_unref (message);
47 case GST_MESSAGE_WARNING:
48 case GST_MESSAGE_ERROR:{
52 gst_message_parse_error (message, &gerror, &debug);
53 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
54 gst_message_unref (message);
55 g_error_free (gerror);
60 gst_message_unref (message);
67 main (gint argc, gchar * argv[])
71 GstElement *src, *sink;
74 GstInterpolationControlSource *csource;
77 GstClockTimeDiff elapsed;
80 gst_init (&argc, &argv);
81 gst_controller_init (&argc, &argv);
84 bin = gst_pipeline_new ("pipeline");
85 src = gst_element_factory_make ("audiotestsrc", "gen_audio");
87 GST_WARNING ("need audiotestsrc from gst-plugins-base");
90 sink = gst_element_factory_make ("fakesink", "swallow_audio");
92 gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
93 if (!gst_element_link (src, sink)) {
94 GST_WARNING ("can't link elements");
98 g_object_set (G_OBJECT (src), "wave", 7, /* sine table - we don't want to benchmark the fpu */
99 "num-buffers", NUM_CP, "samplesperbuffer", BLOCK_SIZE, NULL);
101 tick = BLOCK_SIZE * GST_SECOND / 44100;
103 /* add a controller to the source */
104 if (!(ctrl = gst_controller_new (G_OBJECT (src), "freq", NULL))) {
105 GST_WARNING ("can't control source element");
109 /* create and configure control source */
110 csource = gst_interpolation_control_source_new ();
111 gst_controller_set_control_source (ctrl, "freq",
112 GST_CONTROL_SOURCE (csource));
113 gst_interpolation_control_source_set_interpolation_mode (csource,
114 GST_INTERPOLATE_LINEAR);
115 g_value_init (&freq, G_TYPE_DOUBLE);
118 /* set control values, we set them in a linear order as we would when loading
121 bt = gst_util_get_timestamp ();
123 for (i = 0; i < NUM_CP; i++) {
124 g_value_set_double (&freq, g_random_double_range (50.0, 3000.0));
125 gst_interpolation_control_source_set (csource, i * tick, &freq);
128 ct = gst_util_get_timestamp ();
129 elapsed = GST_CLOCK_DIFF (bt, ct);
130 printf ("linear insert of control-points: %" GST_TIME_FORMAT "\n",
131 GST_TIME_ARGS (elapsed));
134 /* set extra control values, we set them in arbitrary order to simulate
135 * the user editing a project from the ui
137 bt = gst_util_get_timestamp ();
139 for (i = 0; i < 100; i++) {
140 j = g_random_int_range (0, NUM_CP - 1);
141 g_value_set_double (&freq, g_random_double_range (50.0, 3000.0));
142 gst_interpolation_control_source_set (csource, j * tick, &freq);
145 ct = gst_util_get_timestamp ();
146 elapsed = GST_CLOCK_DIFF (bt, ct);
147 printf ("random insert of control-points: %" GST_TIME_FORMAT "\n",
148 GST_TIME_ARGS (elapsed));
150 g_object_unref (csource);
152 /* play, this test sequential reads */
153 bt = gst_util_get_timestamp ();
155 if (gst_element_set_state (bin, GST_STATE_PLAYING)) {
158 gst_element_set_state (bin, GST_STATE_NULL);
161 ct = gst_util_get_timestamp ();
162 elapsed = GST_CLOCK_DIFF (bt, ct);
163 printf ("linear read of control-points: %" GST_TIME_FORMAT "\n",
164 GST_TIME_ARGS (elapsed));
167 g_object_unref (G_OBJECT (ctrl));
168 gst_object_unref (G_OBJECT (bin));