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/gstdirectcontrolbinding.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 GstTimedValueControlSource *tvcs;
183 GstControlSource *cs;
185 GValue *v1, *v2, *v3;
189 e = (GstObject *) gst_element_factory_make ("testobj", NULL);
191 cs = gst_interpolation_control_source_new ();
192 tvcs = (GstTimedValueControlSource *) cs;
194 gst_object_add_control_binding (e, gst_direct_control_binding_new (e, "int",
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 (cs, "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 (cs, "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 (cs, "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 (cs, "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 (cs, "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 (cs, "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 (cs);
259 gst_object_unref (e);
266 GstControlSource *cs;
267 gint t, i1, i2, i3, i4, i5;
268 GValue *v1, *v2, *v3, *v4, *v5;
272 e = (GstObject *) gst_element_factory_make ("testobj", NULL);
274 cs = gst_lfo_control_source_new ();
276 gst_object_add_control_binding (e, gst_direct_control_binding_new (e, "int",
280 "frequency", (gdouble) 0.05,
281 "timeshift", (GstClockTime) 0,
282 "amplitude", (gdouble) 0.5, "offset", (gdouble) 0.5, NULL);
284 /* test single values */
285 if (!(f = fopen ("ctrl_l1.dat", "w")))
287 fprintf (f, "# Time Sine Square Saw RevSaw Triangle\n");
289 for (t = 0; t < 40; t++) {
290 g_object_set (cs, "waveform", GST_LFO_WAVEFORM_SINE, NULL);
291 gst_object_sync_values (e, t * GST_SECOND);
292 i1 = GST_TEST_OBJ (e)->val_int;
294 g_object_set (cs, "waveform", GST_LFO_WAVEFORM_SQUARE, NULL);
295 gst_object_sync_values (e, t * GST_SECOND);
296 i2 = GST_TEST_OBJ (e)->val_int;
298 g_object_set (cs, "waveform", GST_LFO_WAVEFORM_SAW, NULL);
299 gst_object_sync_values (e, t * GST_SECOND);
300 i3 = GST_TEST_OBJ (e)->val_int;
302 g_object_set (cs, "waveform", GST_LFO_WAVEFORM_REVERSE_SAW, NULL);
303 gst_object_sync_values (e, t * GST_SECOND);
304 i4 = GST_TEST_OBJ (e)->val_int;
306 g_object_set (cs, "waveform", GST_LFO_WAVEFORM_TRIANGLE, NULL);
307 gst_object_sync_values (e, t * GST_SECOND);
308 i5 = GST_TEST_OBJ (e)->val_int;
310 fprintf (f, "%4.1f %d %d %d %d %d\n", (gfloat) t, i1, i2, i3, i4, i5);
315 /* test value arrays */
316 if (!(f = fopen ("ctrl_l2.dat", "w")))
318 fprintf (f, "# Time Sine Square Saw RevSaw Triangle\n");
321 g_object_set (cs, "waveform", GST_LFO_WAVEFORM_SINE, NULL);
322 v1 = g_new0 (GValue, n_values);
323 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
325 g_object_set (cs, "waveform", GST_LFO_WAVEFORM_SQUARE, NULL);
326 v2 = g_new0 (GValue, n_values);
327 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v2);
329 g_object_set (cs, "waveform", GST_LFO_WAVEFORM_SAW, NULL);
330 v3 = g_new0 (GValue, n_values);
331 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v3);
333 g_object_set (cs, "waveform", GST_LFO_WAVEFORM_REVERSE_SAW, NULL);
334 v4 = g_new0 (GValue, n_values);
335 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v4);
337 g_object_set (cs, "waveform", GST_LFO_WAVEFORM_TRIANGLE, NULL);
338 v5 = g_new0 (GValue, n_values);
339 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v5);
341 for (t = 0; t < n_values; t++) {
342 i1 = g_value_get_int (&v1[t]);
343 i2 = g_value_get_int (&v2[t]);
344 i3 = g_value_get_int (&v3[t]);
345 i4 = g_value_get_int (&v4[t]);
346 i5 = g_value_get_int (&v5[t]);
347 fprintf (f, "%4.1f %d %d %d %d %d\n", (gfloat) t / 10.0, i1, i2, i3, i4,
349 g_value_unset (&v1[t]);
350 g_value_unset (&v2[t]);
351 g_value_unset (&v3[t]);
352 g_value_unset (&v4[t]);
353 g_value_unset (&v5[t]);
363 gst_object_unref (cs);
364 gst_object_unref (e);
368 test_chained_lfo (void)
371 GstControlSource *cs1, *cs2;
377 e = (GstObject *) gst_element_factory_make ("testobj", NULL);
379 cs1 = gst_lfo_control_source_new ();
381 gst_object_add_control_binding (e, gst_direct_control_binding_new (e, "int",
385 "waveform", GST_LFO_WAVEFORM_SINE,
386 "frequency", (gdouble) 0.05,
387 "timeshift", (GstClockTime) 0, "offset", (gdouble) 0.5, NULL);
389 cs2 = gst_lfo_control_source_new ();
391 gst_object_add_control_binding ((GstObject *) cs1,
392 gst_direct_control_binding_new ((GstObject *) cs1, "amplitude", cs2));
395 "waveform", GST_LFO_WAVEFORM_SINE,
396 "frequency", (gdouble) 0.05,
397 "timeshift", (GstClockTime) 0,
398 "amplitude", (gdouble) 0.5, "offset", (gdouble) 0.5, NULL);
400 /* test single values */
401 if (!(f = fopen ("ctrl_cl1.dat", "w")))
403 fprintf (f, "# Time Sine\n");
405 for (t = 0; t < 40; t++) {
406 gst_object_sync_values (e, t * GST_SECOND);
407 i1 = GST_TEST_OBJ (e)->val_int;
409 fprintf (f, "%4.1f %d\n", (gfloat) t, i1);
414 /* test value arrays */
415 if (!(f = fopen ("ctrl_cl2.dat", "w")))
417 fprintf (f, "# Time Sine\n");
420 v1 = g_new0 (GValue, n_values);
421 gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
423 for (t = 0; t < n_values; t++) {
424 i1 = g_value_get_int (&v1[t]);
425 fprintf (f, "%4.1f %d\n", (gfloat) t / 10.0, i1);
426 g_value_unset (&v1[t]);
432 gst_object_unref (cs1);
433 gst_object_unref (cs2);
434 gst_object_unref (e);
438 main (gint argc, gchar ** argv)
440 gst_init (&argc, &argv);
442 gst_element_register (NULL, "testobj", GST_RANK_NONE, GST_TYPE_TEST_OBJ);
444 test_interpolation ();