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 GstRingBufferSpec * fmt);
47 static GstFlowReturn gst_iir_equalizer_transform_ip (GstBaseTransform * btrans,
50 #define ALLOWED_CAPS \
54 " endianness=(int)BYTE_ORDER," \
55 " signed=(bool)TRUE," \
56 " rate=(int)[1000,MAX]," \
57 " channels=(int)[1,MAX]; " \
58 "audio/x-raw-float," \
59 " width=(int) { 32, 64 } ," \
60 " endianness=(int)BYTE_ORDER," \
61 " rate=(int)[1000,MAX]," \
62 " channels=(int)[1,MAX]"
65 _do_init (GType object_type)
67 const GInterfaceInfo child_proxy_interface_info = {
68 (GInterfaceInitFunc) gst_iir_equalizer_child_proxy_interface_init,
69 NULL, /* interface_finalize */
70 NULL /* interface_data */
73 g_type_add_interface_static (object_type, GST_TYPE_CHILD_PROXY,
74 &child_proxy_interface_info);
77 GST_BOILERPLATE_FULL (GstIirEqualizer, gst_iir_equalizer,
78 GstAudioFilter, GST_TYPE_AUDIO_FILTER, _do_init);
95 } GstIirEqualizerBandType;
97 #define GST_TYPE_IIR_EQUALIZER_BAND_TYPE (gst_iir_equalizer_band_type_get_type ())
99 gst_iir_equalizer_band_type_get_type (void)
101 static GType gtype = 0;
104 static const GEnumValue values[] = {
105 {BAND_TYPE_PEAK, "Peak filter (default for inner bands)", "peak"},
106 {BAND_TYPE_LOW_SHELF, "Low shelf filter (default for first band)",
108 {BAND_TYPE_HIGH_SHELF, "High shelf filter (default for last band)",
113 gtype = g_enum_register_static ("GstIirEqualizerBandType", values);
119 typedef struct _GstIirEqualizerBandClass GstIirEqualizerBandClass;
121 #define GST_TYPE_IIR_EQUALIZER_BAND \
122 (gst_iir_equalizer_band_get_type())
123 #define GST_IIR_EQUALIZER_BAND(obj) \
124 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IIR_EQUALIZER_BAND,GstIirEqualizerBand))
125 #define GST_IIR_EQUALIZER_BAND_CLASS(klass) \
126 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IIR_EQUALIZER_BAND,GstIirEqualizerBandClass))
127 #define GST_IS_IIR_EQUALIZER_BAND(obj) \
128 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IIR_EQUALIZER_BAND))
129 #define GST_IS_IIR_EQUALIZER_BAND_CLASS(klass) \
130 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IIR_EQUALIZER_BAND))
132 struct _GstIirEqualizerBand
137 /* center frequency and gain */
141 GstIirEqualizerBandType type;
143 /* second order iir filter */
144 gdouble b1, b2; /* IIR coefficients for outputs */
145 gdouble a0, a1, a2; /* IIR coefficients for inputs */
148 struct _GstIirEqualizerBandClass
150 GstObjectClass parent_class;
153 static GType gst_iir_equalizer_band_get_type (void);
156 gst_iir_equalizer_band_set_property (GObject * object, guint prop_id,
157 const GValue * value, GParamSpec * pspec)
159 GstIirEqualizerBand *band = GST_IIR_EQUALIZER_BAND (object);
160 GstIirEqualizer *equ =
161 GST_IIR_EQUALIZER (gst_object_get_parent (GST_OBJECT (band)));
167 gain = g_value_get_double (value);
168 GST_DEBUG_OBJECT (band, "gain = %lf -> %lf", band->gain, gain);
169 if (gain != band->gain) {
171 equ->need_new_coefficients = TRUE;
174 GST_DEBUG_OBJECT (band, "changed gain = %lf ", band->gain);
181 freq = g_value_get_double (value);
182 GST_DEBUG_OBJECT (band, "freq = %lf -> %lf", band->freq, freq);
183 if (freq != band->freq) {
185 equ->need_new_coefficients = TRUE;
188 GST_DEBUG_OBJECT (band, "changed freq = %lf ", band->freq);
192 case PROP_BANDWIDTH:{
195 width = g_value_get_double (value);
196 GST_DEBUG_OBJECT (band, "width = %lf -> %lf", band->width, width);
197 if (width != band->width) {
199 equ->need_new_coefficients = TRUE;
202 GST_DEBUG_OBJECT (band, "changed width = %lf ", band->width);
207 GstIirEqualizerBandType type;
209 type = g_value_get_enum (value);
210 GST_DEBUG_OBJECT (band, "type = %d -> %d", band->type, type);
211 if (type != band->type) {
213 equ->need_new_coefficients = TRUE;
216 GST_DEBUG_OBJECT (band, "changed type = %d ", band->type);
221 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
225 gst_object_unref (equ);
229 gst_iir_equalizer_band_get_property (GObject * object, guint prop_id,
230 GValue * value, GParamSpec * pspec)
232 GstIirEqualizerBand *band = GST_IIR_EQUALIZER_BAND (object);
236 g_value_set_double (value, band->gain);
239 g_value_set_double (value, band->freq);
242 g_value_set_double (value, band->width);
245 g_value_set_enum (value, band->type);
248 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
254 gst_iir_equalizer_band_class_init (GstIirEqualizerBandClass * klass)
256 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
258 gobject_class->set_property = gst_iir_equalizer_band_set_property;
259 gobject_class->get_property = gst_iir_equalizer_band_get_property;
261 g_object_class_install_property (gobject_class, PROP_GAIN,
262 g_param_spec_double ("gain", "gain",
263 "gain for the frequency band ranging from -24.0 dB to +12.0 dB",
265 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
267 g_object_class_install_property (gobject_class, PROP_FREQ,
268 g_param_spec_double ("freq", "freq",
269 "center frequency of the band",
271 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
273 g_object_class_install_property (gobject_class, PROP_BANDWIDTH,
274 g_param_spec_double ("bandwidth", "bandwidth",
275 "difference between bandedges in Hz",
277 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
279 g_object_class_install_property (gobject_class, PROP_TYPE,
280 g_param_spec_enum ("type", "Type",
281 "Filter type", GST_TYPE_IIR_EQUALIZER_BAND_TYPE,
283 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
287 gst_iir_equalizer_band_init (GstIirEqualizerBand * band,
288 GstIirEqualizerBandClass * klass)
293 band->type = BAND_TYPE_PEAK;
297 gst_iir_equalizer_band_get_type (void)
299 static GType type = 0;
301 if (G_UNLIKELY (!type)) {
302 const GTypeInfo type_info = {
303 sizeof (GstIirEqualizerBandClass),
306 (GClassInitFunc) gst_iir_equalizer_band_class_init,
309 sizeof (GstIirEqualizerBand),
311 (GInstanceInitFunc) gst_iir_equalizer_band_init,
314 g_type_register_static (GST_TYPE_OBJECT, "GstIirEqualizerBand",
321 /* child proxy iface */
323 gst_iir_equalizer_child_proxy_get_child_by_index (GstChildProxy * child_proxy,
326 GstIirEqualizer *equ = GST_IIR_EQUALIZER (child_proxy);
330 if (G_UNLIKELY (index >= equ->freq_band_count)) {
332 g_return_val_if_fail (index < equ->freq_band_count, NULL);
335 ret = gst_object_ref (equ->bands[index]);
338 GST_LOG_OBJECT (equ, "return child[%d] %" GST_PTR_FORMAT, index, ret);
343 gst_iir_equalizer_child_proxy_get_children_count (GstChildProxy * child_proxy)
345 GstIirEqualizer *equ = GST_IIR_EQUALIZER (child_proxy);
347 GST_LOG ("we have %d children", equ->freq_band_count);
348 return equ->freq_band_count;
352 gst_iir_equalizer_child_proxy_interface_init (gpointer g_iface,
355 GstChildProxyInterface *iface = g_iface;
357 GST_DEBUG ("initializing iface");
359 iface->get_child_by_index = gst_iir_equalizer_child_proxy_get_child_by_index;
360 iface->get_children_count = gst_iir_equalizer_child_proxy_get_children_count;
364 /* equalizer implementation */
367 gst_iir_equalizer_base_init (gpointer g_class)
369 GstAudioFilterClass *audiofilter_class = GST_AUDIO_FILTER_CLASS (g_class);
372 caps = gst_caps_from_string (ALLOWED_CAPS);
373 gst_audio_filter_class_add_pad_templates (audiofilter_class, caps);
374 gst_caps_unref (caps);
378 gst_iir_equalizer_class_init (GstIirEqualizerClass * klass)
380 GstAudioFilterClass *audio_filter_class = (GstAudioFilterClass *) klass;
381 GstBaseTransformClass *btrans_class = (GstBaseTransformClass *) klass;
382 GObjectClass *gobject_class = (GObjectClass *) klass;
384 gobject_class->finalize = gst_iir_equalizer_finalize;
385 audio_filter_class->setup = gst_iir_equalizer_setup;
386 btrans_class->transform_ip = gst_iir_equalizer_transform_ip;
390 gst_iir_equalizer_init (GstIirEqualizer * eq, GstIirEqualizerClass * g_class)
392 eq->bands_lock = g_mutex_new ();
393 eq->need_new_coefficients = TRUE;
397 gst_iir_equalizer_finalize (GObject * object)
399 GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
402 for (i = 0; i < equ->freq_band_count; i++) {
404 gst_object_unparent (GST_OBJECT (equ->bands[i]));
405 equ->bands[i] = NULL;
407 equ->freq_band_count = 0;
410 g_free (equ->history);
412 g_mutex_free (equ->bands_lock);
414 G_OBJECT_CLASS (parent_class)->finalize (object);
419 * The Equivalence of Various Methods of Computing
420 * Biquad Coefficients for Audio Parametric Equalizers
422 * by Robert Bristow-Johnson
424 * http://www.aes.org/e-lib/browse.cfm?elib=6326
425 * http://www.musicdsp.org/files/EQ-Coefficients.pdf
426 * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
428 * The bandwidth method that we use here is the preferred
429 * one from this article transformed from octaves to frequency
432 static inline gdouble
433 arg_to_scale (gdouble arg)
435 return (pow (10.0, arg / 40.0));
439 calculate_omega (gdouble freq, gint rate)
443 if (freq / rate >= 0.5)
445 else if (freq <= 0.0)
448 omega = 2.0 * G_PI * (freq / rate);
454 calculate_bw (GstIirEqualizerBand * band, gint rate)
458 if (band->width / rate >= 0.5) {
459 /* If bandwidth == 0.5 the calculation below fails as tan(G_PI/2)
460 * is undefined. So set the bandwidth to a slightly smaller value.
462 bw = G_PI - 0.00000001;
463 } else if (band->width <= 0.0) {
464 /* If bandwidth == 0 this band won't change anything so set
465 * the coefficients accordingly. The coefficient calculation
466 * below would create coefficients that for some reason amplify
475 bw = 2.0 * G_PI * (band->width / rate);
481 setup_peak_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
483 g_return_if_fail (GST_AUDIO_FILTER (equ)->format.rate);
486 gdouble gain, omega, bw;
487 gdouble alpha, alpha1, alpha2, b0;
489 gain = arg_to_scale (band->gain);
490 omega = calculate_omega (band->freq, GST_AUDIO_FILTER (equ)->format.rate);
491 bw = calculate_bw (band, GST_AUDIO_FILTER (equ)->format.rate);
495 alpha = tan (bw / 2.0);
497 alpha1 = alpha * gain;
498 alpha2 = alpha / gain;
502 band->a0 = (1.0 + alpha1) / b0;
503 band->a1 = (-2.0 * cos (omega)) / b0;
504 band->a2 = (1.0 - alpha1) / b0;
505 band->b1 = (2.0 * cos (omega)) / b0;
506 band->b2 = -(1.0 - alpha2) / b0;
510 ("gain = %5.1f, width= %7.2f, freq = %7.2f, a0 = %7.5g, a1 = %7.5g, a2=%7.5g b1 = %7.5g, b2 = %7.5g",
511 band->gain, band->width, band->freq, band->a0, band->a1, band->a2,
517 setup_low_shelf_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
519 g_return_if_fail (GST_AUDIO_FILTER (equ)->format.rate);
522 gdouble gain, omega, bw;
523 gdouble alpha, delta, b0;
526 gain = arg_to_scale (band->gain);
527 omega = calculate_omega (band->freq, GST_AUDIO_FILTER (equ)->format.rate);
528 bw = calculate_bw (band, GST_AUDIO_FILTER (equ)->format.rate);
534 alpha = tan (bw / 2.0);
536 delta = 2.0 * sqrt (gain) * alpha;
537 b0 = egp + egm * cos (omega) + delta;
539 band->a0 = ((egp - egm * cos (omega) + delta) * gain) / b0;
540 band->a1 = ((egm - egp * cos (omega)) * 2.0 * gain) / b0;
541 band->a2 = ((egp - egm * cos (omega) - delta) * gain) / b0;
542 band->b1 = ((egm + egp * cos (omega)) * 2.0) / b0;
543 band->b2 = -((egp + egm * cos (omega) - delta)) / b0;
548 ("gain = %5.1f, width= %7.2f, freq = %7.2f, a0 = %7.5g, a1 = %7.5g, a2=%7.5g b1 = %7.5g, b2 = %7.5g",
549 band->gain, band->width, band->freq, band->a0, band->a1, band->a2,
555 setup_high_shelf_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
557 g_return_if_fail (GST_AUDIO_FILTER (equ)->format.rate);
560 gdouble gain, omega, bw;
561 gdouble alpha, delta, b0;
564 gain = arg_to_scale (band->gain);
565 omega = calculate_omega (band->freq, GST_AUDIO_FILTER (equ)->format.rate);
566 bw = calculate_bw (band, GST_AUDIO_FILTER (equ)->format.rate);
572 alpha = tan (bw / 2.0);
574 delta = 2.0 * sqrt (gain) * alpha;
575 b0 = egp - egm * cos (omega) + delta;
577 band->a0 = ((egp + egm * cos (omega) + delta) * gain) / b0;
578 band->a1 = ((egm + egp * cos (omega)) * -2.0 * gain) / b0;
579 band->a2 = ((egp + egm * cos (omega) - delta) * gain) / b0;
580 band->b1 = ((egm - egp * cos (omega)) * -2.0) / b0;
581 band->b2 = -((egp - egm * cos (omega) - delta)) / b0;
586 ("gain = %5.1f, width= %7.2f, freq = %7.2f, a0 = %7.5g, a1 = %7.5g, a2=%7.5g b1 = %7.5g, b2 = %7.5g",
587 band->gain, band->width, band->freq, band->a0, band->a1, band->a2,
592 /* Must be called with bands_lock and transform lock! */
594 set_passthrough (GstIirEqualizer * equ)
597 gboolean passthrough = TRUE;
599 for (i = 0; i < equ->freq_band_count; i++) {
600 passthrough = passthrough && (equ->bands[i]->gain == 0.0);
603 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (equ), passthrough);
604 GST_DEBUG ("Passthrough mode: %d\n", passthrough);
607 /* Must be called with bands_lock and transform lock! */
609 update_coefficients (GstIirEqualizer * equ)
611 gint i, n = equ->freq_band_count;
613 for (i = 0; i < n; i++) {
614 if (equ->bands[i]->type == BAND_TYPE_PEAK)
615 setup_peak_filter (equ, equ->bands[i]);
616 else if (equ->bands[i]->type == BAND_TYPE_LOW_SHELF)
617 setup_low_shelf_filter (equ, equ->bands[i]);
619 setup_high_shelf_filter (equ, equ->bands[i]);
622 equ->need_new_coefficients = FALSE;
625 /* Must be called with transform lock! */
627 alloc_history (GstIirEqualizer * equ)
629 /* free + alloc = no memcpy */
630 g_free (equ->history);
632 g_malloc0 (equ->history_size * GST_AUDIO_FILTER (equ)->format.channels *
633 equ->freq_band_count);
637 gst_iir_equalizer_compute_frequencies (GstIirEqualizer * equ, guint new_count)
640 gdouble freq0, freq1, step;
643 if (equ->freq_band_count == new_count)
648 if (G_UNLIKELY (equ->freq_band_count == new_count)) {
653 old_count = equ->freq_band_count;
654 equ->freq_band_count = new_count;
655 GST_DEBUG ("bands %u -> %u", old_count, new_count);
657 if (old_count < new_count) {
659 equ->bands = g_realloc (equ->bands, sizeof (GstObject *) * new_count);
660 for (i = old_count; i < new_count; i++) {
661 equ->bands[i] = g_object_new (GST_TYPE_IIR_EQUALIZER_BAND, NULL);
662 /* otherwise they get names like 'iirequalizerband5' */
663 sprintf (name, "band%u", i);
664 gst_object_set_name (GST_OBJECT (equ->bands[i]), name);
665 GST_DEBUG ("adding band[%d]=%p", i, equ->bands[i]);
667 gst_object_set_parent (GST_OBJECT (equ->bands[i]), GST_OBJECT (equ));
668 gst_child_proxy_child_added (GST_OBJECT (equ),
669 GST_OBJECT (equ->bands[i]));
672 /* free unused bands */
673 for (i = new_count; i < old_count; i++) {
674 GST_DEBUG ("removing band[%d]=%p", i, equ->bands[i]);
675 gst_child_proxy_child_removed (GST_OBJECT (equ),
676 GST_OBJECT (equ->bands[i]));
677 gst_object_unparent (GST_OBJECT (equ->bands[i]));
678 equ->bands[i] = NULL;
684 /* set center frequencies and name band objects
685 * FIXME: arg! we can't change the name of parented objects :(
686 * application should read band->freq to get the name
689 step = pow (HIGHEST_FREQ / LOWEST_FREQ, 1.0 / new_count);
691 for (i = 0; i < new_count; i++) {
692 freq1 = freq0 * step;
695 equ->bands[i]->type = BAND_TYPE_LOW_SHELF;
696 else if (i == new_count - 1)
697 equ->bands[i]->type = BAND_TYPE_HIGH_SHELF;
699 equ->bands[i]->type = BAND_TYPE_PEAK;
701 equ->bands[i]->freq = freq0 + ((freq1 - freq0) / 2.0);
702 equ->bands[i]->width = freq1 - freq0;
703 GST_DEBUG ("band[%2d] = '%lf'", i, equ->bands[i]->freq);
705 g_object_notify (G_OBJECT (equ->bands[i]), "bandwidth");
706 g_object_notify (G_OBJECT (equ->bands[i]), "freq");
707 g_object_notify (G_OBJECT (equ->bands[i]), "type");
710 if(equ->bands[i]->freq<10000.0)
711 sprintf (name,"%dHz",(gint)equ->bands[i]->freq);
713 sprintf (name,"%dkHz",(gint)(equ->bands[i]->freq/1000.0));
714 gst_object_set_name( GST_OBJECT (equ->bands[i]), name);
715 GST_DEBUG ("band[%2d] = '%s'",i,name);
720 equ->need_new_coefficients = TRUE;
724 /* start of code that is type specific */
726 #define CREATE_OPTIMIZED_FUNCTIONS_INT(TYPE,BIG_TYPE,MIN_VAL,MAX_VAL) \
728 BIG_TYPE x1, x2; /* history of input values for a filter */ \
729 BIG_TYPE y1, y2; /* history of output values for a filter */ \
730 } SecondOrderHistory ## TYPE; \
732 static inline BIG_TYPE \
733 one_step_ ## TYPE (GstIirEqualizerBand *filter, \
734 SecondOrderHistory ## TYPE *history, BIG_TYPE input) \
736 /* calculate output */ \
737 BIG_TYPE output = filter->a0 * input + \
738 filter->a1 * history->x1 + filter->a2 * history->x2 + \
739 filter->b1 * history->y1 + filter->b2 * history->y2; \
740 /* update history */ \
741 history->y2 = history->y1; \
742 history->y1 = output; \
743 history->x2 = history->x1; \
744 history->x1 = input; \
750 history_size_ ## TYPE = sizeof (SecondOrderHistory ## TYPE); \
753 gst_iir_equ_process_ ## TYPE (GstIirEqualizer *equ, guint8 *data, \
754 guint size, guint channels) \
756 guint frames = size / channels / sizeof (TYPE); \
757 guint i, c, f, nf = equ->freq_band_count; \
759 GstIirEqualizerBand **filters = equ->bands; \
761 for (i = 0; i < frames; i++) { \
762 SecondOrderHistory ## TYPE *history = equ->history; \
763 for (c = 0; c < channels; c++) { \
764 cur = *((TYPE *) data); \
765 for (f = 0; f < nf; f++) { \
766 cur = one_step_ ## TYPE (filters[f], history, cur); \
769 cur = CLAMP (cur, MIN_VAL, MAX_VAL); \
770 *((TYPE *) data) = (TYPE) floor (cur); \
771 data += sizeof (TYPE); \
776 #define CREATE_OPTIMIZED_FUNCTIONS(TYPE) \
778 TYPE x1, x2; /* history of input values for a filter */ \
779 TYPE y1, y2; /* history of output values for a filter */ \
780 } SecondOrderHistory ## TYPE; \
783 one_step_ ## TYPE (GstIirEqualizerBand *filter, \
784 SecondOrderHistory ## TYPE *history, TYPE input) \
786 /* calculate output */ \
787 TYPE output = filter->a0 * input + filter->a1 * history->x1 + \
788 filter->a2 * history->x2 + filter->b1 * history->y1 + \
789 filter->b2 * history->y2; \
790 /* update history */ \
791 history->y2 = history->y1; \
792 history->y1 = output; \
793 history->x2 = history->x1; \
794 history->x1 = input; \
800 history_size_ ## TYPE = sizeof (SecondOrderHistory ## TYPE); \
803 gst_iir_equ_process_ ## TYPE (GstIirEqualizer *equ, guint8 *data, \
804 guint size, guint channels) \
806 guint frames = size / channels / sizeof (TYPE); \
807 guint i, c, f, nf = equ->freq_band_count; \
809 GstIirEqualizerBand **filters = equ->bands; \
811 for (i = 0; i < frames; i++) { \
812 SecondOrderHistory ## TYPE *history = equ->history; \
813 for (c = 0; c < channels; c++) { \
814 cur = *((TYPE *) data); \
815 for (f = 0; f < nf; f++) { \
816 cur = one_step_ ## TYPE (filters[f], history, cur); \
819 *((TYPE *) data) = (TYPE) cur; \
820 data += sizeof (TYPE); \
825 CREATE_OPTIMIZED_FUNCTIONS_INT (gint16, gfloat, -32768.0, 32767.0);
826 CREATE_OPTIMIZED_FUNCTIONS (gfloat);
827 CREATE_OPTIMIZED_FUNCTIONS (gdouble);
830 gst_iir_equalizer_transform_ip (GstBaseTransform * btrans, GstBuffer * buf)
832 GstAudioFilter *filter = GST_AUDIO_FILTER (btrans);
833 GstIirEqualizer *equ = GST_IIR_EQUALIZER (btrans);
834 GstClockTime timestamp;
836 if (G_UNLIKELY (filter->format.channels < 1 || equ->process == NULL))
837 return GST_FLOW_NOT_NEGOTIATED;
840 if (equ->need_new_coefficients) {
841 update_coefficients (equ);
842 set_passthrough (equ);
846 if (gst_base_transform_is_passthrough (btrans))
849 timestamp = GST_BUFFER_TIMESTAMP (buf);
851 gst_segment_to_stream_time (&btrans->segment, GST_FORMAT_TIME, timestamp);
853 if (GST_CLOCK_TIME_IS_VALID (timestamp))
854 gst_object_sync_values (G_OBJECT (equ), timestamp);
856 equ->process (equ, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf),
857 filter->format.channels);
863 gst_iir_equalizer_setup (GstAudioFilter * audio, GstRingBufferSpec * fmt)
865 GstIirEqualizer *equ = GST_IIR_EQUALIZER (audio);
868 case GST_BUFTYPE_LINEAR:
869 switch (fmt->width) {
871 equ->history_size = history_size_gint16;
872 equ->process = gst_iir_equ_process_gint16;
878 case GST_BUFTYPE_FLOAT:
879 switch (fmt->width) {
881 equ->history_size = history_size_gfloat;
882 equ->process = gst_iir_equ_process_gfloat;
885 equ->history_size = history_size_gdouble;
886 equ->process = gst_iir_equ_process_gdouble;
902 plugin_init (GstPlugin * plugin)
904 GST_DEBUG_CATEGORY_INIT (equalizer_debug, "equalizer", 0, "equalizer");
906 if (!(gst_element_register (plugin, "equalizer-nbands", GST_RANK_NONE,
907 GST_TYPE_IIR_EQUALIZER_NBANDS)))
910 if (!(gst_element_register (plugin, "equalizer-3bands", GST_RANK_NONE,
911 GST_TYPE_IIR_EQUALIZER_3BANDS)))
914 if (!(gst_element_register (plugin, "equalizer-10bands", GST_RANK_NONE,
915 GST_TYPE_IIR_EQUALIZER_10BANDS)))
921 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
924 "GStreamer audio equalizers",
925 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)