controller: also test array functions

Improve the example to also collect value arrays and plot them.
This commit is contained in:
Stefan Sauer 2011-12-31 15:52:18 +01:00
parent 545c6c19a3
commit 886a43988f

View file

@ -4,8 +4,8 @@
* Generates a datafile for various control sources.
*
* Needs gnuplot for plotting.
* plot "ctrl_interpolation.dat" using 1:2 with points title 'none', "" using 1:3 with points title 'linear', "" using 1:4 with points title 'cubic'
* plot "ctrl_lfo.dat" using 1:2 with points title 'sine', "" using 1:3 with points title 'saw', "" using 1:4 with points title 'square', "" using 1:5 with points title 'triangle'
* 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'
* plot "ctrl_l1.dat" using 1:2 with points title 'sine', "" using 1:3 with points title 'saw', "" using 1:4 with points title 'square', "" using 1:5 with points title 'triangle', "ctrl_l2.dat" using 1:2 with lines title 'sine', "" using 1:3 with lines title 'saw', "" using 1:4 with lines title 'square', "" using 1:5 with lines title 'triangle'
*/
#include <stdio.h>
@ -181,6 +181,8 @@ test_interpolation (void)
GstTimedValueControlSource *tvcs;
GstControlSource *cs;
gint t, i1, i2, i3;
GValue *v1, *v2, *v3;
gint n_values;
FILE *f;
e = (GstObject *) gst_element_factory_make ("testobj", NULL);
@ -196,7 +198,8 @@ test_interpolation (void)
gst_timed_value_control_source_set (tvcs, 20 * GST_SECOND, 0.5);
gst_timed_value_control_source_set (tvcs, 30 * GST_SECOND, 0.2);
if (!(f = fopen ("ctrl_interpolation.dat", "w")))
/* test single values */
if (!(f = fopen ("ctrl_i1.dat", "w")))
exit (-1);
fprintf (f, "# Time None Linear Cubic\n");
@ -213,11 +216,44 @@ test_interpolation (void)
gst_object_sync_values (e, t * GST_SECOND);
i3 = GST_TEST_OBJ (e)->val_int;
fprintf (f, "%d %d %d %d\n", t, i1, i2, i3);
fprintf (f, "%4.1f %d %d %d\n", (gfloat) t, i1, i2, i3);
}
fclose (f);
/* test value arrays */
if (!(f = fopen ("ctrl_i2.dat", "w")))
exit (-1);
fprintf (f, "# Time None Linear Cubic\n");
n_values = 40 * 10;
g_object_set (ics, "mode", GST_INTERPOLATION_MODE_NONE, NULL);
v1 = g_new0 (GValue, n_values);
gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
g_object_set (ics, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
v2 = g_new0 (GValue, n_values);
gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v2);
g_object_set (ics, "mode", GST_INTERPOLATION_MODE_CUBIC, NULL);
v3 = g_new0 (GValue, n_values);
gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v3);
for (t = 0; t < n_values; t++) {
i1 = g_value_get_int (&v1[t]);
i2 = g_value_get_int (&v2[t]);
i3 = g_value_get_int (&v3[t]);
fprintf (f, "%4.1f %d %d %d\n", (gfloat) t / 10.0, i1, i2, i3);
g_value_unset (&v1[t]);
g_value_unset (&v2[t]);
g_value_unset (&v3[t]);
}
g_free (v1);
g_free (v2);
g_free (v3);
fclose (f);
gst_object_unref (ics);
gst_object_unref (e);
}
@ -229,6 +265,8 @@ test_lfo (void)
GstLFOControlSource *lfocs;
GstControlSource *cs;
gint t, i1, i2, i3, i4;
GValue *v1, *v2, *v3, *v4;
gint n_values;
FILE *f;
e = (GstObject *) gst_element_factory_make ("testobj", NULL);
@ -243,7 +281,8 @@ test_lfo (void)
"timeshift", (GstClockTime) 0,
"amplitude", (gdouble) 0.5, "offset", (gdouble) 0.5, NULL);
if (!(f = fopen ("ctrl_lfo.dat", "w")))
/* test single values */
if (!(f = fopen ("ctrl_l1.dat", "w")))
exit (-1);
fprintf (f, "# Time Sine Saw Square Triangle\n");
@ -264,11 +303,50 @@ test_lfo (void)
gst_object_sync_values (e, t * GST_SECOND);
i4 = GST_TEST_OBJ (e)->val_int;
fprintf (f, "%d %d %d %d %d\n", t, i1, i2, i3, i4);
fprintf (f, "%4.1f %d %d %d %d\n", (gfloat) t, i1, i2, i3, i4);
}
fclose (f);
/* test value arrays */
if (!(f = fopen ("ctrl_l2.dat", "w")))
exit (-1);
fprintf (f, "# Time Sine Saw Square Triangle\n");
n_values = 40 * 10;
g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SINE, NULL);
v1 = g_new0 (GValue, n_values);
gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SAW, NULL);
v2 = g_new0 (GValue, n_values);
gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v2);
g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_SQUARE, NULL);
v3 = g_new0 (GValue, n_values);
gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v3);
g_object_set (lfocs, "waveform", GST_LFO_WAVEFORM_TRIANGLE, NULL);
v4 = g_new0 (GValue, n_values);
gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v4);
for (t = 0; t < n_values; t++) {
i1 = g_value_get_int (&v1[t]);
i2 = g_value_get_int (&v2[t]);
i3 = g_value_get_int (&v3[t]);
i4 = g_value_get_int (&v4[t]);
fprintf (f, "%4.1f %d %d %d %d\n", (gfloat) t / 10.0, i1, i2, i3, i4);
g_value_unset (&v1[t]);
g_value_unset (&v2[t]);
g_value_unset (&v3[t]);
g_value_unset (&v4[t]);
}
g_free (v1);
g_free (v2);
g_free (v3);
fclose (f);
gst_object_unref (lfocs);
gst_object_unref (e);
}