summaryrefslogtreecommitdiffstats
path: root/tests/icles
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.net>2007-02-03 23:35:26 +0000
committerTim-Philipp Müller <tim@centricular.net>2007-02-03 23:35:26 +0000
commitadd17e34f0b5d163bd09e02b95c19ec6b9473945 (patch)
tree50168cc7aca50d988fa6275705a6c4ab4f127e6e /tests/icles
parentd5bd74dcf6384ef42b66658d8826b6d5d6eaa76d (diff)
downloadgst-plugins-bad-add17e34f0b5d163bd09e02b95c19ec6b9473945.tar.gz
gst-plugins-bad-add17e34f0b5d163bd09e02b95c19ec6b9473945.tar.bz2
gst-plugins-bad-add17e34f0b5d163bd09e02b95c19ec6b9473945.zip
Fix up to use the newly ported (actually working) GstAudioFilter.
Original commit message from CVS: * configure.ac: * gst/equalizer/Makefile.am: * gst/equalizer/gstiirequalizer.c: (gst_iir_equalizer_base_init), (gst_iir_equalizer_class_init), (gst_iir_equalizer_init), (setup_filter), (gst_iir_equalizer_compute_frequencies), (gst_iir_equalizer_set_property), (gst_iir_equalizer_get_property), (gst_iir_equalizer_transform_ip), (gst_iir_equalizer_setup), (plugin_init): * gst/equalizer/gstiirequalizer.h: Fix up to use the newly ported (actually working) GstAudioFilter. Bump core/base requirements to CVS for this. * tests/icles/.cvsignore: * tests/icles/Makefile.am: * tests/icles/equalizer-test.c: (check_bus), (equalizer_set_band_value), (equalizer_set_all_band_values), (equalizer_set_band_value_and_wait), (equalizer_set_all_band_values_and_wait), (do_slider_fiddling), (main): Add brain-dead interactive test for equalizer.
Diffstat (limited to 'tests/icles')
-rw-r--r--tests/icles/.gitignore1
-rw-r--r--tests/icles/Makefile.am7
-rw-r--r--tests/icles/equalizer-test.c293
3 files changed, 300 insertions, 1 deletions
diff --git a/tests/icles/.gitignore b/tests/icles/.gitignore
index 364303c6..bb39cc6c 100644
--- a/tests/icles/.gitignore
+++ b/tests/icles/.gitignore
@@ -1,3 +1,4 @@
+equalizer-test
pitch-test
v4l2src-test
videocrop-test
diff --git a/tests/icles/Makefile.am b/tests/icles/Makefile.am
index 26e0cbc3..b57880e4 100644
--- a/tests/icles/Makefile.am
+++ b/tests/icles/Makefile.am
@@ -16,4 +16,9 @@ videocrop_test_CFLAGS = $(GST_CFLAGS)
videocrop_test_LDADD = $(GST_LIBS)
videocrop_test_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
-noinst_PROGRAMS = $(GST_SOUNDTOUCH_TESTS) videocrop-test
+equalizer_test_SOURCES = equalizer-test.c
+equalizer_test_CFLAGS = $(GST_CFLAGS)
+equalizer_test_LDADD = $(GST_LIBS)
+equalizer_test_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+
+noinst_PROGRAMS = $(GST_SOUNDTOUCH_TESTS) equalizer-test videocrop-test
diff --git a/tests/icles/equalizer-test.c b/tests/icles/equalizer-test.c
new file mode 100644
index 00000000..c7603982
--- /dev/null
+++ b/tests/icles/equalizer-test.c
@@ -0,0 +1,293 @@
+/* GStreamer test for the equalizer element
+ * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <gst/gst.h>
+
+#include <stdlib.h>
+#include <math.h>
+
+GST_DEBUG_CATEGORY_STATIC (equalizer_test_debug);
+#define GST_CAT_DEFAULT equalizer_test_debug
+
+static GstBus *pipeline_bus;
+
+static gboolean
+check_bus (GstClockTime max_wait_time)
+{
+ GstMessage *msg;
+
+ msg = gst_bus_poll (pipeline_bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS,
+ max_wait_time);
+
+ if (msg == NULL)
+ return FALSE;
+
+ if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
+ GError *err = NULL;
+ gchar *debug = NULL;
+
+ g_assert (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
+ gst_message_parse_error (msg, &err, &debug);
+ GST_ERROR ("ERROR: %s [%s]", err->message, debug);
+ g_print ("\n===========> ERROR: %s\n%s\n\n", err->message, debug);
+ g_error_free (err);
+ g_free (debug);
+ }
+
+ if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS) {
+ g_print ("\n === EOS ===\n\n");
+ }
+
+ gst_message_unref (msg);
+ return TRUE;
+}
+
+static void
+equalizer_set_band_value (GstElement * eq, GValueArray * arr, guint band,
+ gdouble val)
+{
+ g_value_set_double (g_value_array_get_nth (arr, band), val);
+ g_object_set (eq, "band-values", arr, NULL);
+ g_print ("Band %2d: %.2f\n", band, val);
+}
+
+static void
+equalizer_set_all_band_values (GstElement * eq, GValueArray * arr, gdouble val)
+{
+ gint i;
+
+ for (i = 0; i < arr->n_values; ++i) {
+ g_value_set_double (g_value_array_get_nth (arr, i), val);
+ }
+ g_object_set (eq, "band-values", arr, NULL);
+ g_print ("All bands: %.2f\n", val);
+}
+
+static gboolean
+equalizer_set_band_value_and_wait (GstElement * eq, GValueArray * arr,
+ guint band, gdouble val)
+{
+ equalizer_set_band_value (eq, arr, band, val);
+ return check_bus (100 * GST_MSECOND);
+}
+
+static gboolean
+equalizer_set_all_band_values_and_wait (GstElement * eq, GValueArray * arr,
+ gdouble val)
+{
+ equalizer_set_all_band_values (eq, arr, val);
+ return check_bus (100 * GST_MSECOND);
+}
+
+static void
+do_slider_fiddling (GstElement * playbin, GstElement * eq)
+{
+ GValueArray *arr;
+ gboolean stop;
+ guint num_bands, i;
+ gdouble d, step = 0.2;
+
+ stop = FALSE;
+
+ g_object_get (eq, "num-bands", &num_bands, NULL);
+
+ g_print ("%u bands.\n", num_bands);
+
+ arr = g_value_array_new (num_bands);
+ for (i = 0; i < num_bands; ++i) {
+ GValue val = { 0, };
+
+ g_value_init (&val, G_TYPE_DOUBLE);
+ g_value_set_double (&val, 0.0);
+ g_value_array_append (arr, &val);
+ }
+
+ g_object_set (eq, "band-values", arr, NULL);
+
+ while (!stop) {
+ for (i = 0; !stop && i < num_bands; ++i) {
+ d = 0.0;
+ while (!stop && d <= 1.0) {
+ stop = equalizer_set_band_value_and_wait (eq, arr, i, d);
+ d += step;
+ }
+ d = 1.0;
+ while (!stop && d >= -1.0) {
+ stop = equalizer_set_band_value_and_wait (eq, arr, i, d);
+ d -= step;
+ }
+ d = -1.0;
+ while (!stop && d <= 0.0) {
+ stop = equalizer_set_band_value_and_wait (eq, arr, i, d);
+ d += step;
+ }
+ }
+
+ d = 0.0;
+ while (!stop && d <= 1.0) {
+ stop = equalizer_set_all_band_values_and_wait (eq, arr, d);
+ d += step;
+ }
+ d = 1.0;
+ while (!stop && d >= -1.0) {
+ stop = equalizer_set_all_band_values_and_wait (eq, arr, d);
+ d -= step;
+ }
+ d = -1.0;
+ while (!stop && d <= 0.0) {
+ stop = equalizer_set_all_band_values_and_wait (eq, arr, d);
+ d += step;
+ }
+ }
+
+ g_value_array_free (arr);
+}
+
+int
+main (int argc, char **argv)
+{
+ gchar *opt_audiosink_str = NULL;
+ gchar **filenames = NULL;
+ const GOptionEntry test_goptions[] = {
+ {"audiosink", '\0', 0, G_OPTION_ARG_STRING, &opt_audiosink_str,
+ "audiosink to use (default: autoaudiosink)", NULL},
+ {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL},
+ {NULL, '\0', 0, 0, NULL, NULL, NULL}
+ };
+ GOptionContext *ctx;
+ GError *opt_err = NULL;
+
+ GstStateChangeReturn ret;
+ GstElement *playbin, *sink, *bin, *eq, *auconv;
+ GstPad *eq_sinkpad;
+ gchar *uri;
+
+ if (!g_thread_supported ())
+ g_thread_init (NULL);
+
+ GST_DEBUG_CATEGORY_INIT (equalizer_test_debug, "equalizertest", 0, "eqtest");
+
+ /* command line option parsing */
+ ctx = g_option_context_new ("FILENAME");
+ g_option_context_add_group (ctx, gst_init_get_option_group ());
+ g_option_context_add_main_entries (ctx, test_goptions, NULL);
+
+ if (!g_option_context_parse (ctx, &argc, &argv, &opt_err)) {
+ g_error ("Error parsing command line options: %s", opt_err->message);
+ return -1;
+ }
+
+ if (filenames == NULL || *filenames == NULL) {
+ g_printerr ("Please specify a file to play back\n");
+ return -1;
+ }
+
+ playbin = gst_element_factory_make ("playbin", "playbin");
+ if (playbin == NULL) {
+ g_error ("Couldn't create 'playbin' element");
+ return -1;
+ }
+
+ if (opt_audiosink_str) {
+ g_print ("Trying audiosink '%s' ...", opt_audiosink_str);
+ sink = gst_element_factory_make (opt_audiosink_str, "sink");
+ g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
+ } else {
+ sink = NULL;
+ }
+ if (sink == NULL) {
+ g_print ("Trying audiosink '%s' ...", "autoaudiosink");
+ sink = gst_element_factory_make ("autoaudiosink", "sink");
+ g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
+ }
+ if (sink == NULL) {
+ g_print ("Trying audiosink '%s' ...", "alsasink");
+ sink = gst_element_factory_make ("alsasink", "sink");
+ g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
+ }
+ if (sink == NULL) {
+ g_print ("Trying audiosink '%s' ...", "osssink");
+ sink = gst_element_factory_make ("osssink", "sink");
+ g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
+ }
+
+ g_assert (sink != NULL);
+
+ bin = gst_bin_new ("ausinkbin");
+ g_assert (bin != NULL);
+
+ eq = gst_element_factory_make ("equalizer", "equalizer");
+ g_assert (eq != NULL);
+
+ auconv = gst_element_factory_make ("audioconvert", "eqauconv");
+ g_assert (auconv != NULL);
+
+ gst_bin_add_many (GST_BIN (bin), eq, auconv, sink, NULL);
+
+ if (!gst_element_link (eq, auconv))
+ g_error ("Failed to link equalizer to audioconvert");
+
+ if (!gst_element_link (auconv, sink))
+ g_error ("Failed to link audioconvert to audio sink");
+
+
+ eq_sinkpad = gst_element_get_static_pad (eq, "sink");
+ g_assert (eq_sinkpad != NULL);
+
+ gst_element_add_pad (bin, gst_ghost_pad_new (NULL, eq_sinkpad));
+ gst_object_unref (eq_sinkpad);
+
+ g_object_set (playbin, "audio-sink", bin, NULL);
+
+ /* won't work: uri = gst_uri_construct ("file", filenames[0]); */
+ uri = g_strdup_printf ("file://%s", filenames[0]);
+ g_object_set (playbin, "uri", uri, NULL);
+ g_free (uri);
+
+ pipeline_bus = GST_ELEMENT_BUS (playbin);
+
+ ret = gst_element_set_state (playbin, GST_STATE_PLAYING);
+ if (ret == GST_STATE_CHANGE_FAILURE) {
+ g_printerr ("Failed to set playbin to PLAYING\n");
+ check_bus (1 * GST_SECOND);
+ return -1;
+ }
+
+ ret = gst_element_get_state (playbin, NULL, NULL, 5 * GST_SECOND);
+ if (ret == GST_STATE_CHANGE_ASYNC) {
+ g_printerr ("Failed to go to PLAYING in 5 seconds, bailing out\n");
+ return -1;
+ } else if (ret != GST_STATE_CHANGE_SUCCESS) {
+ g_printerr ("State change to PLAYING failed\n");
+ check_bus (1 * GST_SECOND);
+ return -1;
+ }
+
+ g_print ("Playing ...\n");
+ do_slider_fiddling (playbin, eq);
+
+ gst_element_set_state (playbin, GST_STATE_NULL);
+ gst_object_unref (playbin);
+
+ return 0;
+}