gst/equalizer/gstiirequalizer.*: Update the filter coefficients only when needed in the transform_ip function and cor...
Original commit message from CVS: * gst/equalizer/gstiirequalizer.c: (gst_iir_equalizer_band_set_property), (gst_iir_equalizer_init), (setup_filter), (set_passthrough), (update_coefficients), (gst_iir_equalizer_compute_frequencies), (gst_iir_equalizer_transform_ip): * gst/equalizer/gstiirequalizer.h: Update the filter coefficients only when needed in the transform_ip function and correctly set the element into passthrough mode if the gain of all bands is 0.
This commit is contained in:
parent
4ffab084be
commit
c17d49ee20
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
2008-05-30 Sebastian Dröge <slomo@circular-chaos.org>
|
||||||
|
|
||||||
|
* gst/equalizer/gstiirequalizer.c:
|
||||||
|
(gst_iir_equalizer_band_set_property), (gst_iir_equalizer_init),
|
||||||
|
(setup_filter), (set_passthrough), (update_coefficients),
|
||||||
|
(gst_iir_equalizer_compute_frequencies),
|
||||||
|
(gst_iir_equalizer_transform_ip):
|
||||||
|
* gst/equalizer/gstiirequalizer.h:
|
||||||
|
Update the filter coefficients only when needed in the transform_ip
|
||||||
|
function and correctly set the element into passthrough mode if the
|
||||||
|
gain of all bands is 0.
|
||||||
|
|
||||||
2008-05-29 Wim Taymans <wim.taymans@collabora.co.uk>
|
2008-05-29 Wim Taymans <wim.taymans@collabora.co.uk>
|
||||||
|
|
||||||
Based on patch by: Sebastian Keller <sebastian-keller at gmx dot de>
|
Based on patch by: Sebastian Keller <sebastian-keller at gmx dot de>
|
||||||
|
@ -120,8 +120,11 @@ struct _GstIirEqualizerBandClass
|
|||||||
};
|
};
|
||||||
|
|
||||||
static GType gst_iir_equalizer_band_get_type (void);
|
static GType gst_iir_equalizer_band_get_type (void);
|
||||||
|
|
||||||
static void setup_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band);
|
static void setup_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band);
|
||||||
|
|
||||||
|
static void set_passthrough (GstIirEqualizer * equ);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_iir_equalizer_band_set_property (GObject * object, guint prop_id,
|
gst_iir_equalizer_band_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec)
|
const GValue * value, GParamSpec * pspec)
|
||||||
@ -138,10 +141,10 @@ gst_iir_equalizer_band_set_property (GObject * object, guint prop_id,
|
|||||||
GstIirEqualizer *equ =
|
GstIirEqualizer *equ =
|
||||||
GST_IIR_EQUALIZER (gst_object_get_parent (GST_OBJECT (band)));
|
GST_IIR_EQUALIZER (gst_object_get_parent (GST_OBJECT (band)));
|
||||||
|
|
||||||
|
equ->need_new_coefficients = equ->need_new_coefficients ||
|
||||||
|
(band->gain != gain);
|
||||||
band->gain = gain;
|
band->gain = gain;
|
||||||
if (GST_AUDIO_FILTER (equ)->format.rate) {
|
|
||||||
setup_filter (equ, band);
|
|
||||||
}
|
|
||||||
gst_object_unref (equ);
|
gst_object_unref (equ);
|
||||||
GST_DEBUG_OBJECT (band, "changed gain = %lf ", band->gain);
|
GST_DEBUG_OBJECT (band, "changed gain = %lf ", band->gain);
|
||||||
}
|
}
|
||||||
@ -156,10 +159,9 @@ gst_iir_equalizer_band_set_property (GObject * object, guint prop_id,
|
|||||||
GstIirEqualizer *equ =
|
GstIirEqualizer *equ =
|
||||||
GST_IIR_EQUALIZER (gst_object_get_parent (GST_OBJECT (band)));
|
GST_IIR_EQUALIZER (gst_object_get_parent (GST_OBJECT (band)));
|
||||||
|
|
||||||
|
equ->need_new_coefficients = equ->need_new_coefficients ||
|
||||||
|
(band->freq != freq);
|
||||||
band->freq = freq;
|
band->freq = freq;
|
||||||
if (GST_AUDIO_FILTER (equ)->format.rate) {
|
|
||||||
setup_filter (equ, band);
|
|
||||||
}
|
|
||||||
gst_object_unref (equ);
|
gst_object_unref (equ);
|
||||||
GST_DEBUG_OBJECT (band, "changed freq = %lf ", band->freq);
|
GST_DEBUG_OBJECT (band, "changed freq = %lf ", band->freq);
|
||||||
}
|
}
|
||||||
@ -174,10 +176,9 @@ gst_iir_equalizer_band_set_property (GObject * object, guint prop_id,
|
|||||||
GstIirEqualizer *equ =
|
GstIirEqualizer *equ =
|
||||||
GST_IIR_EQUALIZER (gst_object_get_parent (GST_OBJECT (band)));
|
GST_IIR_EQUALIZER (gst_object_get_parent (GST_OBJECT (band)));
|
||||||
|
|
||||||
|
equ->need_new_coefficients = equ->need_new_coefficients ||
|
||||||
|
(band->width != width);
|
||||||
band->width = width;
|
band->width = width;
|
||||||
if (GST_AUDIO_FILTER (equ)->format.rate) {
|
|
||||||
setup_filter (equ, band);
|
|
||||||
}
|
|
||||||
gst_object_unref (equ);
|
gst_object_unref (equ);
|
||||||
GST_DEBUG_OBJECT (band, "changed width = %lf ", band->width);
|
GST_DEBUG_OBJECT (band, "changed width = %lf ", band->width);
|
||||||
}
|
}
|
||||||
@ -310,6 +311,7 @@ static void
|
|||||||
gst_iir_equalizer_base_init (gpointer g_class)
|
gst_iir_equalizer_base_init (gpointer g_class)
|
||||||
{
|
{
|
||||||
GstAudioFilterClass *audiofilter_class = GST_AUDIO_FILTER_CLASS (g_class);
|
GstAudioFilterClass *audiofilter_class = GST_AUDIO_FILTER_CLASS (g_class);
|
||||||
|
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
|
|
||||||
caps = gst_caps_from_string (ALLOWED_CAPS);
|
caps = gst_caps_from_string (ALLOWED_CAPS);
|
||||||
@ -321,7 +323,9 @@ static void
|
|||||||
gst_iir_equalizer_class_init (GstIirEqualizerClass * klass)
|
gst_iir_equalizer_class_init (GstIirEqualizerClass * klass)
|
||||||
{
|
{
|
||||||
GstAudioFilterClass *audio_filter_class = (GstAudioFilterClass *) klass;
|
GstAudioFilterClass *audio_filter_class = (GstAudioFilterClass *) klass;
|
||||||
|
|
||||||
GstBaseTransformClass *btrans_class = (GstBaseTransformClass *) klass;
|
GstBaseTransformClass *btrans_class = (GstBaseTransformClass *) klass;
|
||||||
|
|
||||||
GObjectClass *gobject_class = (GObjectClass *) klass;
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
||||||
|
|
||||||
gobject_class->finalize = gst_iir_equalizer_finalize;
|
gobject_class->finalize = gst_iir_equalizer_finalize;
|
||||||
@ -333,13 +337,14 @@ gst_iir_equalizer_class_init (GstIirEqualizerClass * klass)
|
|||||||
static void
|
static void
|
||||||
gst_iir_equalizer_init (GstIirEqualizer * eq, GstIirEqualizerClass * g_class)
|
gst_iir_equalizer_init (GstIirEqualizer * eq, GstIirEqualizerClass * g_class)
|
||||||
{
|
{
|
||||||
/* nothing to do here */
|
eq->need_new_coefficients = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_iir_equalizer_finalize (GObject * object)
|
gst_iir_equalizer_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
|
GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
|
||||||
|
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
for (i = 0; i < equ->freq_band_count; i++) {
|
for (i = 0; i < equ->freq_band_count; i++) {
|
||||||
@ -385,7 +390,9 @@ setup_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
gdouble gain, omega, bw;
|
gdouble gain, omega, bw;
|
||||||
|
|
||||||
gdouble edge_gain, gamma;
|
gdouble edge_gain, gamma;
|
||||||
|
|
||||||
gdouble alpha, beta;
|
gdouble alpha, beta;
|
||||||
|
|
||||||
|
|
||||||
@ -414,6 +421,7 @@ setup_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
|
|||||||
band->a2 = 0.0;
|
band->a2 = 0.0;
|
||||||
band->b1 = 0.0;
|
band->b1 = 0.0;
|
||||||
band->b2 = 0.0;
|
band->b2 = 0.0;
|
||||||
|
gain = 1.0;
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
bw = 2.0 * M_PI * (band->width / GST_AUDIO_FILTER (equ)->format.rate);
|
bw = 2.0 * M_PI * (band->width / GST_AUDIO_FILTER (equ)->format.rate);
|
||||||
@ -439,11 +447,38 @@ setup_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_passthrough (GstIirEqualizer * equ)
|
||||||
|
{
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
gboolean passthrough = TRUE;
|
||||||
|
|
||||||
|
for (i = 0; i < equ->freq_band_count; i++) {
|
||||||
|
passthrough = passthrough && (equ->bands[i]->gain == 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (equ), passthrough);
|
||||||
|
GST_DEBUG ("Passthrough mode: %d\n", passthrough);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_coefficients (GstIirEqualizer * equ)
|
||||||
|
{
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
for (i = 0; i < equ->freq_band_count; i++) {
|
||||||
|
setup_filter (equ, equ->bands[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_iir_equalizer_compute_frequencies (GstIirEqualizer * equ, guint new_count)
|
gst_iir_equalizer_compute_frequencies (GstIirEqualizer * equ, guint new_count)
|
||||||
{
|
{
|
||||||
guint old_count, i;
|
guint old_count, i;
|
||||||
|
|
||||||
gdouble freq0, freq1, step;
|
gdouble freq0, freq1, step;
|
||||||
|
|
||||||
gchar name[20];
|
gchar name[20];
|
||||||
|
|
||||||
old_count = equ->freq_band_count;
|
old_count = equ->freq_band_count;
|
||||||
@ -503,12 +538,7 @@ gst_iir_equalizer_compute_frequencies (GstIirEqualizer * equ, guint new_count)
|
|||||||
freq0 = freq1;
|
freq0 = freq1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
equ->need_new_coefficients = TRUE;
|
||||||
if (GST_AUDIO_FILTER (equ)->format.rate) {
|
|
||||||
for (i = 0; i < new_count; i++) {
|
|
||||||
setup_filter (equ, equ->bands[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* start of code that is type specific */
|
/* start of code that is type specific */
|
||||||
@ -572,7 +602,9 @@ static GstFlowReturn
|
|||||||
gst_iir_equalizer_transform_ip (GstBaseTransform * btrans, GstBuffer * buf)
|
gst_iir_equalizer_transform_ip (GstBaseTransform * btrans, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstAudioFilter *filter = GST_AUDIO_FILTER (btrans);
|
GstAudioFilter *filter = GST_AUDIO_FILTER (btrans);
|
||||||
|
|
||||||
GstIirEqualizer *equ = GST_IIR_EQUALIZER (btrans);
|
GstIirEqualizer *equ = GST_IIR_EQUALIZER (btrans);
|
||||||
|
|
||||||
GstClockTime timestamp;
|
GstClockTime timestamp;
|
||||||
|
|
||||||
if (gst_base_transform_is_passthrough (btrans))
|
if (gst_base_transform_is_passthrough (btrans))
|
||||||
@ -581,6 +613,11 @@ gst_iir_equalizer_transform_ip (GstBaseTransform * btrans, GstBuffer * buf)
|
|||||||
if (G_UNLIKELY (filter->format.channels < 1 || equ->process == NULL))
|
if (G_UNLIKELY (filter->format.channels < 1 || equ->process == NULL))
|
||||||
return GST_FLOW_NOT_NEGOTIATED;
|
return GST_FLOW_NOT_NEGOTIATED;
|
||||||
|
|
||||||
|
if (equ->need_new_coefficients) {
|
||||||
|
update_coefficients (equ);
|
||||||
|
set_passthrough (equ);
|
||||||
|
}
|
||||||
|
|
||||||
timestamp = GST_BUFFER_TIMESTAMP (buf);
|
timestamp = GST_BUFFER_TIMESTAMP (buf);
|
||||||
timestamp =
|
timestamp =
|
||||||
gst_segment_to_stream_time (&btrans->segment, GST_FORMAT_TIME, timestamp);
|
gst_segment_to_stream_time (&btrans->segment, GST_FORMAT_TIME, timestamp);
|
||||||
|
@ -60,6 +60,8 @@ struct _GstIirEqualizer
|
|||||||
gpointer history;
|
gpointer history;
|
||||||
guint history_size;
|
guint history_size;
|
||||||
|
|
||||||
|
gboolean need_new_coefficients;
|
||||||
|
|
||||||
ProcessFunc process;
|
ProcessFunc process;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user