2 * Copyright (C) <2004> Benjamin Otte <otte@gnome.org>
3 * <2007> Stefan Kost <ensonic@users.sf.net>
4 * <2007> Sebastian Dröge <slomo@circular-chaos.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
29 #include "gstiirequalizer.h"
30 #include "gstiirequalizernbands.h"
31 #include "gstiirequalizer3bands.h"
32 #include "gstiirequalizer10bands.h"
34 GST_DEBUG_CATEGORY (equalizer_debug);
35 #define GST_CAT_DEFAULT equalizer_debug
37 #define BANDS_LOCK(equ) g_mutex_lock(equ->bands_lock)
38 #define BANDS_UNLOCK(equ) g_mutex_unlock(equ->bands_lock)
40 static void gst_iir_equalizer_child_proxy_interface_init (gpointer g_iface,
43 static void gst_iir_equalizer_finalize (GObject * object);
45 static gboolean gst_iir_equalizer_setup (GstAudioFilter * filter,
46 const GstAudioInfo * info);
47 static GstFlowReturn gst_iir_equalizer_transform_ip (GstBaseTransform * btrans,
50 #define ALLOWED_CAPS \
52 " format=(string) {"GST_AUDIO_NE(S16)","GST_AUDIO_NE(F32)"," \
53 GST_AUDIO_NE(F64)" }, " \
54 " rate=(int)[1000,MAX]," \
55 " channels=(int)[1,MAX]"
57 #define gst_iir_equalizer_parent_class parent_class
58 G_DEFINE_TYPE_WITH_CODE (GstIirEqualizer, gst_iir_equalizer,
59 GST_TYPE_AUDIO_FILTER,
60 G_IMPLEMENT_INTERFACE (GST_TYPE_CHILD_PROXY,
61 gst_iir_equalizer_child_proxy_interface_init));
79 } GstIirEqualizerBandType;
81 #define GST_TYPE_IIR_EQUALIZER_BAND_TYPE (gst_iir_equalizer_band_type_get_type ())
83 gst_iir_equalizer_band_type_get_type (void)
85 static GType gtype = 0;
88 static const GEnumValue values[] = {
89 {BAND_TYPE_PEAK, "Peak filter (default for inner bands)", "peak"},
90 {BAND_TYPE_LOW_SHELF, "Low shelf filter (default for first band)",
92 {BAND_TYPE_HIGH_SHELF, "High shelf filter (default for last band)",
97 gtype = g_enum_register_static ("GstIirEqualizerBandType", values);
103 typedef struct _GstIirEqualizerBandClass GstIirEqualizerBandClass;
105 #define GST_TYPE_IIR_EQUALIZER_BAND \
106 (gst_iir_equalizer_band_get_type())
107 #define GST_IIR_EQUALIZER_BAND(obj) \
108 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IIR_EQUALIZER_BAND,GstIirEqualizerBand))
109 #define GST_IIR_EQUALIZER_BAND_CLASS(klass) \
110 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IIR_EQUALIZER_BAND,GstIirEqualizerBandClass))
111 #define GST_IS_IIR_EQUALIZER_BAND(obj) \
112 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IIR_EQUALIZER_BAND))
113 #define GST_IS_IIR_EQUALIZER_BAND_CLASS(klass) \
114 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IIR_EQUALIZER_BAND))
116 struct _GstIirEqualizerBand
121 /* center frequency and gain */
125 GstIirEqualizerBandType type;
127 /* second order iir filter */
128 gdouble b1, b2; /* IIR coefficients for outputs */
129 gdouble a0, a1, a2; /* IIR coefficients for inputs */
132 struct _GstIirEqualizerBandClass
134 GstObjectClass parent_class;
137 static GType gst_iir_equalizer_band_get_type (void);
140 gst_iir_equalizer_band_set_property (GObject * object, guint prop_id,
141 const GValue * value, GParamSpec * pspec)
143 GstIirEqualizerBand *band = GST_IIR_EQUALIZER_BAND (object);
144 GstIirEqualizer *equ =
145 GST_IIR_EQUALIZER (gst_object_get_parent (GST_OBJECT (band)));
151 gain = g_value_get_double (value);
152 GST_DEBUG_OBJECT (band, "gain = %lf -> %lf", band->gain, gain);
153 if (gain != band->gain) {
155 equ->need_new_coefficients = TRUE;
158 GST_DEBUG_OBJECT (band, "changed gain = %lf ", band->gain);
165 freq = g_value_get_double (value);
166 GST_DEBUG_OBJECT (band, "freq = %lf -> %lf", band->freq, freq);
167 if (freq != band->freq) {
169 equ->need_new_coefficients = TRUE;
172 GST_DEBUG_OBJECT (band, "changed freq = %lf ", band->freq);
176 case PROP_BANDWIDTH:{
179 width = g_value_get_double (value);
180 GST_DEBUG_OBJECT (band, "width = %lf -> %lf", band->width, width);
181 if (width != band->width) {
183 equ->need_new_coefficients = TRUE;
186 GST_DEBUG_OBJECT (band, "changed width = %lf ", band->width);
191 GstIirEqualizerBandType type;
193 type = g_value_get_enum (value);
194 GST_DEBUG_OBJECT (band, "type = %d -> %d", band->type, type);
195 if (type != band->type) {
197 equ->need_new_coefficients = TRUE;
200 GST_DEBUG_OBJECT (band, "changed type = %d ", band->type);
205 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
209 gst_object_unref (equ);
213 gst_iir_equalizer_band_get_property (GObject * object, guint prop_id,
214 GValue * value, GParamSpec * pspec)
216 GstIirEqualizerBand *band = GST_IIR_EQUALIZER_BAND (object);
220 g_value_set_double (value, band->gain);
223 g_value_set_double (value, band->freq);
226 g_value_set_double (value, band->width);
229 g_value_set_enum (value, band->type);
232 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
238 gst_iir_equalizer_band_class_init (GstIirEqualizerBandClass * klass)
240 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
242 gobject_class->set_property = gst_iir_equalizer_band_set_property;
243 gobject_class->get_property = gst_iir_equalizer_band_get_property;
245 g_object_class_install_property (gobject_class, PROP_GAIN,
246 g_param_spec_double ("gain", "gain",
247 "gain for the frequency band ranging from -24.0 dB to +12.0 dB",
249 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
251 g_object_class_install_property (gobject_class, PROP_FREQ,
252 g_param_spec_double ("freq", "freq",
253 "center frequency of the band",
255 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
257 g_object_class_install_property (gobject_class, PROP_BANDWIDTH,
258 g_param_spec_double ("bandwidth", "bandwidth",
259 "difference between bandedges in Hz",
261 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
263 g_object_class_install_property (gobject_class, PROP_TYPE,
264 g_param_spec_enum ("type", "Type",
265 "Filter type", GST_TYPE_IIR_EQUALIZER_BAND_TYPE,
267 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
271 gst_iir_equalizer_band_init (GstIirEqualizerBand * band,
272 GstIirEqualizerBandClass * klass)
277 band->type = BAND_TYPE_PEAK;
281 gst_iir_equalizer_band_get_type (void)
283 static GType type = 0;
285 if (G_UNLIKELY (!type)) {
286 const GTypeInfo type_info = {
287 sizeof (GstIirEqualizerBandClass),
290 (GClassInitFunc) gst_iir_equalizer_band_class_init,
293 sizeof (GstIirEqualizerBand),
295 (GInstanceInitFunc) gst_iir_equalizer_band_init,
298 g_type_register_static (GST_TYPE_OBJECT, "GstIirEqualizerBand",
305 /* child proxy iface */
307 gst_iir_equalizer_child_proxy_get_child_by_index (GstChildProxy * child_proxy,
310 GstIirEqualizer *equ = GST_IIR_EQUALIZER (child_proxy);
314 if (G_UNLIKELY (index >= equ->freq_band_count)) {
316 g_return_val_if_fail (index < equ->freq_band_count, NULL);
319 ret = gst_object_ref (equ->bands[index]);
322 GST_LOG_OBJECT (equ, "return child[%d] %" GST_PTR_FORMAT, index, ret);
327 gst_iir_equalizer_child_proxy_get_children_count (GstChildProxy * child_proxy)
329 GstIirEqualizer *equ = GST_IIR_EQUALIZER (child_proxy);
331 GST_LOG ("we have %d children", equ->freq_band_count);
332 return equ->freq_band_count;
336 gst_iir_equalizer_child_proxy_interface_init (gpointer g_iface,
339 GstChildProxyInterface *iface = g_iface;
341 GST_DEBUG ("initializing iface");
343 iface->get_child_by_index = gst_iir_equalizer_child_proxy_get_child_by_index;
344 iface->get_children_count = gst_iir_equalizer_child_proxy_get_children_count;
348 /* equalizer implementation */
351 gst_iir_equalizer_class_init (GstIirEqualizerClass * klass)
353 GstAudioFilterClass *audio_filter_class = (GstAudioFilterClass *) klass;
354 GstBaseTransformClass *btrans_class = (GstBaseTransformClass *) klass;
355 GObjectClass *gobject_class = (GObjectClass *) klass;
358 gobject_class->finalize = gst_iir_equalizer_finalize;
359 audio_filter_class->setup = gst_iir_equalizer_setup;
360 btrans_class->transform_ip = gst_iir_equalizer_transform_ip;
362 caps = gst_caps_from_string (ALLOWED_CAPS);
363 gst_audio_filter_class_add_pad_templates (audio_filter_class, caps);
364 gst_caps_unref (caps);
368 gst_iir_equalizer_init (GstIirEqualizer * eq)
370 eq->bands_lock = g_mutex_new ();
371 eq->need_new_coefficients = TRUE;
375 gst_iir_equalizer_finalize (GObject * object)
377 GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
380 for (i = 0; i < equ->freq_band_count; i++) {
382 gst_object_unparent (GST_OBJECT (equ->bands[i]));
383 equ->bands[i] = NULL;
385 equ->freq_band_count = 0;
388 g_free (equ->history);
390 g_mutex_free (equ->bands_lock);
392 G_OBJECT_CLASS (parent_class)->finalize (object);
397 * The Equivalence of Various Methods of Computing
398 * Biquad Coefficients for Audio Parametric Equalizers
400 * by Robert Bristow-Johnson
402 * http://www.aes.org/e-lib/browse.cfm?elib=6326
403 * http://www.musicdsp.org/files/EQ-Coefficients.pdf
404 * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
406 * The bandwidth method that we use here is the preferred
407 * one from this article transformed from octaves to frequency
410 static inline gdouble
411 arg_to_scale (gdouble arg)
413 return (pow (10.0, arg / 40.0));
417 calculate_omega (gdouble freq, gint rate)
421 if (freq / rate >= 0.5)
423 else if (freq <= 0.0)
426 omega = 2.0 * G_PI * (freq / rate);
432 calculate_bw (GstIirEqualizerBand * band, gint rate)
436 if (band->width / rate >= 0.5) {
437 /* If bandwidth == 0.5 the calculation below fails as tan(G_PI/2)
438 * is undefined. So set the bandwidth to a slightly smaller value.
440 bw = G_PI - 0.00000001;
441 } else if (band->width <= 0.0) {
442 /* If bandwidth == 0 this band won't change anything so set
443 * the coefficients accordingly. The coefficient calculation
444 * below would create coefficients that for some reason amplify
453 bw = 2.0 * G_PI * (band->width / rate);
459 setup_peak_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
461 gint rate = GST_AUDIO_FILTER_RATE (equ);
463 g_return_if_fail (rate);
466 gdouble gain, omega, bw;
467 gdouble alpha, alpha1, alpha2, b0;
469 gain = arg_to_scale (band->gain);
470 omega = calculate_omega (band->freq, rate);
471 bw = calculate_bw (band, rate);
475 alpha = tan (bw / 2.0);
477 alpha1 = alpha * gain;
478 alpha2 = alpha / gain;
482 band->a0 = (1.0 + alpha1) / b0;
483 band->a1 = (-2.0 * cos (omega)) / b0;
484 band->a2 = (1.0 - alpha1) / b0;
485 band->b1 = (2.0 * cos (omega)) / b0;
486 band->b2 = -(1.0 - alpha2) / b0;
490 ("gain = %5.1f, width= %7.2f, freq = %7.2f, a0 = %7.5g, a1 = %7.5g, a2=%7.5g b1 = %7.5g, b2 = %7.5g",
491 band->gain, band->width, band->freq, band->a0, band->a1, band->a2,
497 setup_low_shelf_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
499 gint rate = GST_AUDIO_FILTER_RATE (equ);
501 g_return_if_fail (rate);
504 gdouble gain, omega, bw;
505 gdouble alpha, delta, b0;
508 gain = arg_to_scale (band->gain);
509 omega = calculate_omega (band->freq, rate);
510 bw = calculate_bw (band, rate);
516 alpha = tan (bw / 2.0);
518 delta = 2.0 * sqrt (gain) * alpha;
519 b0 = egp + egm * cos (omega) + delta;
521 band->a0 = ((egp - egm * cos (omega) + delta) * gain) / b0;
522 band->a1 = ((egm - egp * cos (omega)) * 2.0 * gain) / b0;
523 band->a2 = ((egp - egm * cos (omega) - delta) * gain) / b0;
524 band->b1 = ((egm + egp * cos (omega)) * 2.0) / b0;
525 band->b2 = -((egp + egm * cos (omega) - delta)) / b0;
530 ("gain = %5.1f, width= %7.2f, freq = %7.2f, a0 = %7.5g, a1 = %7.5g, a2=%7.5g b1 = %7.5g, b2 = %7.5g",
531 band->gain, band->width, band->freq, band->a0, band->a1, band->a2,
537 setup_high_shelf_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
539 gint rate = GST_AUDIO_FILTER_RATE (equ);
541 g_return_if_fail (rate);
544 gdouble gain, omega, bw;
545 gdouble alpha, delta, b0;
548 gain = arg_to_scale (band->gain);
549 omega = calculate_omega (band->freq, rate);
550 bw = calculate_bw (band, rate);
556 alpha = tan (bw / 2.0);
558 delta = 2.0 * sqrt (gain) * alpha;
559 b0 = egp - egm * cos (omega) + delta;
561 band->a0 = ((egp + egm * cos (omega) + delta) * gain) / b0;
562 band->a1 = ((egm + egp * cos (omega)) * -2.0 * gain) / b0;
563 band->a2 = ((egp + egm * cos (omega) - delta) * gain) / b0;
564 band->b1 = ((egm - egp * cos (omega)) * -2.0) / b0;
565 band->b2 = -((egp - egm * cos (omega) - delta)) / b0;
570 ("gain = %5.1f, width= %7.2f, freq = %7.2f, a0 = %7.5g, a1 = %7.5g, a2=%7.5g b1 = %7.5g, b2 = %7.5g",
571 band->gain, band->width, band->freq, band->a0, band->a1, band->a2,
576 /* Must be called with bands_lock and transform lock! */
578 set_passthrough (GstIirEqualizer * equ)
581 gboolean passthrough = TRUE;
583 for (i = 0; i < equ->freq_band_count; i++) {
584 passthrough = passthrough && (equ->bands[i]->gain == 0.0);
587 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (equ), passthrough);
588 GST_DEBUG ("Passthrough mode: %d\n", passthrough);
591 /* Must be called with bands_lock and transform lock! */
593 update_coefficients (GstIirEqualizer * equ)
595 gint i, n = equ->freq_band_count;
597 for (i = 0; i < n; i++) {
598 if (equ->bands[i]->type == BAND_TYPE_PEAK)
599 setup_peak_filter (equ, equ->bands[i]);
600 else if (equ->bands[i]->type == BAND_TYPE_LOW_SHELF)
601 setup_low_shelf_filter (equ, equ->bands[i]);
603 setup_high_shelf_filter (equ, equ->bands[i]);
606 equ->need_new_coefficients = FALSE;
609 /* Must be called with transform lock! */
611 alloc_history (GstIirEqualizer * equ)
613 /* free + alloc = no memcpy */
614 g_free (equ->history);
616 g_malloc0 (equ->history_size * GST_AUDIO_FILTER_CHANNELS (equ) *
617 equ->freq_band_count);
621 gst_iir_equalizer_compute_frequencies (GstIirEqualizer * equ, guint new_count)
624 gdouble freq0, freq1, step;
627 if (equ->freq_band_count == new_count)
632 if (G_UNLIKELY (equ->freq_band_count == new_count)) {
637 old_count = equ->freq_band_count;
638 equ->freq_band_count = new_count;
639 GST_DEBUG ("bands %u -> %u", old_count, new_count);
641 if (old_count < new_count) {
643 equ->bands = g_realloc (equ->bands, sizeof (GstObject *) * new_count);
644 for (i = old_count; i < new_count; i++) {
645 /* otherwise they get names like 'iirequalizerband5' */
646 sprintf (name, "band%u", i);
647 equ->bands[i] = g_object_new (GST_TYPE_IIR_EQUALIZER_BAND,
649 GST_DEBUG ("adding band[%d]=%p", i, equ->bands[i]);
651 gst_object_set_parent (GST_OBJECT (equ->bands[i]), GST_OBJECT (equ));
652 gst_child_proxy_child_added (GST_OBJECT (equ),
653 GST_OBJECT (equ->bands[i]));
656 /* free unused bands */
657 for (i = new_count; i < old_count; i++) {
658 GST_DEBUG ("removing band[%d]=%p", i, equ->bands[i]);
659 gst_child_proxy_child_removed (GST_OBJECT (equ),
660 GST_OBJECT (equ->bands[i]));
661 gst_object_unparent (GST_OBJECT (equ->bands[i]));
662 equ->bands[i] = NULL;
668 /* set center frequencies and name band objects
669 * FIXME: arg! we can't change the name of parented objects :(
670 * application should read band->freq to get the name
673 step = pow (HIGHEST_FREQ / LOWEST_FREQ, 1.0 / new_count);
675 for (i = 0; i < new_count; i++) {
676 freq1 = freq0 * step;
679 equ->bands[i]->type = BAND_TYPE_LOW_SHELF;
680 else if (i == new_count - 1)
681 equ->bands[i]->type = BAND_TYPE_HIGH_SHELF;
683 equ->bands[i]->type = BAND_TYPE_PEAK;
685 equ->bands[i]->freq = freq0 + ((freq1 - freq0) / 2.0);
686 equ->bands[i]->width = freq1 - freq0;
687 GST_DEBUG ("band[%2d] = '%lf'", i, equ->bands[i]->freq);
689 g_object_notify (G_OBJECT (equ->bands[i]), "bandwidth");
690 g_object_notify (G_OBJECT (equ->bands[i]), "freq");
691 g_object_notify (G_OBJECT (equ->bands[i]), "type");
694 if(equ->bands[i]->freq<10000.0)
695 sprintf (name,"%dHz",(gint)equ->bands[i]->freq);
697 sprintf (name,"%dkHz",(gint)(equ->bands[i]->freq/1000.0));
698 gst_object_set_name( GST_OBJECT (equ->bands[i]), name);
699 GST_DEBUG ("band[%2d] = '%s'",i,name);
704 equ->need_new_coefficients = TRUE;
708 /* start of code that is type specific */
710 #define CREATE_OPTIMIZED_FUNCTIONS_INT(TYPE,BIG_TYPE,MIN_VAL,MAX_VAL) \
712 BIG_TYPE x1, x2; /* history of input values for a filter */ \
713 BIG_TYPE y1, y2; /* history of output values for a filter */ \
714 } SecondOrderHistory ## TYPE; \
716 static inline BIG_TYPE \
717 one_step_ ## TYPE (GstIirEqualizerBand *filter, \
718 SecondOrderHistory ## TYPE *history, BIG_TYPE input) \
720 /* calculate output */ \
721 BIG_TYPE output = filter->a0 * input + \
722 filter->a1 * history->x1 + filter->a2 * history->x2 + \
723 filter->b1 * history->y1 + filter->b2 * history->y2; \
724 /* update history */ \
725 history->y2 = history->y1; \
726 history->y1 = output; \
727 history->x2 = history->x1; \
728 history->x1 = input; \
734 history_size_ ## TYPE = sizeof (SecondOrderHistory ## TYPE); \
737 gst_iir_equ_process_ ## TYPE (GstIirEqualizer *equ, guint8 *data, \
738 guint size, guint channels) \
740 guint frames = size / channels / sizeof (TYPE); \
741 guint i, c, f, nf = equ->freq_band_count; \
743 GstIirEqualizerBand **filters = equ->bands; \
745 for (i = 0; i < frames; i++) { \
746 SecondOrderHistory ## TYPE *history = equ->history; \
747 for (c = 0; c < channels; c++) { \
748 cur = *((TYPE *) data); \
749 for (f = 0; f < nf; f++) { \
750 cur = one_step_ ## TYPE (filters[f], history, cur); \
753 cur = CLAMP (cur, MIN_VAL, MAX_VAL); \
754 *((TYPE *) data) = (TYPE) floor (cur); \
755 data += sizeof (TYPE); \
760 #define CREATE_OPTIMIZED_FUNCTIONS(TYPE) \
762 TYPE x1, x2; /* history of input values for a filter */ \
763 TYPE y1, y2; /* history of output values for a filter */ \
764 } SecondOrderHistory ## TYPE; \
767 one_step_ ## TYPE (GstIirEqualizerBand *filter, \
768 SecondOrderHistory ## TYPE *history, TYPE input) \
770 /* calculate output */ \
771 TYPE output = filter->a0 * input + filter->a1 * history->x1 + \
772 filter->a2 * history->x2 + filter->b1 * history->y1 + \
773 filter->b2 * history->y2; \
774 /* update history */ \
775 history->y2 = history->y1; \
776 history->y1 = output; \
777 history->x2 = history->x1; \
778 history->x1 = input; \
784 history_size_ ## TYPE = sizeof (SecondOrderHistory ## TYPE); \
787 gst_iir_equ_process_ ## TYPE (GstIirEqualizer *equ, guint8 *data, \
788 guint size, guint channels) \
790 guint frames = size / channels / sizeof (TYPE); \
791 guint i, c, f, nf = equ->freq_band_count; \
793 GstIirEqualizerBand **filters = equ->bands; \
795 for (i = 0; i < frames; i++) { \
796 SecondOrderHistory ## TYPE *history = equ->history; \
797 for (c = 0; c < channels; c++) { \
798 cur = *((TYPE *) data); \
799 for (f = 0; f < nf; f++) { \
800 cur = one_step_ ## TYPE (filters[f], history, cur); \
803 *((TYPE *) data) = (TYPE) cur; \
804 data += sizeof (TYPE); \
809 CREATE_OPTIMIZED_FUNCTIONS_INT (gint16, gfloat, -32768.0, 32767.0);
810 CREATE_OPTIMIZED_FUNCTIONS (gfloat);
811 CREATE_OPTIMIZED_FUNCTIONS (gdouble);
814 gst_iir_equalizer_transform_ip (GstBaseTransform * btrans, GstBuffer * buf)
816 GstAudioFilter *filter = GST_AUDIO_FILTER (btrans);
817 GstIirEqualizer *equ = GST_IIR_EQUALIZER (btrans);
818 GstClockTime timestamp;
821 gint channels = GST_AUDIO_FILTER_CHANNELS (filter);
823 if (G_UNLIKELY (channels < 1 || equ->process == NULL))
824 return GST_FLOW_NOT_NEGOTIATED;
827 if (equ->need_new_coefficients) {
828 update_coefficients (equ);
829 set_passthrough (equ);
833 if (gst_base_transform_is_passthrough (btrans))
836 timestamp = GST_BUFFER_TIMESTAMP (buf);
838 gst_segment_to_stream_time (&btrans->segment, GST_FORMAT_TIME, timestamp);
840 if (GST_CLOCK_TIME_IS_VALID (timestamp))
841 gst_object_sync_values (G_OBJECT (equ), timestamp);
843 data = gst_buffer_map (buf, &size, NULL, GST_MAP_WRITE);
844 equ->process (equ, data, size, channels);
845 gst_buffer_unmap (buf, data, size);
851 gst_iir_equalizer_setup (GstAudioFilter * audio, const GstAudioInfo * info)
853 GstIirEqualizer *equ = GST_IIR_EQUALIZER (audio);
855 switch (GST_AUDIO_INFO_FORMAT (info)) {
856 case GST_AUDIO_FORMAT_S16:
857 equ->history_size = history_size_gint16;
858 equ->process = gst_iir_equ_process_gint16;
860 case GST_AUDIO_FORMAT_F32:
861 equ->history_size = history_size_gfloat;
862 equ->process = gst_iir_equ_process_gfloat;
864 case GST_AUDIO_FORMAT_F64:
865 equ->history_size = history_size_gdouble;
866 equ->process = gst_iir_equ_process_gdouble;
878 plugin_init (GstPlugin * plugin)
880 GST_DEBUG_CATEGORY_INIT (equalizer_debug, "equalizer", 0, "equalizer");
882 if (!(gst_element_register (plugin, "equalizer-nbands", GST_RANK_NONE,
883 GST_TYPE_IIR_EQUALIZER_NBANDS)))
886 if (!(gst_element_register (plugin, "equalizer-3bands", GST_RANK_NONE,
887 GST_TYPE_IIR_EQUALIZER_3BANDS)))
890 if (!(gst_element_register (plugin, "equalizer-10bands", GST_RANK_NONE,
891 GST_TYPE_IIR_EQUALIZER_10BANDS)))
897 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
900 "GStreamer audio equalizers",
901 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)