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.
25 #include <gst/controller/gstinterpolationcontrolsource.h>
27 /* a song in buzztard can easily reach 30000 here */
32 event_loop (GstElement * pipe)
35 GstMessage *message = NULL;
36 gboolean running = TRUE;
38 bus = gst_element_get_bus (GST_ELEMENT (pipe));
41 message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
43 g_assert (message != NULL);
45 switch (message->type) {
49 case GST_MESSAGE_WARNING:{
53 gst_message_parse_warning (message, &gerror, &debug);
54 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
55 g_error_free (gerror);
59 case GST_MESSAGE_ERROR:{
63 gst_message_parse_error (message, &gerror, &debug);
64 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
65 g_error_free (gerror);
73 gst_message_unref (message);
75 gst_object_unref (bus);
79 main (gint argc, gchar * argv[])
83 GstElement *src, *sink;
85 GstInterpolationControlSource *csource;
87 GstClockTimeDiff elapsed;
90 gst_init (&argc, &argv);
93 bin = gst_pipeline_new ("pipeline");
94 src = gst_element_factory_make ("audiotestsrc", "gen_audio");
96 GST_WARNING ("need audiotestsrc from gst-plugins-base");
99 sink = gst_element_factory_make ("fakesink", "swallow_audio");
101 gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
102 if (!gst_element_link (src, sink)) {
103 GST_WARNING ("can't link elements");
107 g_object_set (G_OBJECT (src), "wave", 7, /* sine table - we don't want to benchmark the fpu */
108 "num-buffers", NUM_CP, "samplesperbuffer", BLOCK_SIZE, NULL);
110 tick = BLOCK_SIZE * GST_SECOND / 44100;
112 /* create and configure control source */
113 csource = gst_interpolation_control_source_new ();
114 gst_object_set_control_source (GST_OBJECT (src), "freq",
115 GST_CONTROL_SOURCE (csource));
116 g_object_set (csource, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
119 /* set control values, we set them in a linear order as we would when loading
122 bt = gst_util_get_timestamp ();
124 for (i = 0; i < NUM_CP; i++) {
125 gst_timed_value_control_source_set ((GstTimedValueControlSource *) csource,
126 i * tick, g_random_double_range (50.0, 3000.0));
129 ct = gst_util_get_timestamp ();
130 elapsed = GST_CLOCK_DIFF (bt, ct);
131 printf ("linear insert of control-points: %" GST_TIME_FORMAT "\n",
132 GST_TIME_ARGS (elapsed));
135 /* set extra control values, we set them in arbitrary order to simulate
136 * the user editing a project from the ui
138 bt = gst_util_get_timestamp ();
140 for (i = 0; i < 100; i++) {
141 j = g_random_int_range (0, NUM_CP - 1);
142 gst_timed_value_control_source_set ((GstTimedValueControlSource *) csource,
143 j * tick, g_random_double_range (50.0, 3000.0));
146 ct = gst_util_get_timestamp ();
147 elapsed = GST_CLOCK_DIFF (bt, ct);
148 printf ("random insert of control-points: %" GST_TIME_FORMAT "\n",
149 GST_TIME_ARGS (elapsed));
152 GstClockTime sample_duration =
153 gst_util_uint64_scale_int (1, GST_SECOND, 44100);
154 gdouble *values = g_new0 (gdouble, BLOCK_SIZE * NUM_CP);
156 bt = gst_util_get_timestamp ();
157 gst_control_source_get_value_array (GST_CONTROL_SOURCE (csource), 0,
158 sample_duration, BLOCK_SIZE * NUM_CP, values);
159 ct = gst_util_get_timestamp ();
161 elapsed = GST_CLOCK_DIFF (bt, ct);
162 printf ("linear array for control-points: %" GST_TIME_FORMAT "\n",
163 GST_TIME_ARGS (elapsed));
166 gst_object_unref (csource);
168 /* play, this test sequential reads */
169 bt = gst_util_get_timestamp ();
171 if (gst_element_set_state (bin, GST_STATE_PLAYING)) {
174 gst_element_set_state (bin, GST_STATE_NULL);
177 ct = gst_util_get_timestamp ();
178 elapsed = GST_CLOCK_DIFF (bt, ct);
179 printf ("linear read of control-points : %" GST_TIME_FORMAT "\n",
180 GST_TIME_ARGS (elapsed));
183 gst_object_unref (G_OBJECT (bin));