Merge remote-tracking branch 'origin/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 <string.h>
74
75 #include <gst/gst.h>
76 #include <gst/base/gstbasetransform.h>
77 #include <gst/audio/audio.h>
78 #include <gst/audio/gstaudiofilter.h>
79
80 #include <math.h>
81
82 #include "math_compat.h"
83
84 #include "audiochebband.h"
85
86 #define GST_CAT_DEFAULT gst_audio_cheb_band_debug
87 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
88
89 enum
90 {
91   PROP_0,
92   PROP_MODE,
93   PROP_TYPE,
94   PROP_LOWER_FREQUENCY,
95   PROP_UPPER_FREQUENCY,
96   PROP_RIPPLE,
97   PROP_POLES
98 };
99
100 #define gst_audio_cheb_band_parent_class parent_class
101 G_DEFINE_TYPE (GstAudioChebBand, gst_audio_cheb_band,
102     GST_TYPE_AUDIO_FX_BASE_IIR_FILTER);
103
104 static void gst_audio_cheb_band_set_property (GObject * object,
105     guint prop_id, const GValue * value, GParamSpec * pspec);
106 static void gst_audio_cheb_band_get_property (GObject * object,
107     guint prop_id, GValue * value, GParamSpec * pspec);
108 static void gst_audio_cheb_band_finalize (GObject * object);
109
110 static gboolean gst_audio_cheb_band_setup (GstAudioFilter * filter,
111     const GstAudioInfo * info);
112
113 enum
114 {
115   MODE_BAND_PASS = 0,
116   MODE_BAND_REJECT
117 };
118
119 #define GST_TYPE_AUDIO_CHEBYSHEV_FREQ_BAND_MODE (gst_audio_cheb_band_mode_get_type ())
120 static GType
121 gst_audio_cheb_band_mode_get_type (void)
122 {
123   static GType gtype = 0;
124
125   if (gtype == 0) {
126     static const GEnumValue values[] = {
127       {MODE_BAND_PASS, "Band pass (default)",
128           "band-pass"},
129       {MODE_BAND_REJECT, "Band reject",
130           "band-reject"},
131       {0, NULL, NULL}
132     };
133
134     gtype = g_enum_register_static ("GstAudioChebBandMode", values);
135   }
136   return gtype;
137 }
138
139 /* GObject vmethod implementations */
140
141 static void
142 gst_audio_cheb_band_class_init (GstAudioChebBandClass * klass)
143 {
144   GObjectClass *gobject_class = (GObjectClass *) klass;
145   GstElementClass *gstelement_class = (GstElementClass *) klass;
146   GstAudioFilterClass *filter_class = (GstAudioFilterClass *) klass;
147
148   GST_DEBUG_CATEGORY_INIT (gst_audio_cheb_band_debug, "audiochebband", 0,
149       "audiochebband element");
150
151   gobject_class->set_property = gst_audio_cheb_band_set_property;
152   gobject_class->get_property = gst_audio_cheb_band_get_property;
153   gobject_class->finalize = gst_audio_cheb_band_finalize;
154
155   g_object_class_install_property (gobject_class, PROP_MODE,
156       g_param_spec_enum ("mode", "Mode",
157           "Low pass or high pass mode", GST_TYPE_AUDIO_CHEBYSHEV_FREQ_BAND_MODE,
158           MODE_BAND_PASS,
159           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
160   g_object_class_install_property (gobject_class, PROP_TYPE,
161       g_param_spec_int ("type", "Type", "Type of the chebychev filter", 1, 2, 1,
162           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
163
164   /* FIXME: Don't use the complete possible range but restrict the upper boundary
165    * so automatically generated UIs can use a slider without */
166   g_object_class_install_property (gobject_class, PROP_LOWER_FREQUENCY,
167       g_param_spec_float ("lower-frequency", "Lower frequency",
168           "Start frequency of the band (Hz)", 0.0, 100000.0,
169           0.0,
170           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
171   g_object_class_install_property (gobject_class, PROP_UPPER_FREQUENCY,
172       g_param_spec_float ("upper-frequency", "Upper frequency",
173           "Stop frequency of the band (Hz)", 0.0, 100000.0, 0.0,
174           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
175   g_object_class_install_property (gobject_class, PROP_RIPPLE,
176       g_param_spec_float ("ripple", "Ripple", "Amount of ripple (dB)", 0.0,
177           200.0, 0.25,
178           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
179   /* FIXME: What to do about this upper boundary? With a frequencies near
180    * rate/4 32 poles are completely possible, with frequencies very low
181    * or very high 16 poles already produces only noise */
182   g_object_class_install_property (gobject_class, PROP_POLES,
183       g_param_spec_int ("poles", "Poles",
184           "Number of poles to use, will be rounded up to the next multiply of four",
185           4, 32, 4,
186           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
187
188   gst_element_class_set_details_simple (gstelement_class,
189       "Band pass & band reject filter", "Filter/Effect/Audio",
190       "Chebyshev band pass and band reject filter",
191       "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
192
193   filter_class->setup = GST_DEBUG_FUNCPTR (gst_audio_cheb_band_setup);
194 }
195
196 static void
197 gst_audio_cheb_band_init (GstAudioChebBand * filter)
198 {
199   filter->lower_frequency = filter->upper_frequency = 0.0;
200   filter->mode = MODE_BAND_PASS;
201   filter->type = 1;
202   filter->poles = 4;
203   filter->ripple = 0.25;
204
205   filter->lock = g_mutex_new ();
206 }
207
208 static void
209 generate_biquad_coefficients (GstAudioChebBand * filter,
210     gint p, gdouble * a0, gdouble * a1, gdouble * a2, gdouble * a3,
211     gdouble * a4, gdouble * b1, gdouble * b2, gdouble * b3, gdouble * b4)
212 {
213   gint np = filter->poles / 2;
214   gdouble ripple = filter->ripple;
215   gint rate = GST_AUDIO_FILTER_RATE (filter);
216
217   /* pole location in s-plane */
218   gdouble rp, ip;
219
220   /* zero location in s-plane */
221   gdouble iz = 0.0;
222
223   /* transfer function coefficients for the z-plane */
224   gdouble x0, x1, x2, y1, y2;
225   gint type = filter->type;
226
227   /* Calculate pole location for lowpass at frequency 1 */
228   {
229     gdouble angle = (G_PI / 2.0) * (2.0 * p - 1) / np;
230
231     rp = -sin (angle);
232     ip = cos (angle);
233   }
234
235   /* If we allow ripple, move the pole from the unit
236    * circle to an ellipse and keep cutoff at frequency 1 */
237   if (ripple > 0 && type == 1) {
238     gdouble es, vx;
239
240     es = sqrt (pow (10.0, ripple / 10.0) - 1.0);
241
242     vx = (1.0 / np) * asinh (1.0 / es);
243     rp = rp * sinh (vx);
244     ip = ip * cosh (vx);
245   } else if (type == 2) {
246     gdouble es, vx;
247
248     es = sqrt (pow (10.0, ripple / 10.0) - 1.0);
249     vx = (1.0 / np) * asinh (es);
250     rp = rp * sinh (vx);
251     ip = ip * cosh (vx);
252   }
253
254   /* Calculate inverse of the pole location to move from
255    * type I to type II */
256   if (type == 2) {
257     gdouble mag2 = rp * rp + ip * ip;
258
259     rp /= mag2;
260     ip /= mag2;
261   }
262
263   /* Calculate zero location for frequency 1 on the
264    * unit circle for type 2 */
265   if (type == 2) {
266     gdouble angle = G_PI / (np * 2.0) + ((p - 1) * G_PI) / (np);
267     gdouble mag2;
268
269     iz = cos (angle);
270     mag2 = iz * iz;
271     iz /= mag2;
272   }
273
274   /* Convert from s-domain to z-domain by
275    * using the bilinear Z-transform, i.e.
276    * substitute s by (2/t)*((z-1)/(z+1))
277    * with t = 2 * tan(0.5).
278    */
279   if (type == 1) {
280     gdouble t, m, d;
281
282     t = 2.0 * tan (0.5);
283     m = rp * rp + ip * ip;
284     d = 4.0 - 4.0 * rp * t + m * t * t;
285
286     x0 = (t * t) / d;
287     x1 = 2.0 * x0;
288     x2 = x0;
289     y1 = (8.0 - 2.0 * m * t * t) / d;
290     y2 = (-4.0 - 4.0 * rp * t - m * t * t) / d;
291   } else {
292     gdouble t, m, d;
293
294     t = 2.0 * tan (0.5);
295     m = rp * rp + ip * ip;
296     d = 4.0 - 4.0 * rp * t + m * t * t;
297
298     x0 = (t * t * iz * iz + 4.0) / d;
299     x1 = (-8.0 + 2.0 * iz * iz * t * t) / d;
300     x2 = x0;
301     y1 = (8.0 - 2.0 * m * t * t) / d;
302     y2 = (-4.0 - 4.0 * rp * t - m * t * t) / d;
303   }
304
305   /* Convert from lowpass at frequency 1 to either bandpass
306    * or band reject.
307    *
308    * For bandpass substitute z^(-1) with:
309    *
310    *   -2            -1
311    * -z   + alpha * z   - beta
312    * ----------------------------
313    *         -2            -1
314    * beta * z   - alpha * z   + 1
315    *
316    * alpha = (2*a*b)/(1+b)
317    * beta = (b-1)/(b+1)
318    * a = cos((w1 + w0)/2) / cos((w1 - w0)/2)
319    * b = tan(1/2) * cot((w1 - w0)/2)
320    *
321    * For bandreject substitute z^(-1) with:
322    * 
323    *  -2            -1
324    * z   - alpha * z   + beta
325    * ----------------------------
326    *         -2            -1
327    * beta * z   - alpha * z   + 1
328    *
329    * alpha = (2*a)/(1+b)
330    * beta = (1-b)/(1+b)
331    * a = cos((w1 + w0)/2) / cos((w1 - w0)/2)
332    * b = tan(1/2) * tan((w1 - w0)/2)
333    *
334    */
335   {
336     gdouble a, b, d;
337     gdouble alpha, beta;
338     gdouble w0 = 2.0 * G_PI * (filter->lower_frequency / rate);
339     gdouble w1 = 2.0 * G_PI * (filter->upper_frequency / rate);
340
341     if (filter->mode == MODE_BAND_PASS) {
342       a = cos ((w1 + w0) / 2.0) / cos ((w1 - w0) / 2.0);
343       b = tan (1.0 / 2.0) / tan ((w1 - w0) / 2.0);
344
345       alpha = (2.0 * a * b) / (1.0 + b);
346       beta = (b - 1.0) / (b + 1.0);
347
348       d = 1.0 + beta * (y1 - beta * y2);
349
350       *a0 = (x0 + beta * (-x1 + beta * x2)) / d;
351       *a1 = (alpha * (-2.0 * x0 + x1 + beta * x1 - 2.0 * beta * x2)) / d;
352       *a2 =
353           (-x1 - beta * beta * x1 + 2.0 * beta * (x0 + x2) +
354           alpha * alpha * (x0 - x1 + x2)) / d;
355       *a3 = (alpha * (x1 + beta * (-2.0 * x0 + x1) - 2.0 * x2)) / d;
356       *a4 = (beta * (beta * x0 - x1) + x2) / d;
357       *b1 = (alpha * (2.0 + y1 + beta * y1 - 2.0 * beta * y2)) / d;
358       *b2 =
359           (-y1 - beta * beta * y1 - alpha * alpha * (1.0 + y1 - y2) +
360           2.0 * beta * (-1.0 + y2)) / d;
361       *b3 = (alpha * (y1 + beta * (2.0 + y1) - 2.0 * y2)) / d;
362       *b4 = (-beta * beta - beta * y1 + y2) / d;
363     } else {
364       a = cos ((w1 + w0) / 2.0) / cos ((w1 - w0) / 2.0);
365       b = tan (1.0 / 2.0) * tan ((w1 - w0) / 2.0);
366
367       alpha = (2.0 * a) / (1.0 + b);
368       beta = (1.0 - b) / (1.0 + b);
369
370       d = -1.0 + beta * (beta * y2 + y1);
371
372       *a0 = (-x0 - beta * x1 - beta * beta * x2) / d;
373       *a1 = (alpha * (2.0 * x0 + x1 + beta * x1 + 2.0 * beta * x2)) / d;
374       *a2 =
375           (-x1 - beta * beta * x1 - 2.0 * beta * (x0 + x2) -
376           alpha * alpha * (x0 + x1 + x2)) / d;
377       *a3 = (alpha * (x1 + beta * (2.0 * x0 + x1) + 2.0 * x2)) / d;
378       *a4 = (-beta * beta * x0 - beta * x1 - x2) / d;
379       *b1 = (alpha * (-2.0 + y1 + beta * y1 + 2.0 * beta * y2)) / d;
380       *b2 =
381           -(y1 + beta * beta * y1 + 2.0 * beta * (-1.0 + y2) +
382           alpha * alpha * (-1.0 + y1 + y2)) / d;
383       *b3 = (alpha * (beta * (-2.0 + y1) + y1 + 2.0 * y2)) / d;
384       *b4 = -(-beta * beta + beta * y1 + y2) / d;
385     }
386   }
387 }
388
389 static void
390 generate_coefficients (GstAudioChebBand * filter)
391 {
392   gint rate = GST_AUDIO_FILTER_RATE (filter);
393
394   if (rate == 0) {
395     gdouble *a = g_new0 (gdouble, 1);
396
397     a[0] = 1.0;
398     gst_audio_fx_base_iir_filter_set_coefficients (GST_AUDIO_FX_BASE_IIR_FILTER
399         (filter), a, 1, NULL, 0);
400     GST_LOG_OBJECT (filter, "rate was not set yet");
401     return;
402   }
403
404   if (filter->upper_frequency <= filter->lower_frequency) {
405     gdouble *a = g_new0 (gdouble, 1);
406
407     a[0] = (filter->mode == MODE_BAND_PASS) ? 0.0 : 1.0;
408     gst_audio_fx_base_iir_filter_set_coefficients (GST_AUDIO_FX_BASE_IIR_FILTER
409         (filter), a, 1, NULL, 0);
410
411     GST_LOG_OBJECT (filter, "frequency band had no or negative dimension");
412     return;
413   }
414
415   if (filter->upper_frequency > rate / 2) {
416     filter->upper_frequency = rate / 2;
417     GST_LOG_OBJECT (filter, "clipped upper frequency to nyquist frequency");
418   }
419
420   if (filter->lower_frequency < 0.0) {
421     filter->lower_frequency = 0.0;
422     GST_LOG_OBJECT (filter, "clipped lower frequency to 0.0");
423   }
424
425   /* Calculate coefficients for the chebyshev filter */
426   {
427     gint np = filter->poles;
428     gdouble *a, *b;
429     gint i, p;
430
431     a = g_new0 (gdouble, np + 5);
432     b = g_new0 (gdouble, np + 5);
433
434     /* Calculate transfer function coefficients */
435     a[4] = 1.0;
436     b[4] = 1.0;
437
438     for (p = 1; p <= np / 4; p++) {
439       gdouble a0, a1, a2, a3, a4, b1, b2, b3, b4;
440       gdouble *ta = g_new0 (gdouble, np + 5);
441       gdouble *tb = g_new0 (gdouble, np + 5);
442
443       generate_biquad_coefficients (filter, p, &a0, &a1, &a2, &a3, &a4, &b1,
444           &b2, &b3, &b4);
445
446       memcpy (ta, a, sizeof (gdouble) * (np + 5));
447       memcpy (tb, b, sizeof (gdouble) * (np + 5));
448
449       /* add the new coefficients for the new two poles
450        * to the cascade by multiplication of the transfer
451        * functions */
452       for (i = 4; i < np + 5; i++) {
453         a[i] =
454             a0 * ta[i] + a1 * ta[i - 1] + a2 * ta[i - 2] + a3 * ta[i - 3] +
455             a4 * ta[i - 4];
456         b[i] =
457             tb[i] - b1 * tb[i - 1] - b2 * tb[i - 2] - b3 * tb[i - 3] -
458             b4 * tb[i - 4];
459       }
460       g_free (ta);
461       g_free (tb);
462     }
463
464     /* Move coefficients to the beginning of the array
465      * and multiply the b coefficients with -1 to move from
466      * the transfer function's coefficients to the difference
467      * equation's coefficients */
468     b[4] = 0.0;
469     for (i = 0; i <= np; i++) {
470       a[i] = a[i + 4];
471       b[i] = -b[i + 4];
472     }
473
474     /* Normalize to unity gain at frequency 0 and frequency
475      * 0.5 for bandreject and unity gain at band center frequency
476      * for bandpass */
477     if (filter->mode == MODE_BAND_REJECT) {
478       /* gain is sqrt(H(0)*H(0.5)) */
479
480       gdouble gain1 =
481           gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b, np + 1,
482           1.0, 0.0);
483       gdouble gain2 =
484           gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b, np + 1,
485           -1.0, 0.0);
486
487       gain1 = sqrt (gain1 * gain2);
488
489       for (i = 0; i <= np; i++) {
490         a[i] /= gain1;
491       }
492     } else {
493       /* gain is H(wc), wc = center frequency */
494
495       gdouble w1 = 2.0 * G_PI * (filter->lower_frequency / rate);
496       gdouble w2 = 2.0 * G_PI * (filter->upper_frequency / rate);
497       gdouble w0 = (w2 + w1) / 2.0;
498       gdouble zr = cos (w0), zi = sin (w0);
499       gdouble gain =
500           gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b, np + 1, zr,
501           zi);
502
503       for (i = 0; i <= np; i++) {
504         a[i] /= gain;
505       }
506     }
507
508     gst_audio_fx_base_iir_filter_set_coefficients (GST_AUDIO_FX_BASE_IIR_FILTER
509         (filter), a, np + 1, b, np + 1);
510
511     GST_LOG_OBJECT (filter,
512         "Generated IIR coefficients for the Chebyshev filter");
513     GST_LOG_OBJECT (filter,
514         "mode: %s, type: %d, poles: %d, lower-frequency: %.2f Hz, upper-frequency: %.2f Hz, ripple: %.2f dB",
515         (filter->mode == MODE_BAND_PASS) ? "band-pass" : "band-reject",
516         filter->type, filter->poles, filter->lower_frequency,
517         filter->upper_frequency, filter->ripple);
518
519     GST_LOG_OBJECT (filter, "%.2f dB gain @ 0Hz",
520         20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b,
521                 np + 1, 1.0, 0.0)));
522     {
523       gdouble w1 = 2.0 * G_PI * (filter->lower_frequency / rate);
524       gdouble w2 = 2.0 * G_PI * (filter->upper_frequency / rate);
525       gdouble w0 = (w2 + w1) / 2.0;
526       gdouble zr, zi;
527
528       zr = cos (w1);
529       zi = sin (w1);
530       GST_LOG_OBJECT (filter, "%.2f dB gain @ %dHz",
531           20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1,
532                   b, np + 1, zr, zi)), (int) filter->lower_frequency);
533       zr = cos (w0);
534       zi = sin (w0);
535       GST_LOG_OBJECT (filter, "%.2f dB gain @ %dHz",
536           20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1,
537                   b, np + 1, zr, zi)),
538           (int) ((filter->lower_frequency + filter->upper_frequency) / 2.0));
539       zr = cos (w2);
540       zi = sin (w2);
541       GST_LOG_OBJECT (filter, "%.2f dB gain @ %dHz",
542           20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1,
543                   b, np + 1, zr, zi)), (int) filter->upper_frequency);
544     }
545     GST_LOG_OBJECT (filter, "%.2f dB gain @ %dHz",
546         20.0 * log10 (gst_audio_fx_base_iir_filter_calculate_gain (a, np + 1, b,
547                 np + 1, -1.0, 0.0)), rate / 2);
548   }
549 }
550
551 static void
552 gst_audio_cheb_band_finalize (GObject * object)
553 {
554   GstAudioChebBand *filter = GST_AUDIO_CHEB_BAND (object);
555
556   g_mutex_free (filter->lock);
557   filter->lock = NULL;
558
559   G_OBJECT_CLASS (parent_class)->finalize (object);
560 }
561
562 static void
563 gst_audio_cheb_band_set_property (GObject * object, guint prop_id,
564     const GValue * value, GParamSpec * pspec)
565 {
566   GstAudioChebBand *filter = GST_AUDIO_CHEB_BAND (object);
567
568   switch (prop_id) {
569     case PROP_MODE:
570       g_mutex_lock (filter->lock);
571       filter->mode = g_value_get_enum (value);
572       generate_coefficients (filter);
573       g_mutex_unlock (filter->lock);
574       break;
575     case PROP_TYPE:
576       g_mutex_lock (filter->lock);
577       filter->type = g_value_get_int (value);
578       generate_coefficients (filter);
579       g_mutex_unlock (filter->lock);
580       break;
581     case PROP_LOWER_FREQUENCY:
582       g_mutex_lock (filter->lock);
583       filter->lower_frequency = g_value_get_float (value);
584       generate_coefficients (filter);
585       g_mutex_unlock (filter->lock);
586       break;
587     case PROP_UPPER_FREQUENCY:
588       g_mutex_lock (filter->lock);
589       filter->upper_frequency = g_value_get_float (value);
590       generate_coefficients (filter);
591       g_mutex_unlock (filter->lock);
592       break;
593     case PROP_RIPPLE:
594       g_mutex_lock (filter->lock);
595       filter->ripple = g_value_get_float (value);
596       generate_coefficients (filter);
597       g_mutex_unlock (filter->lock);
598       break;
599     case PROP_POLES:
600       g_mutex_lock (filter->lock);
601       filter->poles = GST_ROUND_UP_4 (g_value_get_int (value));
602       generate_coefficients (filter);
603       g_mutex_unlock (filter->lock);
604       break;
605     default:
606       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
607       break;
608   }
609 }
610
611 static void
612 gst_audio_cheb_band_get_property (GObject * object, guint prop_id,
613     GValue * value, GParamSpec * pspec)
614 {
615   GstAudioChebBand *filter = GST_AUDIO_CHEB_BAND (object);
616
617   switch (prop_id) {
618     case PROP_MODE:
619       g_value_set_enum (value, filter->mode);
620       break;
621     case PROP_TYPE:
622       g_value_set_int (value, filter->type);
623       break;
624     case PROP_LOWER_FREQUENCY:
625       g_value_set_float (value, filter->lower_frequency);
626       break;
627     case PROP_UPPER_FREQUENCY:
628       g_value_set_float (value, filter->upper_frequency);
629       break;
630     case PROP_RIPPLE:
631       g_value_set_float (value, filter->ripple);
632       break;
633     case PROP_POLES:
634       g_value_set_int (value, filter->poles);
635       break;
636     default:
637       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
638       break;
639   }
640 }
641
642 /* GstAudioFilter vmethod implementations */
643
644 static gboolean
645 gst_audio_cheb_band_setup (GstAudioFilter * base, const GstAudioInfo * info)
646 {
647   GstAudioChebBand *filter = GST_AUDIO_CHEB_BAND (base);
648
649   generate_coefficients (filter);
650
651   return GST_AUDIO_FILTER_CLASS (parent_class)->setup (base, info);
652 }