mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
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.
This commit is contained in:
parent
d5bd74dcf6
commit
add17e34f0
8 changed files with 499 additions and 148 deletions
23
ChangeLog
23
ChangeLog
|
@ -1,3 +1,26 @@
|
|||
2007-02-03 Tim-Philipp Müller <tim at centricular dot net>
|
||||
|
||||
* 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.
|
||||
|
||||
2007-02-02 Tim-Philipp Müller <tim at centricular dot net>
|
||||
|
||||
* gst/equalizer/gstiirequalizer.c: (gst_iir_equalizer_class_init),
|
||||
|
|
|
@ -42,8 +42,8 @@ dnl AS_LIBTOOL_TAGS([CXX])
|
|||
AM_PROG_LIBTOOL
|
||||
|
||||
dnl *** required versions of GStreamer stuff ***
|
||||
GST_REQ=0.10.10.1
|
||||
GSTPB_REQ=0.10.10.1
|
||||
GST_REQ=0.10.11.1
|
||||
GSTPB_REQ=0.10.11.1
|
||||
|
||||
dnl *** autotools stuff ****
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
#include "gstiirequalizer.h"
|
||||
|
||||
#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 GST_EQUALIZER_TRANSFORM_LOCK(eq) \
|
||||
g_mutex_lock (GST_BASE_TRANSFORM(eq)->transform_lock)
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
struct _GstIirEqualizerClass
|
||||
{
|
||||
GstAudioFilterClass audiofilter_class;
|
||||
};
|
||||
#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 gboolean gst_iir_equalizer_setup (GstAudioFilter * filter,
|
||||
GstRingBufferSpec * fmt);
|
||||
static GstFlowReturn gst_iir_equalizer_transform_ip (GstBaseTransform * btrans,
|
||||
GstBuffer * buf);
|
||||
|
||||
static GstAudioFilterClass *parent_class;
|
||||
GST_DEBUG_CATEGORY_STATIC (equalizer_debug);
|
||||
#define GST_CAT_DEFAULT equalizer_debug
|
||||
|
||||
GType
|
||||
gst_iir_equalizer_get_type (void)
|
||||
{
|
||||
static GType iir_equalizer_type = 0;
|
||||
#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]"
|
||||
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
77
gst/equalizer/gstiirequalizer.h
Normal file
77
gst/equalizer/gstiirequalizer.h
Normal file
|
@ -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__ */
|
1
tests/icles/.gitignore
vendored
1
tests/icles/.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
equalizer-test
|
||||
pitch-test
|
||||
v4l2src-test
|
||||
videocrop-test
|
||||
|
|
|
@ -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
|
||||
|
|
293
tests/icles/equalizer-test.c
Normal file
293
tests/icles/equalizer-test.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue