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>
18 #include <gst/controller/gstcontrolbindingdirect.h>
20 /* local test element */
31 #define GST_TYPE_TEST_OBJ (gst_test_obj_get_type ())
32 #define GST_TEST_OBJ(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_TEST_OBJ, GstTestObj))
33 #define GST_TEST_OBJ_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_TEST_OBJ, GstTestObjClass))
34 #define GST_IS_TEST_OBJ(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_TEST_OBJ))
35 #define GST_IS_TEST_OBJ_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_TEST_OBJ))
36 #define GST_TEST_OBJ_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_TEST_OBJ, GstTestObjClass))
38 typedef struct _GstTestObj GstTestObj;
39 typedef struct _GstTestObjClass GstTestObjClass;
49 struct _GstTestObjClass
51 GstElementClass parent_class;
54 static GType gst_test_obj_get_type (void);
57 gst_test_obj_get_property (GObject * object,
58 guint property_id, GValue * value, GParamSpec * pspec)
60 GstTestObj *self = GST_TEST_OBJ (object);
62 switch (property_id) {
64 g_value_set_int (value, self->val_int);
67 g_value_set_float (value, self->val_float);
70 g_value_set_double (value, self->val_double);
73 g_value_set_boolean (value, self->val_boolean);
76 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
82 gst_test_obj_set_property (GObject * object,
83 guint property_id, const GValue * value, GParamSpec * pspec)
85 GstTestObj *self = GST_TEST_OBJ (object);
87 switch (property_id) {
89 self->val_int = g_value_get_int (value);
90 GST_DEBUG ("test value int=%d", self->val_int);
93 self->val_float = g_value_get_float (value);
94 GST_DEBUG ("test value float=%f", self->val_float);
97 self->val_double = g_value_get_double (value);
98 GST_DEBUG ("test value double=%f", self->val_double);
101 self->val_boolean = g_value_get_boolean (value);
102 GST_DEBUG ("test value boolean=%d", self->val_boolean);
105 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
111 gst_test_obj_class_init (GstTestObjClass * klass)
113 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
115 gobject_class->set_property = gst_test_obj_set_property;
116 gobject_class->get_property = gst_test_obj_get_property;
118 g_object_class_install_property (gobject_class, PROP_INT,
119 g_param_spec_int ("int",
121 "int number parameter",
122 0, 100, 0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
124 g_object_class_install_property (gobject_class, PROP_FLOAT,
125 g_param_spec_float ("float",
127 "float number parameter",
128 0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
130 g_object_class_install_property (gobject_class, PROP_DOUBLE,
131 g_param_spec_double ("double",
133 "double number parameter",
134 0.0, 100.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
136 g_object_class_install_property (gobject_class, PROP_BOOLEAN,
137 g_param_spec_boolean ("boolean",
140 FALSE, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
144 gst_test_obj_base_init (GstTestObjClass * klass)
146 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
148 gst_element_class_set_details_simple (element_class,
149 "test object for unit tests",
150 "Test", "Use in unit tests", "Stefan Sauer <ensonic@users.sf.net>");
154 gst_test_obj_get_type (void)
156 static volatile gsize TEST_OBJ_type = 0;
158 if (g_once_init_enter (&TEST_OBJ_type)) {
160 static const GTypeInfo info = {
161 (guint16) sizeof (GstTestObjClass),
162 (GBaseInitFunc) gst_test_obj_base_init, // base_init
163 NULL, // base_finalize
164 (GClassInitFunc) gst_test_obj_class_init, // class_init
165 NULL, // class_finalize
167 (guint16) sizeof (GstTestObj),
169 NULL, // instance_init
172 type = g_type_register_static (GST_TYPE_ELEMENT, "GstTestObj", &info, 0);
173 g_once_init_leave (&TEST_OBJ_type, type);
175 return TEST_OBJ_type;
179 test_interpolation (void)
182 GstInterpolationControlSource *ics;
183 GstTimedValueControlSource *tvcs;
184 GstControlSource *cs;
186 GValue *v1, *v2, *v3;
190 e = (GstObject *) gst_element_factory_make ("testobj", NULL);
192 ics = gst_interpolation_control_source_new ();
193 tvcs = (GstTimedValueControlSource *) ics;
194 cs = (GstControlSource *) ics;
196 gst_object_add_control_binding (e, gst_control_binding_direct_new (e, "int",
199 gst_timed_value_control_source_set (tvcs, 0 * GST_SECOND, 0.0);
200 gst_timed_value_control_source_set (tvcs, 10 * GST_SECOND, 1.0);
201 gst_timed_value_control_source_set (tvcs, 20 * GST_SECOND, 0.5);
202 gst_timed_value_control_source_set (tvcs, 30 * GST_SECOND, 0.2);
204 /* test single values */
205 if (!(f = fopen ("ctrl_i1.dat", "w")))
207 fprintf (f, "# Time None Linear Cubic\n");
209 for (t = 0; t < 40; t++) {
210 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_NONE, NULL);
211 gst_object_sync_values (e, t * GST_SECOND);
212 i1 = GST_TEST_OBJ (e)->val_int;
214 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
215 gst_object_sync_values (e, t * GST_SECOND);
216 i2 = GST_TEST_OBJ (e)->val_int;
218 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_CUBIC, NULL);
219 gst_object_sync_values (e, t * GST_SECOND);
220 i3 = GST_TEST_OBJ (e)->val_int;
222 fprintf (f, "%4.1f %d %d %d\n", (gfloat) t, i1, i2, i3);
227 /* test value arrays */
228 if (!(f = fopen ("ctrl_i2.dat", "w")))
230 fprintf (f, "# Time None Linear Cubic\n");
233 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_NONE, NULL);
234 v1 = g_new0 (GValue, n_values);
235 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
237 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
238 v2 = g_new0 (GValue, n_values);
239 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v2);
241 g_object_set (ics, "mode", GST_INTERPOLATION_MODE_CUBIC, NULL);
242 v3 = g_new0 (GValue, n_values);
243 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v3);
245 for (t = 0; t < n_values; t++) {
246 i1 = g_value_get_int (&v1[t]);
247 i2 = g_value_get_int (&v2[t]);
248 i3 = g_value_get_int (&v3[t]);
249 fprintf (f, "%4.1f %d %d %d\n", (gfloat) t / 10.0, i1, i2, i3);
250 g_value_unset (&v1[t]);
251 g_value_unset (&v2[t]);
252 g_value_unset (&v3[t]);
260 gst_object_unref (ics);
261 gst_object_unref (e);
268 GstLFOControlSource *lfocs;
269 GstControlSource *cs;
270 gint t, i1, i2, i3, i4, i5;
271 GValue *v1, *v2, *v3, *v4, *v5;
275 e = (GstObject *) gst_element_factory_make ("testobj", NULL);
277 lfocs = gst_lfo_control_source_new ();
278 cs = (GstControlSource *) lfocs;
280 gst_object_add_control_binding (e, gst_control_binding_direct_new (e, "int",
284 "frequency", (gdouble) 0.05,
285 "timeshift", (GstClockTime) 0,
286 "amplitude", (gdouble) 0.5, "offset", (gdouble) 0.5, NULL);
288 /* test single values */
289 if (!(f = fopen ("ctrl_l1.dat", "w")))
291 fprintf (f, "# Time Sine Square Saw RevSaw Triangle\n");
293 for (t = 0; t < 40; t++) {
294 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SINE, NULL);
295 gst_object_sync_values (e, t * GST_SECOND);
296 i1 = GST_TEST_OBJ (e)->val_int;
298 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SQUARE, NULL);
299 gst_object_sync_values (e, t * GST_SECOND);
300 i2 = GST_TEST_OBJ (e)->val_int;
302 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SAW, NULL);
303 gst_object_sync_values (e, t * GST_SECOND);
304 i3 = GST_TEST_OBJ (e)->val_int;
306 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_REVERSE_SAW, NULL);
307 gst_object_sync_values (e, t * GST_SECOND);
308 i4 = GST_TEST_OBJ (e)->val_int;
310 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_TRIANGLE, NULL);
311 gst_object_sync_values (e, t * GST_SECOND);
312 i5 = GST_TEST_OBJ (e)->val_int;
314 fprintf (f, "%4.1f %d %d %d %d %d\n", (gfloat) t, i1, i2, i3, i4, i5);
319 /* test value arrays */
320 if (!(f = fopen ("ctrl_l2.dat", "w")))
322 fprintf (f, "# Time Sine Square Saw RevSaw Triangle\n");
325 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SINE, NULL);
326 v1 = g_new0 (GValue, n_values);
327 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
329 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SQUARE, NULL);
330 v2 = g_new0 (GValue, n_values);
331 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v2);
333 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SAW, NULL);
334 v3 = g_new0 (GValue, n_values);
335 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v3);
337 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_REVERSE_SAW, NULL);
338 v4 = g_new0 (GValue, n_values);
339 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v4);
341 g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_TRIANGLE, NULL);
342 v5 = g_new0 (GValue, n_values);
343 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v5);
345 for (t = 0; t < n_values; t++) {
346 i1 = g_value_get_int (&v1[t]);
347 i2 = g_value_get_int (&v2[t]);
348 i3 = g_value_get_int (&v3[t]);
349 i4 = g_value_get_int (&v4[t]);
350 i5 = g_value_get_int (&v5[t]);
351 fprintf (f, "%4.1f %d %d %d %d %d\n", (gfloat) t / 10.0, i1, i2, i3, i4,
353 g_value_unset (&v1[t]);
354 g_value_unset (&v2[t]);
355 g_value_unset (&v3[t]);
356 g_value_unset (&v4[t]);
357 g_value_unset (&v5[t]);
367 gst_object_unref (lfocs);
368 gst_object_unref (e);
372 test_chained_lfo (void)
375 GstLFOControlSource *lfocs1, *lfocs2;
376 GstControlSource *cs1, *cs2;
382 e = (GstObject *) gst_element_factory_make ("testobj", NULL);
384 lfocs1 = gst_lfo_control_source_new ();
385 cs1 = (GstControlSource *) lfocs1;
387 gst_object_add_control_binding (e, gst_control_binding_direct_new (e, "int",
390 g_object_set (lfocs1,
391 "waveform", GST_LFO_WAVEFORM_SINE,
392 "frequency", (gdouble) 0.05,
393 "timeshift", (GstClockTime) 0, "offset", (gdouble) 0.5, NULL);
395 lfocs2 = gst_lfo_control_source_new ();
396 cs2 = (GstControlSource *) lfocs2;
398 gst_object_add_control_binding ((GstObject *) lfocs1,
399 gst_control_binding_direct_new ((GstObject *) lfocs1, "amplitude", cs2));
401 g_object_set (lfocs2,
402 "waveform", GST_LFO_WAVEFORM_SINE,
403 "frequency", (gdouble) 0.05,
404 "timeshift", (GstClockTime) 0,
405 "amplitude", (gdouble) 0.5, "offset", (gdouble) 0.5, NULL);
407 /* test single values */
408 if (!(f = fopen ("ctrl_cl1.dat", "w")))
410 fprintf (f, "# Time Sine\n");
412 for (t = 0; t < 40; t++) {
413 gst_object_sync_values (e, t * GST_SECOND);
414 i1 = GST_TEST_OBJ (e)->val_int;
416 fprintf (f, "%4.1f %d\n", (gfloat) t, i1);
421 /* test value arrays */
422 if (!(f = fopen ("ctrl_cl2.dat", "w")))
424 fprintf (f, "# Time Sine\n");
427 v1 = g_new0 (GValue, n_values);
428 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
430 for (t = 0; t < n_values; t++) {
431 i1 = g_value_get_int (&v1[t]);
432 fprintf (f, "%4.1f %d\n", (gfloat) t / 10.0, i1);
433 g_value_unset (&v1[t]);
439 gst_object_unref (lfocs1);
440 gst_object_unref (lfocs2);
441 gst_object_unref (e);
445 main (gint argc, gchar ** argv)
447 gst_init (&argc, &argv);
449 gst_element_register (NULL, "testobj", GST_RANK_NONE, GST_TYPE_TEST_OBJ);
451 test_interpolation ();