Merge branch 'master' into 0.11
[platform/upstream/gst-plugins-good.git] / gst / audiofx / audiochebband.c
1 /* 
2  * GStreamer
3  * Copyright (C) 2007-2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /* 
22  * Chebyshev type 1 filter design based on
23  * "The Scientist and Engineer's Guide to DSP", Chapter 20.
24  * http://www.dspguide.com/
25  *
26  * For type 2 and Chebyshev filters in general read
27  * http://en.wikipedia.org/wiki/Chebyshev_filter
28  *
29  * Transformation from lowpass to bandpass/bandreject:
30  * http://docs.dewresearch.com/DspHelp/html/IDH_LinearSystems_LowpassToBandPassZ.htm
31  * http://docs.dewresearch.com/DspHelp/html/IDH_LinearSystems_LowpassToBandStopZ.htm
32  * 
33  */
34
35 /**
36  * SECTION:element-audiochebband
37  *
38  * Attenuates all frequencies outside (bandpass) or inside (bandreject) of a frequency
39  * band. The number of poles and the ripple parameter control the rolloff.
40  *
41  * This element has the advantage over the windowed sinc bandpass and bandreject filter that it is
42  * much faster and produces almost as good results. It's only disadvantages are the highly
43  * non-linear phase and the slower rolloff compared to a windowed sinc filter with a large kernel.
44  *
45  * For type 1 the ripple parameter specifies how much ripple in dB is allowed in the passband, i.e.
46  * some frequencies in the passband will be amplified by that value. A higher ripple value will allow
47  * a faster rolloff.
48  *
49  * For type 2 the ripple parameter specifies the stopband attenuation. In the stopband the gain will
50  * be at most this value. A lower ripple value will allow a faster rolloff.
51  *
52  * As a special case, a Chebyshev type 1 filter with no ripple is a Butterworth filter.
53  *
54  * <note>
55  * Be warned that a too large number of poles can produce noise. The most poles are possible with
56  * a cutoff frequency at a quarter of the sampling rate.
57  * </note>
58  *
59  * <refsect2>
60  * <title>Example launch line</title>
61  * |[
62  * gst-launch audiotestsrc freq=1500 ! audioconvert ! audiochebband mode=band-pass lower-frequency=1000 upper-frequenc=6000 poles=4 ! audioconvert ! alsasink
63  * gst-launch filesrc location="melo1.ogg" ! oggdemux ! vorbisdec ! audioconvert ! audiochebband mode=band-reject lower-frequency=1000 upper-frequency=4000 ripple=0.2 ! audioconvert ! alsasink
64  * gst-launch audiotestsrc wave=white-noise ! audioconvert ! audiochebband mode=band-pass lower-frequency=1000 upper-frequency=4000 type=2 ! audioconvert ! alsasink
65  * ]|
66  * </refsect2>
67  */
68
69 #ifdef HAVE_CONFIG_H
70 #include "config.h"
71 #endif
72
73 #include <gst/gst.h>
74 #include <gst/base/gstbasetransform.h>
75 #include <gst/audio/audio.h>
76 #include <gst/audio/gstaudiofilter.h>
77
78 #include <math.h>
79
80 #include "math_compat.h"
81
82 #include "audiochebband.h"
83
84 #define GST_CAT_DEFAULT gst_audio_cheb_band_debug
85 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
86
87 enum
88 {
89   PROP_0,
90   PROP_MODE,
91   PROP_TYPE,
92   PROP_LOWER_FREQUENCY,
93   PROP_UPPER_FREQUENCY,
94   PROP_RIPPLE,
95   PROP_POLES
96 };
97
98 #define gst_audio_cheb_band_parent_class parent_class
99 G_DEFINE_TYPE (GstAudioChebBand, gst_audio_cheb_band,
100     GST_TYPE_AUDIO_FX_BASE_IIR_FILTER);
101
102 static void gst_audio_cheb_band_set_property (GObject * object,
103     guint prop_id, const GValue * value, GParamSpec * pspec);
104 static void gst_audio_cheb_band_get_property (GObject * object,
105     guint prop_id, GValue * value, GParamSpec * pspec);
106 static void gst_audio_cheb_band_finalize (GObject * object);
107
108 static gboolean gst_audio_cheb_band_setup (GstAudioFilter * filter,
109     const GstAudioInfo * info);
110
111 enum
112 {
113   MODE_BAND_PASS = 0,
114   MODE_BAND_REJECT
115 };
116
117 #define GST_TYPE_AUDIO_CHEBYSHEV_FREQ_BAND_MODE (gst_audio_cheb_band_mode_get_type ())
118 static GType
119 gst_audio_cheb_band_mode_get_type (void)
120 {
121   static GType gtype = 0;
122
123   if (gtype == 0) {
124     static const GEnumValue values[] = {
125       {MODE_BAND_PASS, "Band pass (default)",
126           "band-pass"},
127       {MODE_BAND_REJECT, "Band reject",
128           "band-reject"},
129       {0, NULL, NULL}
130     };
131
132     gtype = g_enum_register_static ("GstAudioChebBandMode", values);
133   }
134   return gtype;
135 }
136
137 /* GObject vmethod implementations */
138
139 static void
140 gst_audio_cheb_band_class_init (GstAudioChebBandClass * klass)
141 {
142   GObjectClass *gobject_class = (GObjectClass *) klass;
143   GstElementClass *gstelement_class = (GstElementClass *) klass;
144   GstAudioFilterClass *filter_class = (GstAudioFilterClass *) klass;
145
146   GST_DEBUG_CATEGORY_INIT (gst_audio_cheb_band_debug, "audiochebband", 0,
147       "audiochebband element");
148
149   gobject_class->set_property = gst_audio_cheb_band_set_property;
150   gobject_class->get_property = gst_audio_cheb_band_get_property;
151   gobject_class->finalize = gst_audio_cheb_band_finalize;
152
153   g_object_class_install_property (gobject_class, PROP_MODE,
154       g_param_spec_enum ("mode", "Mode",
155           "Low pass or high pass mode", GST_TYPE_AUDIO_CHEBYSHEV_FREQ_BAND_MODE,
156           MODE_BAND_PASS,
157           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
158   g_object_class_install_property (gobject_class, PROP_TYPE,
159       g_param_spec_int ("type", "Type", "Type of the chebychev filter", 1, 2, 1,
160           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
161
162   /* FIXME: Don't use the complete possible range but restrict the upper boundary
163    * so automatically generated UIs can use a slider without */
164   g_object_class_install_property (gobject_class, PROP_LOWER_FREQUENCY,
165       g_param_spec_float ("lower-frequency", "Lower frequency",
166           "Start frequency of the band (Hz)", 0.0, 100000.0,
167           0.0,
168           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
169   g_object_class_install_property (gobject_class, PROP_UPPER_FREQUENCY,
170       g_param_spec_float ("upper-frequency", "Upper frequency",
171           "Stop frequency of the band (Hz)", 0.0, 100000.0, 0.0,
172           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
173   g_object_class_install_property (gobject_class, PROP_RIPPLE,
174       g_param_spec_float ("ripple", "Ripple", "Amount of ripple (dB)", 0.0,
175           200.0, 0.25,
176           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
177   /* FIXME: What to do about this upper boundary? With a frequencies near
178    * rate/4 32 poles are completely possible, with frequencies very low
179    * or very high 16 poles already produces only noise */
180   g_object_class_install_property (gobject_class, PROP_POLES,
181       g_param_spec_int ("poles", "Poles",
182           "Number of poles to use, will be rounded up to the next multiply of four",
183           4, 32, 4,
184           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
185
186   gst_element_class_set_details_simple (gstelement_class,
187       "Band pass & band reject filter", "Filter/Effect/Audio",
188       "Chebyshev band pass and band reject filter",
189       "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
190
191   filter_class->setup = GST_DEBUG_FUNCPTR (gst_audio_cheb_band_setup);
192 }
193
194 static void
195 gst_audio_cheb_band_init (GstAudioChebBand * filter)
196 {
197   filter->lower_frequency = filter->upper_frequency = 0.0;
198   filter->mode = MODE_BAND_PASS;
199   filter->type = 1;
200   filter->poles = 4;
201   filter->ripple = 0.25;
202
203   filter->lock = g_mutex_new ();
204 }
205
206 static void
207 generate_biquad_coefficients (GstAudioChebBand * filter,
208     gint p, gdouble * a0, gdouble * a1, gdouble * a2, gdouble * a3,
209     gdouble * a4, gdouble * b1, gdouble * b2, gdouble * b3, gdouble * b4)
210 {
211   gint np = filter->poles / 2;
212   gdouble ripple = filter->ripple;
213   gint rate = GST_AUDIO_FILTER_RATE (filter);
214
215   /* pole location in s-plane */
216   gdouble rp, ip;
217
218   /* zero location in s-plane */
219   gdouble iz = 0.0;
220
221   /* transfer function coefficients for the z-plane */
222   gdouble x0, x1, x2, y1, y2;
223   gint type = filter->type;
224
225   /* Calculate pole location for lowpass at frequency 1 */
226   {
227     gdouble angle = (G_PI / 2.0) * (2.0 * p - 1) / np;
228
229     rp = -sin (angle);
230     ip = cos (angle);
231   }
232
233   /* If we allow ripple, move the pole from the unit
234    * circle to an ellipse and keep cutoff at frequency 1 */
235   if (ripple > 0 && type == 1) {
236     gdouble es, vx;
237
238     es = sqrt (pow (10.0, ripple / 10.0) - 1.0);
239
240     vx = (1.0 / np) * asinh (1.0 / es);
241     rp = rp * sinh (vx);
242     ip = ip * cosh (vx);
243   } else if (type == 2) {
244     gdouble es, vx;
245
246     es = sqrt (pow (10.0, ripple / 10.0) - 1.0);
247     vx = (1.0 / np) * asinh (es);
248     rp = rp * sinh (vx);
249     ip = ip * cosh (vx);
250   }
251
252   /* Calculate inverse of the pole location to move from
253    * type I to type II */
254   if (type == 2) {
255     gdouble mag2 = rp * rp + ip * ip;
256
257     rp /= mag2;
258     ip /= mag2;
259   }
260
261   /* Calculate zero location for frequency 1 on the
262    * unit circle for type 2 */
263   if (type == 2) {
264     gdouble angle = G_PI / (np * 2.0) + ((p - 1) * G_PI) / (np);
265     gdouble mag2;
266
267     iz = cos (angle);
268     mag2 = iz * iz;
269     iz /= mag2;
270   }
271
272   /* Convert from s-domain to z-domain by
273    * using the bilinear Z-transform, i.e.
274    * substitute s by (2/t)*((z-1)/(z+1))
275    * with t = 2 * tan(0.5).
276    */
277   if (type == 1) {
278     gdouble t, m, d;
279
280     t = 2.0 * tan (0.5);
281     m = rp * rp + ip * ip;
282     d = 4.0 - 4.0 * rp * t + m * t * t;
283
284     x0 = (t * t) / d;
285     x1 = 2.0 * x0;
286     x2 = x0;
287     y1 = (8.0 - 2.0 * m * t * t) / d;
288     y2 = (-4.0 - 4.0 * rp * t - m * t * t) / d;
289   } else {
290     gdouble t, m, d;
291
292     t = 2.0 * tan (0.5);
293     m = rp * rp + ip * ip;
294     d = 4.0 - 4.0 * rp * t + m * t * t;
295
296     x0 = (t * t * iz * iz + 4.0) / d;
297     x1 = (-8.0 + 2.0 * iz * iz * t * t) / d;
298     x2 = x0;
299     y1 = (8.0 - 2.0 * m * t * t) / d;
300     y2 = (-4.0 - 4.0 * rp * t - m * t * t) / d;
301   }
302
303   /* Convert from lowpass at frequency 1 to either bandpass
304    * or band reject.
305    *
306    * For bandpass substitute z^(-1) with:
307    *
308    *   -2            -1
309    * -z   + alpha * z   - beta
310    * ----------------------------
311    *         -2            -1
312    * beta * z   - alpha * z   + 1
313    *
314    * alpha = (2*a*b)/(1+b)
315    * beta = (b-1)/(b+1)
316    * a = cos((w1 + w0)/2) / cos((w1 - w0)/2)
317    * b = tan(1/2) * cot((w1 - w0)/2)
318    *
319    * For bandreject substitute z^(-1) with:
320    * 
321    *  -2            -1
322    * z   - alpha * z   + beta
323    * ----------------------------
324    *         -2            -1
325    * beta * z   - alpha * z   + 1
326    *
327    * alpha = (2*a)/(1+b)
328    * beta = (1-b)/(1+b)
329    * a = cos((w1 + w0)/2) / cos((w1 - w0)/2)
330    * b = tan(1/2) * tan((w1 - w0)/2)
331    *
332    */
333   {
334     gdouble a, b, d;
335     gdouble alpha, beta;
336     gdouble w0 = 2.0 * G_PI * (filter->lower_frequency / rate);
337     gdouble w1 = 2.0 * G_PI * (filter->upper_frequency / rate);
338
339     if (filter->mode == MODE_BAND_PASS) {
340       a = cos ((w1 + w0) / 2.0) / cos ((w1 - w0) / 2.0);
341       b = tan (1.0 / 2.0) / tan ((w1 - w0) / 2.0);
342
343       alpha = (2.0 * a * b) / (1.0 + b);
344       beta = (b - 1.0) / (b + 1.0);
345
346       d = 1.0 + beta * (y1 - beta * y2);
347
348       *a0 = (x0 + beta * (-x1 + beta * x2)) / d;
349       *a1 = (alpha * (-2.0 * x0 + x1 + beta * x1 - 2.0 * beta * x2)) / d;
350       *a2 =
351           (-x1 - beta * beta * x1 + 2.0 * beta * (x0 + x2) +
352           alpha * alpha * (x0 - x1 + x2)) / d;
353       *a3 = (alpha * (x1 + beta * (-2.0 * x0 + x1) - 2.0 * x2)) / d;
354       *a4 = (beta * (beta * x0 - x1) + x2) / d;
355       *b1 = (alpha * (2.0 + y1 + beta * y1 - 2.0 * beta * y2)) / d;
356       *b2 =
357           (-y1 - beta * beta * y1 - alpha * alpha * (1.0 + y1 - y2) +
358           2.0 * beta * (-1.0 + y2)) / d;
359       *b3 = (alpha * (y1 + beta * (2.0 + y1) - 2.0 * y2)) / d;
360       *b4 = (-beta * beta - beta * y1 + y2) / d;
361     } else {
362       a = cos ((w1 + w0) / 2.0) / cos ((w1 - w0) / 2.0);
363       b = tan (1.0 / 2.0) * tan ((w1 - w0) / 2.0);
364
365       alpha = (2.0 * a) / (1.0 + b);
366       beta = (1.0 - b) / (1.0 + b);
367
368       d = -1.0 + beta * (beta * y2 + y1);
369
370       *a0 = (-x0 - beta * x1 - beta * beta * x2) / d;
371       *a1 = (alpha * (2.0 * x0 + x1 + beta * x1 + 2.0 * beta * x2)) / d;
372       *a2 =
373           (-x1 - beta * beta * x1 - 2.0 * beta * (x0 + x2) -
374           alpha * alpha * (x0 + x1 + x2)) / d;
375       *a3 = (alpha * (x1 + beta * (2.0 * x0 + x1) + 2.0 * x2)) / d;
376       *a4 = (-beta * beta * x0 - beta * x1 - x2) / d;
377       *b1 = (alpha * (-2.0 + y1 + beta * y1 + 2.0 * beta * y2)) / d;
378       *b2 =
379           -(y1 + beta * beta * y1 + 2.0 * beta * (-1.0 + y2) +
380           alpha * alpha * (-1.0 + y1 + y2)) / d;
381       *b3 = (alpha * (beta * (-2.0 + y1) + y1 + 2.0 * y2)) / d;
382       *b4 = -(-beta * beta + beta * y1 + y2) / d;
383     }
384   }
385 }
386
387 static void
388 generate_coefficients (GstAudioChebBand * filter)
389 {
390   gint rate = GST_AUDIO_FILTER_RATE (filter);
391
392   if (rate == 0) {
393     gdouble *a = g_new0 (gdouble, 1);
394
395     a[0] = 1.0;
396     gst_audio_fx_base_iir_filter_set_coefficients (GST_AUDIO_FX_BASE_IIR_FILTER
397         (filter), a, 1, NULL, 0);
398     GST_LOG_OBJECT (filter, "rate was not set yet");
399     return;
400   }
401
402   if (filter->upper_frequency <= filter->lower_frequency) {
403     gdouble *a = g_new0 (gdouble, 1);
404
405     a[0] = (filter->mode == MODE_BAND_PASS) ? 0.0 : 1.0;
406     gst_audio_fx_base_iir_filter_set_coefficients (GST_AUDIO_FX_BASE_IIR_FILTER
407         (filter), a, 1, NULL, 0);
408
409     GST_LOG_OBJECT (filter, "frequency band had no or negative dimension");
410     return;
411   }
412
413   if (filter->upper_frequency > rate / 2) {
414     filter->upper_frequency = rate / 2;
415     GST_LOG_OBJECT (filter, "clipped upper frequency to nyquist frequency");
416   }
417
418   if (filter->lower_frequency < 0.0) {
419     filter->lower_frequency = 0.0;
420     GST_LOG_OBJECT (filter, "clipped lower frequency to 0.0");
421   }
422
423   /* Calculate coefficients for the chebyshev filter */
424   {
425     gint np = filter->poles;
426     gdouble *a, *b;
427     gint i, p;
428
429     a = g_new0 (gdouble, np + 5);
430     b = g_new0 (gdouble, np + 5);
431
432     /* Calculate transfer function coefficients */
433     a[4] = 1.0;
434     b[4] = 1.0;
435
436     for (p = 1; p <= np / 4; p++) {
437       gdouble a0, a1, a2, a3, a4, b1, b2, b3, b4;
438       gdouble *ta = g_new0 (gdouble, np + 5);
439       gdouble *tb = g_new0 (gdouble, np + 5);
440
441       generate_biquad_coefficients (filter, p, &a0, &a1, &a2, &a3, &a4, &b1,
442           &b2, &b3, &b4);
443
444       memcpy (ta, a, sizeof (gdouble) * (np + 5));
445       memcpy (tb, b, sizeof (gdouble) * (np + 5));
446
447       /* add the new coefficients for the new two poles
448        * to the cascade by multiplication of the transfer
449        * functions */
450       for (i = 4; i < np + 5; i++) {
451         a[i] =
452             a0 * ta[i] + a1 * ta[i - 1] + a2 * ta[i - 2] + a3 * ta[i - 3] +
453             a4 * ta[i - 4];
454         b[i] =
455             tb[i] - b1 * tb[i - 1] - b2 * tb[i - 2] - b3 * tb[i - 3] -
456             b4 * tb[i - 4];
457       }
458       g_free (ta);
459       g_free (tb);
460     }
461
462     /* Move coefficients to the beginning of the array
463      * and multiply the b coefficients with -1 to move from
464      * the transfer function's coefficients to the difference
465      * equation's coefficients */
466     b[4] = 0.0;
467     for (i = 0; i <= np; i++) {
468       a[i] = a[i + 4];
469       b[i] = -b[i + 4];
470     }
471
472     /* Normalize to unity gain at frequency 0 and frequency
473      * 0.5 for bandreject and unity gain at band center frequency
474      * for bandpass */
475     if (filter->mode == MODE_BAND_REJECT) {
476       /* gain is sqrt(H(0)*H(0.5)) */
477
478       gdouble gain1 =
479           gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b, np + 1,
480           1.0, 0.0);
481       gdouble gain2 =
482           gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b, np + 1,
483           -1.0, 0.0);
484
485       gain1 = sqrt (gain1 * gain2);
486
487       for (i = 0; i <= np; i++) {
488         a[i] /= gain1;
489       }
490     } else {
491       /* gain is H(wc), wc = center frequency */
492
493       gdouble w1 = 2.0 * G_PI * (filter->lower_frequency / rate);
494       gdouble w2 = 2.0 * G_PI * (filter->upper_frequency / rate);
495       gdouble w0 = (w2 + w1) / 2.0;
496       gdouble zr = cos (w0), zi = sin (w0);
497       gdouble gain =
498           gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b, np + 1, zr,
499           zi);
500
501       for (i = 0; i <= np; i++) {
502         a[i] /= gain;
503       }
504     }
505
506     gst_audio_fx_base_iir_filter_set_coefficients (GST_AUDIO_FX_BASE_IIR_FILTER
507         (filter), a, np + 1, b, np + 1);
508
509     GST_LOG_OBJECT (filter,
510         "Generated IIR coefficients for the Chebyshev filter");
511     GST_LOG_OBJECT (filter,
512         "mode: %s, type: %d, poles: %d, lower-frequency: %.2f Hz, upper-frequency: %.2f Hz, ripple: %.2f dB",
513         (filter->mode == MODE_BAND_PASS) ? "band-pass" : "band-reject",
514         filter->type, filter->poles, filter->lower_frequency,
515         filter->upper_frequency, filter->ripple);
516
517     GST_LOG_OBJECT (filter, "%.2f dB gain @ 0Hz",
518         20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b,
519                 np + 1, 1.0, 0.0)));
520     {
521       gdouble w1 = 2.0 * G_PI * (filter->lower_frequency / rate);
522       gdouble w2 = 2.0 * G_PI * (filter->upper_frequency / rate);
523       gdouble w0 = (w2 + w1) / 2.0;
524       gdouble zr, zi;
525
526       zr = cos (w1);
527       zi = sin (w1);
528       GST_LOG_OBJECT (filter, "%.2f dB gain @ %dHz",
529           20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1,
530                   b, np + 1, zr, zi)), (int) filter->lower_frequency);
531       zr = cos (w0);
532       zi = sin (w0);
533       GST_LOG_OBJECT (filter, "%.2f dB gain @ %dHz",
534           20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1,
535                   b, np + 1, zr, zi)),
536           (int) ((filter->lower_frequency + filter->upper_frequency) / 2.0));
537       zr = cos (w2);
538       zi = sin (w2);
539       GST_LOG_OBJECT (filter, "%.2f dB gain @ %dHz",
540           20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1,
541                   b, np + 1, zr, zi)), (int) filter->upper_frequency);
542     }
543     GST_LOG_OBJECT (filter, "%.2f dB gain @ %dHz",
544         20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b,
545                 np + 1, -1.0, 0.0)), rate / 2);
546   }
547 }
548
549 static void
550 gst_audio_cheb_band_finalize (GObject * object)
551 {
552   GstAudioChebBand *filter = GST_AUDIO_CHEB_BAND (object);
553
554   g_mutex_free (filter->lock);
555   filter->lock = NULL;
556
557   G_OBJECT_CLASS (parent_class)->finalize (object);
558 }
559
560 static void
561 gst_audio_cheb_band_set_property (GObject * object, guint prop_id,
562     const GValue * value, GParamSpec * pspec)
563 {
564   GstAudioChebBand *filter = GST_AUDIO_CHEB_BAND (object);
565
566   switch (prop_id) {
567     case PROP_MODE:
568       g_mutex_lock (filter->lock);
569       filter->mode = g_value_get_enum (value);
570       generate_coefficients (filter);
571       g_mutex_unlock (filter->lock);
572       break;
573     case PROP_TYPE:
574       g_mutex_lock (filter->lock);
575       filter->type = g_value_get_int (value);
576       generate_coefficients (filter);
577       g_mutex_unlock (filter->lock);
578       break;
579     case PROP_LOWER_FREQUENCY:
580       g_mutex_lock (filter->lock);
581       filter->lower_frequency = g_value_get_float (value);
582       generate_coefficients (filter);
583       g_mutex_unlock (filter->lock);
584       break;
585     case PROP_UPPER_FREQUENCY:
586       g_mutex_lock (filter->lock);
587       filter->upper_frequency = g_value_get_float (value);
588       generate_coefficients (filter);
589       g_mutex_unlock (filter->lock);
590       break;
591     case PROP_RIPPLE:
592       g_mutex_lock (filter->lock);
593       filter->ripple = g_value_get_float (value);
594       generate_coefficients (filter);
595       g_mutex_unlock (filter->lock);
596       break;
597     case PROP_POLES:
598       g_mutex_lock (filter->lock);
599       filter->poles = GST_ROUND_UP_4 (g_value_get_int (value));
600       generate_coefficients (filter);
601       g_mutex_unlock (filter->lock);
602       break;
603     default:
604       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
605       break;
606   }
607 }
608
609 static void
610 gst_audio_cheb_band_get_property (GObject * object, guint prop_id,
611     GValue * value, GParamSpec * pspec)
612 {
613   GstAudioChebBand *filter = GST_AUDIO_CHEB_BAND (object);
614
615   switch (prop_id) {
616     case PROP_MODE:
617       g_value_set_enum (value, filter->mode);
618       break;
619     case PROP_TYPE:
620       g_value_set_int (value, filter->type);
621       break;
622     case PROP_LOWER_FREQUENCY:
623       g_value_set_float (value, filter->lower_frequency);
624       break;
625     case PROP_UPPER_FREQUENCY:
626       g_value_set_float (value, filter->upper_frequency);
627       break;
628     case PROP_RIPPLE:
629       g_value_set_float (value, filter->ripple);
630       break;
631     case PROP_POLES:
632       g_value_set_int (value, filter->poles);
633       break;
634     default:
635       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
636       break;
637   }
638 }
639
640 /* GstAudioFilter vmethod implementations */
641
642 static gboolean
643 gst_audio_cheb_band_setup (GstAudioFilter * base, const GstAudioInfo * info)
644 {
645   GstAudioChebBand *filter = GST_AUDIO_CHEB_BAND (base);
646
647   generate_coefficients (filter);
648
649   return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info);
650 }