summaryrefslogtreecommitdiffstats
path: root/gst
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 /gst
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 'gst')
-rw-r--r--gst/equalizer/Makefile.am4
-rw-r--r--gst/equalizer/gstiirequalizer.c246
-rw-r--r--gst/equalizer/gstiirequalizer.h77
3 files changed, 178 insertions, 149 deletions
diff --git a/gst/equalizer/Makefile.am b/gst/equalizer/Makefile.am
index ed26e295..1ef12c94 100644
--- a/gst/equalizer/Makefile.am
+++ b/gst/equalizer/Makefile.am
@@ -1,6 +1,8 @@
plugin_LTLIBRARIES = libgstequalizer.la
-libgstequalizer_la_SOURCES = gstiirequalizer.c
+libgstequalizer_la_SOURCES = gstiirequalizer.c gstiirequalizer.h
libgstequalizer_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
libgstequalizer_la_LIBADD = $(GST_LIBS) $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_MAJORMINOR)
libgstequalizer_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+
+noinst_HEADERS = gstiirequalizer.h
diff --git a/gst/equalizer/gstiirequalizer.c b/gst/equalizer/gstiirequalizer.c
index fd8f3781..48dfac42 100644
--- a/gst/equalizer/gstiirequalizer.c
+++ b/gst/equalizer/gstiirequalizer.c
@@ -23,157 +23,91 @@
#include <math.h>
#include <string.h>
-#include <gst/gst.h>
-#include <gst/audio/audio.h>
-#include <gst/audio/gstaudiofilter.h>
-
-typedef struct _GstIirEqualizer GstIirEqualizer;
-typedef struct _GstIirEqualizerClass GstIirEqualizerClass;
-
-#define GST_TYPE_IIR_EQUALIZER \
- (gst_iir_equalizer_get_type())
-#define GST_IIR_EQUALIZER(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IIR_EQUALIZER,GstIirEqualizer))
-#define GST_IIR_EQUALIZER_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IIR_EQUALIZER,GstIirEqualizerClass))
-#define GST_IS_IIR_EQUALIZER(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IIR_EQUALIZER))
-#define GST_IS_IIR_EQUALIZER_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IIR_EQUALIZER))
-
-#define LOWEST_FREQ (20.0)
-#define HIGHEST_FREQ (20000.0)
-
-typedef void (*ProcessFunc) (GstIirEqualizer * equ, guint8 * data, guint size,
- guint channels);
-
-typedef struct
-{
- gdouble alpha; /* IIR coefficients for outputs */
- gdouble beta; /* IIR coefficients for inputs */
- gdouble gamma; /* IIR coefficients for inputs */
-} SecondOrderFilter;
-struct _GstIirEqualizer
-{
- GstAudioFilter audiofilter;
-
- /* properties */
- guint freq_count;
- gdouble bandwidth;
- gdouble *freqs;
- gdouble *values;
-
- /* data */
- SecondOrderFilter *filter;
- gpointer history;
- ProcessFunc process;
- guint history_size;
-};
+#include "gstiirequalizer.h"
-struct _GstIirEqualizerClass
-{
- GstAudioFilterClass audiofilter_class;
-};
+#define GST_EQUALIZER_TRANSFORM_LOCK(eq) \
+ g_mutex_lock (GST_BASE_TRANSFORM(eq)->transform_lock)
+
+#define GST_EQUALIZER_TRANSFORM_UNLOCK(eq) \
+ g_mutex_unlock (GST_BASE_TRANSFORM(eq)->transform_lock)
enum
{
ARG_0,
- ARG_BANDS,
- ARG_BANDWIDTH,
+ ARG_NUM_BANDS,
+ ARG_BAND_WIDTH,
ARG_BAND_VALUES
};
-static void gst_iir_equalizer_base_init (gpointer g_class);
-static void gst_iir_equalizer_class_init (gpointer g_class,
- gpointer class_data);
-static void gst_iir_equalizer_init (GTypeInstance * instance, gpointer g_class);
static void gst_iir_equalizer_finalize (GObject * object);
-
static void gst_iir_equalizer_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_iir_equalizer_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
-static void gst_iir_equalizer_setup (GstAudioFilter * iir_equalizer);
-static void gst_iir_equalizer_filter_inplace (GstAudioFilter *
- iir_equalizer, GstBuffer * buf);
-
-static GstAudioFilterClass *parent_class;
-
-GType
-gst_iir_equalizer_get_type (void)
-{
- static GType iir_equalizer_type = 0;
-
- if (!iir_equalizer_type) {
- static const GTypeInfo iir_equalizer_info = {
- sizeof (GstIirEqualizerClass),
- gst_iir_equalizer_base_init,
- NULL,
- gst_iir_equalizer_class_init,
- NULL,
- gst_iir_equalizer_init,
- sizeof (GstIirEqualizer),
- 0,
- NULL,
- };
-
- iir_equalizer_type = g_type_register_static (GST_TYPE_AUDIO_FILTER,
- "GstIirEqualizer", &iir_equalizer_info, 0);
- }
- return iir_equalizer_type;
-}
+static gboolean gst_iir_equalizer_setup (GstAudioFilter * filter,
+ GstRingBufferSpec * fmt);
+static GstFlowReturn gst_iir_equalizer_transform_ip (GstBaseTransform * btrans,
+ GstBuffer * buf);
+
+GST_DEBUG_CATEGORY_STATIC (equalizer_debug);
+#define GST_CAT_DEFAULT equalizer_debug
+
+#define ALLOWED_CAPS \
+ "audio/x-raw-int," \
+ " depth=(int)16," \
+ " width=(int)16," \
+ " endianness=(int)BYTE_ORDER," \
+ " signed=(bool)TRUE," \
+ " rate=(int)[1000,MAX]," \
+ " channels=(int)[1,MAX]; " \
+ "audio/x-raw-float," \
+ " width=(int)32," \
+ " endianness=(int)BYTE_ORDER," \
+ " rate=(int)[1000,MAX]," \
+ " channels=(int)[1,MAX]"
+
+GST_BOILERPLATE (GstIirEqualizer, gst_iir_equalizer, GstAudioFilter,
+ GST_TYPE_AUDIO_FILTER);
static void
gst_iir_equalizer_base_init (gpointer g_class)
{
- static const GstElementDetails iir_equalizer_details =
+ GstAudioFilterClass *audiofilter_class = GST_AUDIO_FILTER_CLASS (g_class);
+ GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+ const GstElementDetails iir_equalizer_details =
GST_ELEMENT_DETAILS ("Equalizer",
"Filter/Effect/Audio",
"Direct Form IIR equalizer",
"Benjamin Otte <otte@gnome.org>");
- GstIirEqualizerClass *klass = (GstIirEqualizerClass *) g_class;
- GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
GstCaps *caps;
gst_element_class_set_details (element_class, &iir_equalizer_details);
- caps = gst_caps_from_string ("audio/x-raw-int, depth=(int)16, width=(int)16, "
- "endianness=(int)BYTE_ORDER, signed=(bool)TRUE, "
- "rate=(int)[1000,MAX], channels=(int)[1,6];"
- "audio/x-raw-float, width=(int)32, endianness=(int)BYTE_ORDER,"
- "rate=(int)[1000,MAX], channels=(int)[1,6]");
- gst_audio_filter_class_add_pad_templates (GST_AUDIO_FILTER_CLASS (g_class),
- caps);
+ caps = gst_caps_from_string (ALLOWED_CAPS);
+ gst_audio_filter_class_add_pad_templates (audiofilter_class, caps);
gst_caps_unref (caps);
}
static void
-gst_iir_equalizer_class_init (gpointer g_class, gpointer class_data)
+gst_iir_equalizer_class_init (GstIirEqualizerClass * klass)
{
- GObjectClass *gobject_class;
- GstElementClass *gstelement_class;
- GstIirEqualizerClass *klass;
- GstAudioFilterClass *audio_filter_class;
-
- klass = (GstIirEqualizerClass *) g_class;
- gobject_class = (GObjectClass *) klass;
- gstelement_class = (GstElementClass *) klass;
- audio_filter_class = (GstAudioFilterClass *) g_class;
+ GstAudioFilterClass *audio_filter_class = (GstAudioFilterClass *) klass;
+ GstBaseTransformClass *btrans_class = (GstBaseTransformClass *) klass;
+ GObjectClass *gobject_class = (GObjectClass *) klass;
gobject_class->set_property = gst_iir_equalizer_set_property;
gobject_class->get_property = gst_iir_equalizer_get_property;
gobject_class->finalize = gst_iir_equalizer_finalize;
- parent_class = g_type_class_peek_parent (g_class);
-
- g_object_class_install_property (gobject_class, ARG_BANDS,
- g_param_spec_uint ("bands", "bands", "number of different bands to use",
- 2, 64, 15, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class, ARG_BANDWIDTH,
- g_param_spec_double ("bandwidth", "bandwidth",
- "bandwidth calculated as distance between bands * this value", 0.1,
+ g_object_class_install_property (gobject_class, ARG_NUM_BANDS,
+ g_param_spec_uint ("num-bands", "num-bands",
+ "number of different bands to use", 2, 64, 15,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_object_class_install_property (gobject_class, ARG_BAND_WIDTH,
+ g_param_spec_double ("band-width", "band-width",
+ "band width calculated as distance between bands * this value", 0.1,
5.0, 1.0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class, ARG_BAND_VALUES,
g_param_spec_value_array ("band-values", "band values",
@@ -184,12 +118,13 @@ gst_iir_equalizer_class_init (gpointer g_class, gpointer class_data)
G_PARAM_WRITABLE));
audio_filter_class->setup = gst_iir_equalizer_setup;
- audio_filter_class->filter_inplace = gst_iir_equalizer_filter_inplace;
+ btrans_class->transform_ip = gst_iir_equalizer_transform_ip;
}
static void
-gst_iir_equalizer_init (GTypeInstance * instance, gpointer g_class)
+gst_iir_equalizer_init (GstIirEqualizer * eq, GstIirEqualizerClass * g_class)
{
+ /* nothing to do here */
}
static void
@@ -220,7 +155,7 @@ setup_filter (GstIirEqualizer * equ, SecondOrderFilter * filter, gdouble gain,
gdouble frequency)
{
gdouble q = pow (HIGHEST_FREQ / LOWEST_FREQ,
- 1.0 / (equ->freq_count - 1)) * equ->bandwidth;
+ 1.0 / (equ->freq_count - 1)) * equ->band_width;
gdouble theta = frequency * 2 * M_PI;
filter->beta = (q - theta / 2) / (2 * q + theta);
@@ -257,21 +192,22 @@ gst_iir_equalizer_compute_frequencies (GstIirEqualizer * equ, guint band_count)
memset (equ->filter + sizeof (SecondOrderFilter) * old_count, 0,
sizeof (SecondOrderFilter) * (band_count - old_count));
}
+
+ /* free + alloc = no memcpy */
+ g_free (equ->history);
equ->history =
- g_realloc (equ->history,
- equ->history_size * audio->channels * band_count);
- memset (equ->history, 0, equ->history_size * audio->channels * band_count);
+ g_malloc0 (equ->history_size * audio->format.channels * band_count);
equ->freqs[0] = LOWEST_FREQ;
for (i = 1; i < band_count; i++) {
equ->freqs[i] = equ->freqs[i - 1] * step;
}
- if (audio->rate) {
+ if (audio->format.rate > 0) {
guint i;
for (i = 0; i < band_count; i++) {
setup_filter (equ, &equ->filter[i], arg_to_scale (equ->values[i]),
- equ->freqs[i] / audio->rate);
+ equ->freqs[i] / audio->format.rate);
}
}
}
@@ -282,20 +218,21 @@ gst_iir_equalizer_set_property (GObject * object, guint prop_id,
{
GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
+ GST_EQUALIZER_TRANSFORM_LOCK (equ);
GST_OBJECT_LOCK (equ);
switch (prop_id) {
- case ARG_BANDS:
+ case ARG_NUM_BANDS:
gst_iir_equalizer_compute_frequencies (equ, g_value_get_uint (value));
break;
- case ARG_BANDWIDTH:
- if (g_value_get_double (value) != equ->bandwidth) {
- equ->bandwidth = g_value_get_double (value);
- if (GST_AUDIO_FILTER (equ)->rate) {
+ case ARG_BAND_WIDTH:
+ if (g_value_get_double (value) != equ->band_width) {
+ equ->band_width = g_value_get_double (value);
+ if (GST_AUDIO_FILTER (equ)->format.rate) {
guint i;
for (i = 0; i < equ->freq_count; i++) {
setup_filter (equ, &equ->filter[i], arg_to_scale (equ->values[i]),
- equ->freqs[i] / GST_AUDIO_FILTER (equ)->rate);
+ equ->freqs[i] / GST_AUDIO_FILTER (equ)->format.rate);
}
}
}
@@ -319,7 +256,7 @@ gst_iir_equalizer_set_property (GObject * object, guint prop_id,
if (new_val != equ->values[i]) {
equ->values[i] = new_val;
setup_filter (equ, &equ->filter[i], arg_to_scale (new_val),
- equ->freqs[i] / GST_AUDIO_FILTER (equ)->rate);
+ equ->freqs[i] / GST_AUDIO_FILTER (equ)->format.rate);
}
}
}
@@ -330,6 +267,7 @@ gst_iir_equalizer_set_property (GObject * object, guint prop_id,
break;
}
GST_OBJECT_UNLOCK (equ);
+ GST_EQUALIZER_TRANSFORM_UNLOCK (equ);
}
static void
@@ -338,19 +276,21 @@ gst_iir_equalizer_get_property (GObject * object, guint prop_id,
{
GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
+ GST_EQUALIZER_TRANSFORM_LOCK (equ);
GST_OBJECT_LOCK (equ);
switch (prop_id) {
- case ARG_BANDS:
+ case ARG_NUM_BANDS:
g_value_set_uint (value, equ->freq_count);
break;
- case ARG_BANDWIDTH:
- g_value_set_double (value, equ->bandwidth);
+ case ARG_BAND_WIDTH:
+ g_value_set_double (value, equ->band_width);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
GST_OBJECT_UNLOCK (equ);
+ GST_EQUALIZER_TRANSFORM_UNLOCK (equ);
}
/* start of code that is type specific */
@@ -411,37 +351,47 @@ guint size, guint channels) \
CREATE_OPTIMIZED_FUNCTIONS (gint16, gint, -32768, 32767);
CREATE_OPTIMIZED_FUNCTIONS (gfloat, gfloat, -1.0, 1.0);
-static void
-gst_iir_equalizer_filter_inplace (GstAudioFilter * filter, GstBuffer * buf)
+static GstFlowReturn
+gst_iir_equalizer_transform_ip (GstBaseTransform * btrans, GstBuffer * buf)
{
- GstIirEqualizer *equ = GST_IIR_EQUALIZER (filter);
+ GstAudioFilter *filter = GST_AUDIO_FILTER (btrans);
+ GstIirEqualizer *equ = GST_IIR_EQUALIZER (btrans);
+
+ if (G_UNLIKELY (filter->format.channels < 1 || equ->process == NULL))
+ return GST_FLOW_NOT_NEGOTIATED;
- GST_OBJECT_LOCK (equ);
equ->process (equ, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf),
- filter->channels);
- GST_OBJECT_UNLOCK (equ);
+ filter->format.channels);
+
+ return GST_FLOW_OK;
}
-static void
-gst_iir_equalizer_setup (GstAudioFilter * audio)
+static gboolean
+gst_iir_equalizer_setup (GstAudioFilter * audio, GstRingBufferSpec * fmt)
{
GstIirEqualizer *equ = GST_IIR_EQUALIZER (audio);
- if (audio->width == 16) {
- equ->history_size = history_size_gint16;
- equ->process = gst_iir_equ_process_gint16;
- } else if (audio->width == 32) {
- equ->history_size = history_size_gfloat;
- equ->process = gst_iir_equ_process_gfloat;
- } else {
- g_assert_not_reached ();
+ switch (fmt->width) {
+ case 16:
+ equ->history_size = history_size_gint16;
+ equ->process = gst_iir_equ_process_gint16;
+ break;
+ case 32:
+ equ->history_size = history_size_gfloat;
+ equ->process = gst_iir_equ_process_gfloat;
+ break;
+ default:
+ return FALSE;
}
gst_iir_equalizer_compute_frequencies (equ, equ->freq_count);
+ return TRUE;
}
static gboolean
plugin_init (GstPlugin * plugin)
{
+ GST_DEBUG_CATEGORY_INIT (equalizer_debug, "equalizer", 0, "equalizer");
+
return gst_element_register (plugin, "equalizer", GST_RANK_NONE,
GST_TYPE_IIR_EQUALIZER);
}
diff --git a/gst/equalizer/gstiirequalizer.h b/gst/equalizer/gstiirequalizer.h
new file mode 100644
index 00000000..2193369b
--- /dev/null
+++ b/gst/equalizer/gstiirequalizer.h
@@ -0,0 +1,77 @@
+/* GStreamer IIR equalizer
+ * Copyright (C) <2004> Benjamin Otte <otte@gnome.org>
+ *
+ * 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.
+ */
+
+#ifndef __GST_IIR_EQUALIZER__
+#define __GST_IIR_EQUALIZER__
+
+#include <gst/audio/gstaudiofilter.h>
+#include <gst/audio/gstringbuffer.h>
+
+typedef struct _GstIirEqualizer GstIirEqualizer;
+typedef struct _GstIirEqualizerClass GstIirEqualizerClass;
+
+#define GST_TYPE_IIR_EQUALIZER \
+ (gst_iir_equalizer_get_type())
+#define GST_IIR_EQUALIZER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IIR_EQUALIZER,GstIirEqualizer))
+#define GST_IIR_EQUALIZER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IIR_EQUALIZER,GstIirEqualizerClass))
+#define GST_IS_IIR_EQUALIZER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IIR_EQUALIZER))
+#define GST_IS_IIR_EQUALIZER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IIR_EQUALIZER))
+
+#define LOWEST_FREQ (20.0)
+#define HIGHEST_FREQ (20000.0)
+
+typedef void (*ProcessFunc) (GstIirEqualizer * eq, guint8 * data, guint size,
+ guint channels);
+
+typedef struct
+{
+ gdouble alpha; /* IIR coefficients for outputs */
+ gdouble beta; /* IIR coefficients for inputs */
+ gdouble gamma; /* IIR coefficients for inputs */
+} SecondOrderFilter;
+
+struct _GstIirEqualizer
+{
+ GstAudioFilter audiofilter;
+
+ /*< private >*/
+
+ /* properties */
+ guint freq_count;
+ gdouble band_width;
+ gdouble *freqs;
+ gdouble *values;
+
+ /* data */
+ SecondOrderFilter *filter;
+ gpointer history;
+ ProcessFunc process;
+ guint history_size;
+};
+
+struct _GstIirEqualizerClass
+{
+ GstAudioFilterClass audiofilter_class;
+};
+
+#endif /* __GST_IIR_EQUALIZER__ */