4 * Generates a datafile for various control sources.
6 * Needs gnuplot for plotting.
7 * plot "ctrl_i1.dat" using 1:2 with points title 'none', "" using 1:3 with points title 'linear', "" using 1:4 with points title 'cubic', "ctrl_i2.dat" using 1:2 with lines title 'none', "" using 1:3 with lines title 'linear', "" using 1:4 with lines title 'cubic'
8 * plot "ctrl_l1.dat" using 1:2 with points title 'sine', "" using 1:3 with points title 'square', "" using 1:4 with points title 'saw', "" using 1:5 with points title 'revsaw', "" using 1:6 with points title 'triangle', "ctrl_l2.dat" using 1:2 with lines title 'sine', "" using 1:3 with lines title 'square', "" using 1:4 with lines title 'saw', "" using 1:5 with lines title 'revsaw', "" using 1:6 with lines title 'triangle'
9 * plot "ctrl_cl1.dat" using 1:2 with points title 'sine', "ctrl_cl2.dat" using 1:2 with lines title 'sine'
16 #include <gst/controller/gstinterpolationcontrolsource.h>
17 #include <gst/controller/gstlfocontrolsource.h>
19 /* local test element */
30 #define GST_TYPE_TEST_OBJ (gst_test_obj_get_type ())
31 #define GST_TEST_OBJ(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_TEST_OBJ, GstTestObj))
32 #define GST_TEST_OBJ_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_TEST_OBJ, GstTestObjClass))
33 #define GST_IS_TEST_OBJ(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TEST_OBJ))
34 #define GST_IS_TEST_OBJ_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_TEST_OBJ))
35 #define GST_TEST_OBJ_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_TEST_OBJ, GstTestObjClass))
37 typedef struct _GstTestObj GstTestObj;
38 typedef struct _GstTestObjClass GstTestObjClass;
48 struct _GstTestObjClass
50 GstElementClass parent_class;
53 static GType gst_test_obj_get_type (void);
56 gst_test_obj_get_property (GObject * object,
57 guint property_id, GValue * value, GParamSpec * pspec)
59 GstTestObj *self = GST_TEST_OBJ (object);
61 switch (property_id) {
63 g_value_set_int (value, self->val_int);
66 g_value_set_float (value, self->val_float);
69 g_value_set_double (value, self->val_double);
72 g_value_set_boolean (value, self->val_boolean);
75 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
81 gst_test_obj_set_property (GObject * object,
82 guint property_id, const GValue * value, GParamSpec * pspec)
84 GstTestObj *self = GST_TEST_OBJ (object);
86 switch (property_id) {
88 self->val_int = g_value_get_int (value);
89 GST_DEBUG ("test value int=%d", self->val_int);
92 self->val_float = g_value_get_float (value);
93 GST_DEBUG ("test value float=%f", self->val_float);
96 self->val_double = g_value_get_double (value);
97 GST_DEBUG ("test value double=%f", self->val_double);
100 self->val_boolean = g_value_get_boolean (value);
101 GST_DEBUG ("test value boolean=%d", self->val_boolean);
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
110 gst_test_obj_class_init (GstTestObjClass * klass)
112 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
114 gobject_class->set_property = gst_test_obj_set_property;
115 gobject_class->get_property = gst_test_obj_get_property;
117 g_object_class_install_property (gobject_class, PROP_INT,
118 g_param_spec_int ("int",
120 "int number parameter for the TEST_OBJ",
121 0, 100, 0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
123 g_object_class_install_property (gobject_class, PROP_FLOAT,
124 g_param_spec_float ("float",
126 "float number parameter for the TEST_OBJ",
127 0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
129 g_object_class_install_property (gobject_class, PROP_DOUBLE,
130 g_param_spec_double ("double",
132 "double number parameter for the TEST_OBJ",
133 0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
135 g_object_class_install_property (gobject_class, PROP_BOOLEAN,
136 g_param_spec_boolean ("boolean",
138 "boolean parameter for the TEST_OBJ",
139 FALSE, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
143 gst_test_obj_base_init (GstTestObjClass * klass)
145 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
147 gst_element_class_set_details_simple (element_class,
148 "test object for unit tests",
149 "Test", "Use in unit tests", "Stefan Sauer <ensonic@users.sf.net>");
153 gst_test_obj_get_type (void)
155 static volatile gsize TEST_OBJ_type = 0;
157 if (g_once_init_enter (&TEST_OBJ_type)) {
159 static const GTypeInfo info = {
160 (guint16) sizeof (GstTestObjClass),
161 (GBaseInitFunc) gst_test_obj_base_init, // base_init
162 NULL, // base_finalize
163 (GClassInitFunc) gst_test_obj_class_init, // class_init
164 NULL, // class_finalize
166 (guint16) sizeof (GstTestObj),
168 NULL, // instance_init
171 type = g_type_register_static (GST_TYPE_ELEMENT, "GstTestObj", &info, 0);
172 g_once_init_leave (&TEST_OBJ_type, type);
174 return TEST_OBJ_type;
178 test_interpolation (void)
181 GstInterpolationControlSource *ics;
182 GstTimedValueControlSource *tvcs;
183 GstControlSource *cs;
185 GValue *v1, *v2, *v3;
189 e = (GstObject *) gst_element_factory_make ("testobj", NULL);
191 ics = gst_interpolation_control_source_new ();
192 tvcs = (GstTimedValueControlSource *) ics;
193 cs = (GstControlSource *) ics;
195 gst_object_set_control_source (e, "int", cs);
197 gst_timed_value_control_source_set (tvcs, 0 * GST_SECOND, 0.0);
198 gst_timed_value_control_source_set (tvcs, 10 * GST_SECOND, 1.0);
199 gst_timed_value_control_source_set (tvcs, 20 * GST_SECOND, 0.5);
200 gst_timed_value_control_source_set (tvcs, 30 * GST_SECOND, 0.2);
202 /* test single values */
203 if (!(f = fopen ("ctrl_i1.dat", "w")))
205 fprintf (f, "# Time None Linear Cubic\n");
207 for (t = 0; t < 40; t++) {
208 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_NONE, NULL);
209 gst_object_sync_values (e, t * GST_SECOND);
210 i1 = GST_TEST_OBJ (e)->val_int;
212 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
213 gst_object_sync_values (e, t * GST_SECOND);
214 i2 = GST_TEST_OBJ (e)->val_int;
216 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_CUBIC, NULL);
217 gst_object_sync_values (e, t * GST_SECOND);
218 i3 = GST_TEST_OBJ (e)->val_int;
220 fprintf (f, "%4.1f %d %d %d\n", (gfloat) t, i1, i2, i3);
225 /* test value arrays */
226 if (!(f = fopen ("ctrl_i2.dat", "w")))
228 fprintf (f, "# Time None Linear Cubic\n");
231 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_NONE, NULL);
232 v1 = g_new0 (GValue, n_values);
233 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
235 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
236 v2 = g_new0 (GValue, n_values);
237 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v2);
239 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_CUBIC, NULL);
240 v3 = g_new0 (GValue, n_values);
241 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v3);
243 for (t = 0; t < n_values; t++) {
244 i1 = g_value_get_int (&v1[t]);
245 i2 = g_value_get_int (&v2[t]);
246 i3 = g_value_get_int (&v3[t]);
247 fprintf (f, "%4.1f %d %d %d\n", (gfloat) t / 10.0, i1, i2, i3);
248 g_value_unset (&v1[t]);
249 g_value_unset (&v2[t]);
250 g_value_unset (&v3[t]);
258 gst_object_unref (ics);
259 gst_object_unref (e);
266 GstLFOControlSource *lfocs;
267 GstControlSource *cs;
268 gint t, i1, i2, i3, i4, i5;
269 GValue *v1, *v2, *v3, *v4, *v5;
273 e = (GstObject *) gst_element_factory_make ("testobj", NULL);
275 lfocs = gst_lfo_control_source_new ();
276 cs = (GstControlSource *) lfocs;
278 gst_object_set_control_source (e, "int", cs);
281 "frequency", (gdouble) 0.05,
282 "timeshift", (GstClockTime) 0,
283 "amplitude", (gdouble) 0.5, "offset", (gdouble) 0.5, NULL);
285 /* test single values */
286 if (!(f = fopen ("ctrl_l1.dat", "w")))
288 fprintf (f, "# Time Sine Square Saw RevSaw Triangle\n");
290 for (t = 0; t < 40; t++) {
291 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SINE, NULL);
292 gst_object_sync_values (e, t * GST_SECOND);
293 i1 = GST_TEST_OBJ (e)->val_int;
295 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SQUARE, NULL);
296 gst_object_sync_values (e, t * GST_SECOND);
297 i2 = GST_TEST_OBJ (e)->val_int;
299 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SAW, NULL);
300 gst_object_sync_values (e, t * GST_SECOND);
301 i3 = GST_TEST_OBJ (e)->val_int;
303 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_REVERSE_SAW, NULL);
304 gst_object_sync_values (e, t * GST_SECOND);
305 i4 = GST_TEST_OBJ (e)->val_int;
307 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_TRIANGLE, NULL);
308 gst_object_sync_values (e, t * GST_SECOND);
309 i5 = GST_TEST_OBJ (e)->val_int;
311 fprintf (f, "%4.1f %d %d %d %d %d\n", (gfloat) t, i1, i2, i3, i4, i5);
316 /* test value arrays */
317 if (!(f = fopen ("ctrl_l2.dat", "w")))
319 fprintf (f, "# Time Sine Square Saw RevSaw Triangle\n");
322 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SINE, NULL);
323 v1 = g_new0 (GValue, n_values);
324 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
326 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SQUARE, NULL);
327 v2 = g_new0 (GValue, n_values);
328 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v2);
330 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SAW, NULL);
331 v3 = g_new0 (GValue, n_values);
332 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v3);
334 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_REVERSE_SAW, NULL);
335 v4 = g_new0 (GValue, n_values);
336 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v4);
338 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_TRIANGLE, NULL);
339 v5 = g_new0 (GValue, n_values);
340 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v5);
342 for (t = 0; t < n_values; t++) {
343 i1 = g_value_get_int (&v1[t]);
344 i2 = g_value_get_int (&v2[t]);
345 i3 = g_value_get_int (&v3[t]);
346 i4 = g_value_get_int (&v4[t]);
347 i5 = g_value_get_int (&v5[t]);
348 fprintf (f, "%4.1f %d %d %d %d %d\n", (gfloat) t / 10.0, i1, i2, i3, i4,
350 g_value_unset (&v1[t]);
351 g_value_unset (&v2[t]);
352 g_value_unset (&v3[t]);
353 g_value_unset (&v4[t]);
354 g_value_unset (&v5[t]);
364 gst_object_unref (lfocs);
365 gst_object_unref (e);
369 test_chained_lfo (void)
372 GstLFOControlSource *lfocs1, *lfocs2;
373 GstControlSource *cs1, *cs2;
379 e = (GstObject *) gst_element_factory_make ("testobj", NULL);
381 lfocs1 = gst_lfo_control_source_new ();
382 cs1 = (GstControlSource *) lfocs1;
384 gst_object_set_control_source (e, "int", cs1);
386 g_object_set (lfocs1,
387 "waveform", GST_LFO_WAVEFORM_SINE,
388 "frequency", (gdouble) 0.05,
389 "timeshift", (GstClockTime) 0, "offset", (gdouble) 0.5, NULL);
391 lfocs2 = gst_lfo_control_source_new ();
392 cs2 = (GstControlSource *) lfocs2;
394 gst_object_set_control_source ((GstObject *) lfocs1, "amplitude", cs2);
396 g_object_set (lfocs2,
397 "waveform", GST_LFO_WAVEFORM_SINE,
398 "frequency", (gdouble) 0.05,
399 "timeshift", (GstClockTime) 0,
400 "amplitude", (gdouble) 0.5, "offset", (gdouble) 0.5, NULL);
402 /* test single values */
403 if (!(f = fopen ("ctrl_cl1.dat", "w")))
405 fprintf (f, "# Time Sine\n");
407 for (t = 0; t < 40; t++) {
408 gst_object_sync_values (e, t * GST_SECOND);
409 i1 = GST_TEST_OBJ (e)->val_int;
411 fprintf (f, "%4.1f %d\n", (gfloat) t, i1);
416 /* test value arrays */
417 if (!(f = fopen ("ctrl_cl2.dat", "w")))
419 fprintf (f, "# Time Sine\n");
422 v1 = g_new0 (GValue, n_values);
423 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
425 for (t = 0; t < n_values; t++) {
426 i1 = g_value_get_int (&v1[t]);
427 fprintf (f, "%4.1f %d\n", (gfloat) t / 10.0, i1);
428 g_value_unset (&v1[t]);
434 gst_object_unref (lfocs1);
435 gst_object_unref (lfocs2);
436 gst_object_unref (e);
440 main (gint argc, gchar ** argv)
442 gst_init (&argc, &argv);
444 gst_element_register (NULL, "testobj", GST_RANK_NONE, GST_TYPE_TEST_OBJ);
446 test_interpolation ();