Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / elements / audiochebband.c
1 /* GStreamer
2  *
3  * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org>
4  *
5  * audiochebband.c: Unit test for the audiochebband element
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  * 
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  * 
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22
23 #include <gst/gst.h>
24 #include <gst/base/gstbasetransform.h>
25 #include <gst/check/gstcheck.h>
26
27 #include <math.h>
28
29 /* For ease of programming we use globals to keep refs for our floating
30  * src and sink pads we create; otherwise we always have to do get_pad,
31  * get_peer, and then remove references in every test function */
32 GstPad *mysrcpad, *mysinkpad;
33
34 #define BUFFER_CAPS_STRING_32           \
35     "audio/x-raw-float, "               \
36     "channels = (int) 1, "              \
37     "rate = (int) 44100, "              \
38     "endianness = (int) BYTE_ORDER, "   \
39     "width = (int) 32"                  \
40
41 #define BUFFER_CAPS_STRING_64           \
42     "audio/x-raw-float, "               \
43     "channels = (int) 1, "              \
44     "rate = (int) 44100, "              \
45     "endianness = (int) BYTE_ORDER, "   \
46     "width = (int) 64"                  \
47
48 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
49     GST_PAD_SINK,
50     GST_PAD_ALWAYS,
51     GST_STATIC_CAPS ("audio/x-raw-float, "
52         "channels = (int) 1, "
53         "rate = (int) 44100, "
54         "endianness = (int) BYTE_ORDER, " "width = (int) { 32, 64 }")
55     );
56 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
57     GST_PAD_SRC,
58     GST_PAD_ALWAYS,
59     GST_STATIC_CAPS ("audio/x-raw-float, "
60         "channels = (int) 1, "
61         "rate = (int) 44100, "
62         "endianness = (int) BYTE_ORDER, " "width = (int) { 32, 64 }")
63     );
64
65 static GstElement *
66 setup_audiochebband (void)
67 {
68   GstElement *audiochebband;
69
70   GST_DEBUG ("setup_audiochebband");
71   audiochebband = gst_check_setup_element ("audiochebband");
72   mysrcpad = gst_check_setup_src_pad (audiochebband, &srctemplate, NULL);
73   mysinkpad = gst_check_setup_sink_pad (audiochebband, &sinktemplate, NULL);
74   gst_pad_set_active (mysrcpad, TRUE);
75   gst_pad_set_active (mysinkpad, TRUE);
76
77   return audiochebband;
78 }
79
80 static void
81 cleanup_audiochebband (GstElement * audiochebband)
82 {
83   GST_DEBUG ("cleanup_audiochebband");
84
85   g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
86   g_list_free (buffers);
87   buffers = NULL;
88
89   gst_pad_set_active (mysrcpad, FALSE);
90   gst_pad_set_active (mysinkpad, FALSE);
91   gst_check_teardown_src_pad (audiochebband);
92   gst_check_teardown_sink_pad (audiochebband);
93   gst_check_teardown_element (audiochebband);
94 }
95
96 /* Test if data containing only one frequency component
97  * at 0 is erased with bandpass mode and a 
98  * 2000Hz frequency band around rate/4 */
99 GST_START_TEST (test_type1_32_bp_0hz)
100 {
101   GstElement *audiochebband;
102   GstBuffer *inbuffer, *outbuffer;
103   GstCaps *caps;
104   gfloat *in, *res, rms;
105   gint i;
106
107   audiochebband = setup_audiochebband ();
108   /* Set to bandpass */
109   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
110   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
111   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
112   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
113
114   fail_unless (gst_element_set_state (audiochebband,
115           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
116       "could not set to playing");
117
118   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
119       44100 / 4.0 - 1000, NULL);
120   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
121       44100 / 4.0 + 1000, NULL);
122   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
123   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
124   for (i = 0; i < 1024; i++)
125     in[i] = 1.0;
126
127   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
128   gst_buffer_set_caps (inbuffer, caps);
129   gst_caps_unref (caps);
130   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
131
132   /* pushing gives away my reference ... */
133   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
134   /* ... and puts a new buffer on the global list */
135   fail_unless_equals_int (g_list_length (buffers), 1);
136   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
137
138   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
139
140   rms = 0.0;
141   for (i = 0; i < 1024; i++)
142     rms += res[i] * res[i];
143   rms = sqrt (rms / 1024.0);
144   fail_unless (rms <= 0.1);
145
146   /* cleanup */
147   cleanup_audiochebband (audiochebband);
148 }
149
150 GST_END_TEST;
151
152 /* Test if data containing only one frequency component
153  * at band center is preserved with bandpass mode and a 
154  * 2000Hz frequency band around rate/4 */
155 GST_START_TEST (test_type1_32_bp_11025hz)
156 {
157   GstElement *audiochebband;
158   GstBuffer *inbuffer, *outbuffer;
159   GstCaps *caps;
160   gfloat *in, *res, rms;
161   gint i;
162
163   audiochebband = setup_audiochebband ();
164   /* Set to bandpass */
165   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
166   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
167   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
168   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
169
170   fail_unless (gst_element_set_state (audiochebband,
171           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
172       "could not set to playing");
173
174   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
175       44100 / 4.0 - 1000, NULL);
176   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
177       44100 / 4.0 + 1000, NULL);
178   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
179   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
180   for (i = 0; i < 1024; i += 4) {
181     in[i] = 0.0;
182     in[i + 1] = 1.0;
183     in[i + 2] = 0.0;
184     in[i + 3] = -1.0;
185   }
186
187   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
188   gst_buffer_set_caps (inbuffer, caps);
189   gst_caps_unref (caps);
190   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
191
192   /* pushing gives away my reference ... */
193   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
194   /* ... and puts a new buffer on the global list */
195   fail_unless_equals_int (g_list_length (buffers), 1);
196   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
197
198   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
199
200   rms = 0.0;
201   for (i = 0; i < 1024; i++)
202     rms += res[i] * res[i];
203   rms = sqrt (rms / 1024.0);
204   fail_unless (rms >= 0.6);
205
206   /* cleanup */
207   cleanup_audiochebband (audiochebband);
208 }
209
210 GST_END_TEST;
211
212 /* Test if data containing only one frequency component
213  * at rate/2 is erased with bandpass mode and a 
214  * 2000Hz frequency band around rate/4 */
215 GST_START_TEST (test_type1_32_bp_22050hz)
216 {
217   GstElement *audiochebband;
218   GstBuffer *inbuffer, *outbuffer;
219   GstCaps *caps;
220   gfloat *in, *res, rms;
221   gint i;
222
223   audiochebband = setup_audiochebband ();
224   /* Set to bandpass */
225   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
226   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
227   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
228   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
229
230   fail_unless (gst_element_set_state (audiochebband,
231           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
232       "could not set to playing");
233
234   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
235       44100 / 4.0 - 1000, NULL);
236   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
237       44100 / 4.0 + 1000, NULL);
238   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
239   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
240   for (i = 0; i < 1024; i += 2) {
241     in[i] = 1.0;
242     in[i + 1] = -1.0;
243   }
244
245   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
246   gst_buffer_set_caps (inbuffer, caps);
247   gst_caps_unref (caps);
248   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
249
250   /* pushing gives away my reference ... */
251   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
252   /* ... and puts a new buffer on the global list */
253   fail_unless_equals_int (g_list_length (buffers), 1);
254   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
255
256   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
257
258   rms = 0.0;
259   for (i = 0; i < 1024; i++)
260     rms += res[i] * res[i];
261   rms = sqrt (rms / 1024.0);
262   fail_unless (rms <= 0.1);
263
264   /* cleanup */
265   cleanup_audiochebband (audiochebband);
266 }
267
268 GST_END_TEST;
269
270 /* Test if data containing only one frequency component
271  * at 0 is preserved with bandreject mode and a 
272  * 2000Hz frequency band around rate/4 */
273 GST_START_TEST (test_type1_32_br_0hz)
274 {
275   GstElement *audiochebband;
276   GstBuffer *inbuffer, *outbuffer;
277   GstCaps *caps;
278   gfloat *in, *res, rms;
279   gint i;
280
281   audiochebband = setup_audiochebband ();
282   /* Set to bandreject */
283   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
284   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
285   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
286   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
287
288   fail_unless (gst_element_set_state (audiochebband,
289           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
290       "could not set to playing");
291
292   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
293       44100 / 4.0 - 1000, NULL);
294   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
295       44100 / 4.0 + 1000, NULL);
296   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
297   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
298   for (i = 0; i < 1024; i++)
299     in[i] = 1.0;
300
301   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
302   gst_buffer_set_caps (inbuffer, caps);
303   gst_caps_unref (caps);
304   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
305
306   /* pushing gives away my reference ... */
307   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
308   /* ... and puts a new buffer on the global list */
309   fail_unless_equals_int (g_list_length (buffers), 1);
310   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
311
312   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
313
314   rms = 0.0;
315   for (i = 0; i < 1024; i++)
316     rms += res[i] * res[i];
317   rms = sqrt (rms / 1024.0);
318   fail_unless (rms >= 0.9);
319
320   /* cleanup */
321   cleanup_audiochebband (audiochebband);
322 }
323
324 GST_END_TEST;
325
326 /* Test if data containing only one frequency component
327  * at band center is erased with bandreject mode and a 
328  * 2000Hz frequency band around rate/4 */
329 GST_START_TEST (test_type1_32_br_11025hz)
330 {
331   GstElement *audiochebband;
332   GstBuffer *inbuffer, *outbuffer;
333   GstCaps *caps;
334   gfloat *in, *res, rms;
335   gint i;
336
337   audiochebband = setup_audiochebband ();
338   /* Set to bandreject */
339   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
340   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
341   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
342   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
343
344   fail_unless (gst_element_set_state (audiochebband,
345           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
346       "could not set to playing");
347
348   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
349       44100 / 4.0 - 1000, NULL);
350   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
351       44100 / 4.0 + 1000, NULL);
352   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
353   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
354   for (i = 0; i < 1024; i += 4) {
355     in[i] = 0.0;
356     in[i + 1] = 1.0;
357     in[i + 2] = 0.0;
358     in[i + 3] = -1.0;
359   }
360
361   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
362   gst_buffer_set_caps (inbuffer, caps);
363   gst_caps_unref (caps);
364   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
365
366   /* pushing gives away my reference ... */
367   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
368   /* ... and puts a new buffer on the global list */
369   fail_unless_equals_int (g_list_length (buffers), 1);
370   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
371
372   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
373
374   rms = 0.0;
375   for (i = 0; i < 1024; i++)
376     rms += res[i] * res[i];
377   rms = sqrt (rms / 1024.0);
378   fail_unless (rms <= 0.1);
379
380   /* cleanup */
381   cleanup_audiochebband (audiochebband);
382 }
383
384 GST_END_TEST;
385
386 /* Test if data containing only one frequency component
387  * at rate/2 is preserved with bandreject mode and a 
388  * 2000Hz frequency band around rate/4 */
389 GST_START_TEST (test_type1_32_br_22050hz)
390 {
391   GstElement *audiochebband;
392   GstBuffer *inbuffer, *outbuffer;
393   GstCaps *caps;
394   gfloat *in, *res, rms;
395   gint i;
396
397   audiochebband = setup_audiochebband ();
398   /* Set to bandreject */
399   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
400   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
401   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
402   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
403
404   fail_unless (gst_element_set_state (audiochebband,
405           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
406       "could not set to playing");
407
408   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
409       44100 / 4.0 - 1000, NULL);
410   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
411       44100 / 4.0 + 1000, NULL);
412   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
413   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
414   for (i = 0; i < 1024; i += 2) {
415     in[i] = 1.0;
416     in[i + 1] = -1.0;
417   }
418
419   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
420   gst_buffer_set_caps (inbuffer, caps);
421   gst_caps_unref (caps);
422   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
423
424   /* pushing gives away my reference ... */
425   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
426   /* ... and puts a new buffer on the global list */
427   fail_unless_equals_int (g_list_length (buffers), 1);
428   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
429
430   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
431
432   rms = 0.0;
433   for (i = 0; i < 1024; i++)
434     rms += res[i] * res[i];
435   rms = sqrt (rms / 1024.0);
436   fail_unless (rms >= 0.9);
437
438   /* cleanup */
439   cleanup_audiochebband (audiochebband);
440 }
441
442 GST_END_TEST;
443
444 /* Test if data containing only one frequency component
445  * at 0 is erased with bandpass mode and a 
446  * 2000Hz frequency band around rate/4 */
447 GST_START_TEST (test_type1_64_bp_0hz)
448 {
449   GstElement *audiochebband;
450   GstBuffer *inbuffer, *outbuffer;
451   GstCaps *caps;
452   gdouble *in, *res, rms;
453   gint i;
454
455   audiochebband = setup_audiochebband ();
456   /* Set to bandpass */
457   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
458   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
459   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
460   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
461
462   fail_unless (gst_element_set_state (audiochebband,
463           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
464       "could not set to playing");
465
466   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
467       44100 / 4.0 - 1000, NULL);
468   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
469       44100 / 4.0 + 1000, NULL);
470   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
471   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
472   for (i = 0; i < 1024; i++)
473     in[i] = 1.0;
474
475   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
476   gst_buffer_set_caps (inbuffer, caps);
477   gst_caps_unref (caps);
478   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
479
480   /* pushing gives away my reference ... */
481   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
482   /* ... and puts a new buffer on the global list */
483   fail_unless_equals_int (g_list_length (buffers), 1);
484   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
485
486   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
487
488   rms = 0.0;
489   for (i = 0; i < 1024; i++)
490     rms += res[i] * res[i];
491   rms = sqrt (rms / 1024.0);
492   fail_unless (rms <= 0.1);
493
494   /* cleanup */
495   cleanup_audiochebband (audiochebband);
496 }
497
498 GST_END_TEST;
499
500 /* Test if data containing only one frequency component
501  * at band center is preserved with bandpass mode and a 
502  * 2000Hz frequency band around rate/4 */
503 GST_START_TEST (test_type1_64_bp_11025hz)
504 {
505   GstElement *audiochebband;
506   GstBuffer *inbuffer, *outbuffer;
507   GstCaps *caps;
508   gdouble *in, *res, rms;
509   gint i;
510
511   audiochebband = setup_audiochebband ();
512   /* Set to bandpass */
513   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
514   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
515   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
516   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
517
518   fail_unless (gst_element_set_state (audiochebband,
519           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
520       "could not set to playing");
521
522   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
523       44100 / 4.0 - 1000, NULL);
524   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
525       44100 / 4.0 + 1000, NULL);
526   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
527   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
528   for (i = 0; i < 1024; i += 4) {
529     in[i] = 0.0;
530     in[i + 1] = 1.0;
531     in[i + 2] = 0.0;
532     in[i + 3] = -1.0;
533   }
534
535   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
536   gst_buffer_set_caps (inbuffer, caps);
537   gst_caps_unref (caps);
538   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
539
540   /* pushing gives away my reference ... */
541   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
542   /* ... and puts a new buffer on the global list */
543   fail_unless_equals_int (g_list_length (buffers), 1);
544   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
545
546   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
547
548   rms = 0.0;
549   for (i = 0; i < 1024; i++)
550     rms += res[i] * res[i];
551   rms = sqrt (rms / 1024.0);
552   fail_unless (rms >= 0.6);
553
554   /* cleanup */
555   cleanup_audiochebband (audiochebband);
556 }
557
558 GST_END_TEST;
559
560 /* Test if data containing only one frequency component
561  * at rate/2 is erased with bandpass mode and a 
562  * 2000Hz frequency band around rate/4 */
563 GST_START_TEST (test_type1_64_bp_22050hz)
564 {
565   GstElement *audiochebband;
566   GstBuffer *inbuffer, *outbuffer;
567   GstCaps *caps;
568   gdouble *in, *res, rms;
569   gint i;
570
571   audiochebband = setup_audiochebband ();
572   /* Set to bandpass */
573   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
574   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
575   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
576   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
577
578   fail_unless (gst_element_set_state (audiochebband,
579           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
580       "could not set to playing");
581
582   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
583       44100 / 4.0 - 1000, NULL);
584   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
585       44100 / 4.0 + 1000, NULL);
586   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
587   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
588   for (i = 0; i < 1024; i += 2) {
589     in[i] = 1.0;
590     in[i + 1] = -1.0;
591   }
592
593   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
594   gst_buffer_set_caps (inbuffer, caps);
595   gst_caps_unref (caps);
596   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
597
598   /* pushing gives away my reference ... */
599   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
600   /* ... and puts a new buffer on the global list */
601   fail_unless_equals_int (g_list_length (buffers), 1);
602   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
603
604   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
605
606   rms = 0.0;
607   for (i = 0; i < 1024; i++)
608     rms += res[i] * res[i];
609   rms = sqrt (rms / 1024.0);
610   fail_unless (rms <= 0.1);
611
612   /* cleanup */
613   cleanup_audiochebband (audiochebband);
614 }
615
616 GST_END_TEST;
617
618 /* Test if data containing only one frequency component
619  * at 0 is preserved with bandreject mode and a 
620  * 2000Hz frequency band around rate/4 */
621 GST_START_TEST (test_type1_64_br_0hz)
622 {
623   GstElement *audiochebband;
624   GstBuffer *inbuffer, *outbuffer;
625   GstCaps *caps;
626   gdouble *in, *res, rms;
627   gint i;
628
629   audiochebband = setup_audiochebband ();
630   /* Set to bandreject */
631   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
632   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
633   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
634   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
635
636   fail_unless (gst_element_set_state (audiochebband,
637           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
638       "could not set to playing");
639
640   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
641       44100 / 4.0 - 1000, NULL);
642   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
643       44100 / 4.0 + 1000, NULL);
644   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
645   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
646   for (i = 0; i < 1024; i++)
647     in[i] = 1.0;
648
649   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
650   gst_buffer_set_caps (inbuffer, caps);
651   gst_caps_unref (caps);
652   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
653
654   /* pushing gives away my reference ... */
655   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
656   /* ... and puts a new buffer on the global list */
657   fail_unless_equals_int (g_list_length (buffers), 1);
658   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
659
660   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
661
662   rms = 0.0;
663   for (i = 0; i < 1024; i++)
664     rms += res[i] * res[i];
665   rms = sqrt (rms / 1024.0);
666   fail_unless (rms >= 0.9);
667
668   /* cleanup */
669   cleanup_audiochebband (audiochebband);
670 }
671
672 GST_END_TEST;
673
674 /* Test if data containing only one frequency component
675  * at band center is erased with bandreject mode and a 
676  * 2000Hz frequency band around rate/4 */
677 GST_START_TEST (test_type1_64_br_11025hz)
678 {
679   GstElement *audiochebband;
680   GstBuffer *inbuffer, *outbuffer;
681   GstCaps *caps;
682   gdouble *in, *res, rms;
683   gint i;
684
685   audiochebband = setup_audiochebband ();
686   /* Set to bandreject */
687   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
688   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
689   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
690   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
691
692   fail_unless (gst_element_set_state (audiochebband,
693           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
694       "could not set to playing");
695
696   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
697       44100 / 4.0 - 1000, NULL);
698   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
699       44100 / 4.0 + 1000, NULL);
700   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
701   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
702   for (i = 0; i < 1024; i += 4) {
703     in[i] = 0.0;
704     in[i + 1] = 1.0;
705     in[i + 2] = 0.0;
706     in[i + 3] = -1.0;
707   }
708
709   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
710   gst_buffer_set_caps (inbuffer, caps);
711   gst_caps_unref (caps);
712   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
713
714   /* pushing gives away my reference ... */
715   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
716   /* ... and puts a new buffer on the global list */
717   fail_unless_equals_int (g_list_length (buffers), 1);
718   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
719
720   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
721
722   rms = 0.0;
723   for (i = 0; i < 1024; i++)
724     rms += res[i] * res[i];
725   rms = sqrt (rms / 1024.0);
726   fail_unless (rms <= 0.1);
727
728   /* cleanup */
729   cleanup_audiochebband (audiochebband);
730 }
731
732 GST_END_TEST;
733
734 /* Test if data containing only one frequency component
735  * at rate/2 is preserved with bandreject mode and a 
736  * 2000Hz frequency band around rate/4 */
737 GST_START_TEST (test_type1_64_br_22050hz)
738 {
739   GstElement *audiochebband;
740   GstBuffer *inbuffer, *outbuffer;
741   GstCaps *caps;
742   gdouble *in, *res, rms;
743   gint i;
744
745   audiochebband = setup_audiochebband ();
746   /* Set to bandreject */
747   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
748   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
749   g_object_set (G_OBJECT (audiochebband), "type", 1, NULL);
750   g_object_set (G_OBJECT (audiochebband), "ripple", 0.25, NULL);
751
752   fail_unless (gst_element_set_state (audiochebband,
753           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
754       "could not set to playing");
755
756   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
757       44100 / 4.0 - 1000, NULL);
758   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
759       44100 / 4.0 + 1000, NULL);
760   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
761   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
762   for (i = 0; i < 1024; i += 2) {
763     in[i] = 1.0;
764     in[i + 1] = -1.0;
765   }
766
767   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
768   gst_buffer_set_caps (inbuffer, caps);
769   gst_caps_unref (caps);
770   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
771
772   /* pushing gives away my reference ... */
773   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
774   /* ... and puts a new buffer on the global list */
775   fail_unless_equals_int (g_list_length (buffers), 1);
776   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
777
778   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
779
780   rms = 0.0;
781   for (i = 0; i < 1024; i++)
782     rms += res[i] * res[i];
783   rms = sqrt (rms / 1024.0);
784   fail_unless (rms >= 0.9);
785
786   /* cleanup */
787   cleanup_audiochebband (audiochebband);
788 }
789
790 GST_END_TEST;
791
792 /* Test if data containing only one frequency component
793  * at 0 is erased with bandpass mode and a 
794  * 2000Hz frequency band around rate/4 */
795 GST_START_TEST (test_type2_32_bp_0hz)
796 {
797   GstElement *audiochebband;
798   GstBuffer *inbuffer, *outbuffer;
799   GstCaps *caps;
800   gfloat *in, *res, rms;
801   gint i;
802
803   audiochebband = setup_audiochebband ();
804   /* Set to bandpass */
805   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
806   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
807   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
808   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
809
810   fail_unless (gst_element_set_state (audiochebband,
811           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
812       "could not set to playing");
813
814   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
815       44100 / 4.0 - 1000, NULL);
816   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
817       44100 / 4.0 + 1000, NULL);
818   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
819   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
820   for (i = 0; i < 1024; i++)
821     in[i] = 1.0;
822
823   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
824   gst_buffer_set_caps (inbuffer, caps);
825   gst_caps_unref (caps);
826   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
827
828   /* pushing gives away my reference ... */
829   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
830   /* ... and puts a new buffer on the global list */
831   fail_unless_equals_int (g_list_length (buffers), 1);
832   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
833
834   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
835
836   rms = 0.0;
837   for (i = 0; i < 1024; i++)
838     rms += res[i] * res[i];
839   rms = sqrt (rms / 1024.0);
840   fail_unless (rms <= 0.1);
841
842   /* cleanup */
843   cleanup_audiochebband (audiochebband);
844 }
845
846 GST_END_TEST;
847
848 /* Test if data containing only one frequency component
849  * at band center is preserved with bandpass mode and a 
850  * 2000Hz frequency band around rate/4 */
851 GST_START_TEST (test_type2_32_bp_11025hz)
852 {
853   GstElement *audiochebband;
854   GstBuffer *inbuffer, *outbuffer;
855   GstCaps *caps;
856   gfloat *in, *res, rms;
857   gint i;
858
859   audiochebband = setup_audiochebband ();
860   /* Set to bandpass */
861   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
862   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
863   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
864   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
865
866   fail_unless (gst_element_set_state (audiochebband,
867           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
868       "could not set to playing");
869
870   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
871       44100 / 4.0 - 1000, NULL);
872   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
873       44100 / 4.0 + 1000, NULL);
874   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
875   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
876   for (i = 0; i < 1024; i += 4) {
877     in[i] = 0.0;
878     in[i + 1] = 1.0;
879     in[i + 2] = 0.0;
880     in[i + 3] = -1.0;
881   }
882
883   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
884   gst_buffer_set_caps (inbuffer, caps);
885   gst_caps_unref (caps);
886   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
887
888   /* pushing gives away my reference ... */
889   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
890   /* ... and puts a new buffer on the global list */
891   fail_unless_equals_int (g_list_length (buffers), 1);
892   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
893
894   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
895
896   rms = 0.0;
897   for (i = 0; i < 1024; i++)
898     rms += res[i] * res[i];
899   rms = sqrt (rms / 1024.0);
900   fail_unless (rms >= 0.6);
901
902   /* cleanup */
903   cleanup_audiochebband (audiochebband);
904 }
905
906 GST_END_TEST;
907
908 /* Test if data containing only one frequency component
909  * at rate/2 is erased with bandpass mode and a 
910  * 2000Hz frequency band around rate/4 */
911 GST_START_TEST (test_type2_32_bp_22050hz)
912 {
913   GstElement *audiochebband;
914   GstBuffer *inbuffer, *outbuffer;
915   GstCaps *caps;
916   gfloat *in, *res, rms;
917   gint i;
918
919   audiochebband = setup_audiochebband ();
920   /* Set to bandpass */
921   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
922   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
923   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
924   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
925
926   fail_unless (gst_element_set_state (audiochebband,
927           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
928       "could not set to playing");
929
930   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
931       44100 / 4.0 - 1000, NULL);
932   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
933       44100 / 4.0 + 1000, NULL);
934   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
935   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
936   for (i = 0; i < 1024; i += 2) {
937     in[i] = 1.0;
938     in[i + 1] = -1.0;
939   }
940
941   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
942   gst_buffer_set_caps (inbuffer, caps);
943   gst_caps_unref (caps);
944   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
945
946   /* pushing gives away my reference ... */
947   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
948   /* ... and puts a new buffer on the global list */
949   fail_unless_equals_int (g_list_length (buffers), 1);
950   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
951
952   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
953
954   rms = 0.0;
955   for (i = 0; i < 1024; i++)
956     rms += res[i] * res[i];
957   rms = sqrt (rms / 1024.0);
958   fail_unless (rms <= 0.1);
959
960   /* cleanup */
961   cleanup_audiochebband (audiochebband);
962 }
963
964 GST_END_TEST;
965
966 /* Test if data containing only one frequency component
967  * at 0 is preserved with bandreject mode and a 
968  * 2000Hz frequency band around rate/4 */
969 GST_START_TEST (test_type2_32_br_0hz)
970 {
971   GstElement *audiochebband;
972   GstBuffer *inbuffer, *outbuffer;
973   GstCaps *caps;
974   gfloat *in, *res, rms;
975   gint i;
976
977   audiochebband = setup_audiochebband ();
978   /* Set to bandreject */
979   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
980   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
981   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
982   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
983
984   fail_unless (gst_element_set_state (audiochebband,
985           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
986       "could not set to playing");
987
988   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
989       44100 / 4.0 - 1000, NULL);
990   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
991       44100 / 4.0 + 1000, NULL);
992   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
993   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
994   for (i = 0; i < 1024; i++)
995     in[i] = 1.0;
996
997   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
998   gst_buffer_set_caps (inbuffer, caps);
999   gst_caps_unref (caps);
1000   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1001
1002   /* pushing gives away my reference ... */
1003   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1004   /* ... and puts a new buffer on the global list */
1005   fail_unless_equals_int (g_list_length (buffers), 1);
1006   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1007
1008   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
1009
1010   rms = 0.0;
1011   for (i = 0; i < 1024; i++)
1012     rms += res[i] * res[i];
1013   rms = sqrt (rms / 1024.0);
1014   fail_unless (rms >= 0.9);
1015
1016   /* cleanup */
1017   cleanup_audiochebband (audiochebband);
1018 }
1019
1020 GST_END_TEST;
1021
1022 /* Test if data containing only one frequency component
1023  * at band center is erased with bandreject mode and a 
1024  * 2000Hz frequency band around rate/4 */
1025 GST_START_TEST (test_type2_32_br_11025hz)
1026 {
1027   GstElement *audiochebband;
1028   GstBuffer *inbuffer, *outbuffer;
1029   GstCaps *caps;
1030   gfloat *in, *res, rms;
1031   gint i;
1032
1033   audiochebband = setup_audiochebband ();
1034   /* Set to bandreject */
1035   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
1036   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
1037   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
1038   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
1039
1040   fail_unless (gst_element_set_state (audiochebband,
1041           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1042       "could not set to playing");
1043
1044   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
1045       44100 / 4.0 - 1000, NULL);
1046   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
1047       44100 / 4.0 + 1000, NULL);
1048   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
1049   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
1050   for (i = 0; i < 1024; i += 4) {
1051     in[i] = 0.0;
1052     in[i + 1] = 1.0;
1053     in[i + 2] = 0.0;
1054     in[i + 3] = -1.0;
1055   }
1056
1057   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
1058   gst_buffer_set_caps (inbuffer, caps);
1059   gst_caps_unref (caps);
1060   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1061
1062   /* pushing gives away my reference ... */
1063   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1064   /* ... and puts a new buffer on the global list */
1065   fail_unless_equals_int (g_list_length (buffers), 1);
1066   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1067
1068   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
1069
1070   rms = 0.0;
1071   for (i = 0; i < 1024; i++)
1072     rms += res[i] * res[i];
1073   rms = sqrt (rms / 1024.0);
1074   fail_unless (rms <= 0.1);
1075
1076   /* cleanup */
1077   cleanup_audiochebband (audiochebband);
1078 }
1079
1080 GST_END_TEST;
1081
1082 /* Test if data containing only one frequency component
1083  * at rate/2 is preserved with bandreject mode and a 
1084  * 2000Hz frequency band around rate/4 */
1085 GST_START_TEST (test_type2_32_br_22050hz)
1086 {
1087   GstElement *audiochebband;
1088   GstBuffer *inbuffer, *outbuffer;
1089   GstCaps *caps;
1090   gfloat *in, *res, rms;
1091   gint i;
1092
1093   audiochebband = setup_audiochebband ();
1094   /* Set to bandreject */
1095   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
1096   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
1097   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
1098   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
1099
1100   fail_unless (gst_element_set_state (audiochebband,
1101           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1102       "could not set to playing");
1103
1104   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
1105       44100 / 4.0 - 1000, NULL);
1106   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
1107       44100 / 4.0 + 1000, NULL);
1108   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gfloat));
1109   in = (gfloat *) GST_BUFFER_DATA (inbuffer);
1110   for (i = 0; i < 1024; i += 2) {
1111     in[i] = 1.0;
1112     in[i + 1] = -1.0;
1113   }
1114
1115   caps = gst_caps_from_string (BUFFER_CAPS_STRING_32);
1116   gst_buffer_set_caps (inbuffer, caps);
1117   gst_caps_unref (caps);
1118   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1119
1120   /* pushing gives away my reference ... */
1121   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1122   /* ... and puts a new buffer on the global list */
1123   fail_unless_equals_int (g_list_length (buffers), 1);
1124   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1125
1126   res = (gfloat *) GST_BUFFER_DATA (outbuffer);
1127
1128   rms = 0.0;
1129   for (i = 0; i < 1024; i++)
1130     rms += res[i] * res[i];
1131   rms = sqrt (rms / 1024.0);
1132   fail_unless (rms >= 0.9);
1133
1134   /* cleanup */
1135   cleanup_audiochebband (audiochebband);
1136 }
1137
1138 GST_END_TEST;
1139
1140 /* Test if data containing only one frequency component
1141  * at 0 is erased with bandpass mode and a 
1142  * 2000Hz frequency band around rate/4 */
1143 GST_START_TEST (test_type2_64_bp_0hz)
1144 {
1145   GstElement *audiochebband;
1146   GstBuffer *inbuffer, *outbuffer;
1147   GstCaps *caps;
1148   gdouble *in, *res, rms;
1149   gint i;
1150
1151   audiochebband = setup_audiochebband ();
1152   /* Set to bandpass */
1153   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
1154   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
1155   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
1156   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
1157
1158   fail_unless (gst_element_set_state (audiochebband,
1159           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1160       "could not set to playing");
1161
1162   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
1163       44100 / 4.0 - 1000, NULL);
1164   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
1165       44100 / 4.0 + 1000, NULL);
1166   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
1167   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
1168   for (i = 0; i < 1024; i++)
1169     in[i] = 1.0;
1170
1171   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
1172   gst_buffer_set_caps (inbuffer, caps);
1173   gst_caps_unref (caps);
1174   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1175
1176   /* pushing gives away my reference ... */
1177   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1178   /* ... and puts a new buffer on the global list */
1179   fail_unless_equals_int (g_list_length (buffers), 1);
1180   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1181
1182   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
1183
1184   rms = 0.0;
1185   for (i = 0; i < 1024; i++)
1186     rms += res[i] * res[i];
1187   rms = sqrt (rms / 1024.0);
1188   fail_unless (rms <= 0.1);
1189
1190   /* cleanup */
1191   cleanup_audiochebband (audiochebband);
1192 }
1193
1194 GST_END_TEST;
1195
1196 /* Test if data containing only one frequency component
1197  * at band center is preserved with bandpass mode and a 
1198  * 2000Hz frequency band around rate/4 */
1199 GST_START_TEST (test_type2_64_bp_11025hz)
1200 {
1201   GstElement *audiochebband;
1202   GstBuffer *inbuffer, *outbuffer;
1203   GstCaps *caps;
1204   gdouble *in, *res, rms;
1205   gint i;
1206
1207   audiochebband = setup_audiochebband ();
1208   /* Set to bandpass */
1209   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
1210   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
1211   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
1212   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
1213
1214   fail_unless (gst_element_set_state (audiochebband,
1215           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1216       "could not set to playing");
1217
1218   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
1219       44100 / 4.0 - 1000, NULL);
1220   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
1221       44100 / 4.0 + 1000, NULL);
1222   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
1223   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
1224   for (i = 0; i < 1024; i += 4) {
1225     in[i] = 0.0;
1226     in[i + 1] = 1.0;
1227     in[i + 2] = 0.0;
1228     in[i + 3] = -1.0;
1229   }
1230
1231   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
1232   gst_buffer_set_caps (inbuffer, caps);
1233   gst_caps_unref (caps);
1234   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1235
1236   /* pushing gives away my reference ... */
1237   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1238   /* ... and puts a new buffer on the global list */
1239   fail_unless_equals_int (g_list_length (buffers), 1);
1240   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1241
1242   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
1243
1244   rms = 0.0;
1245   for (i = 0; i < 1024; i++)
1246     rms += res[i] * res[i];
1247   rms = sqrt (rms / 1024.0);
1248   fail_unless (rms >= 0.6);
1249
1250   /* cleanup */
1251   cleanup_audiochebband (audiochebband);
1252 }
1253
1254 GST_END_TEST;
1255
1256 /* Test if data containing only one frequency component
1257  * at rate/2 is erased with bandpass mode and a 
1258  * 2000Hz frequency band around rate/4 */
1259 GST_START_TEST (test_type2_64_bp_22050hz)
1260 {
1261   GstElement *audiochebband;
1262   GstBuffer *inbuffer, *outbuffer;
1263   GstCaps *caps;
1264   gdouble *in, *res, rms;
1265   gint i;
1266
1267   audiochebband = setup_audiochebband ();
1268   /* Set to bandpass */
1269   g_object_set (G_OBJECT (audiochebband), "mode", 0, NULL);
1270   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
1271   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
1272   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
1273
1274   fail_unless (gst_element_set_state (audiochebband,
1275           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1276       "could not set to playing");
1277
1278   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
1279       44100 / 4.0 - 1000, NULL);
1280   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
1281       44100 / 4.0 + 1000, NULL);
1282   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
1283   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
1284   for (i = 0; i < 1024; i += 2) {
1285     in[i] = 1.0;
1286     in[i + 1] = -1.0;
1287   }
1288
1289   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
1290   gst_buffer_set_caps (inbuffer, caps);
1291   gst_caps_unref (caps);
1292   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1293
1294   /* pushing gives away my reference ... */
1295   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1296   /* ... and puts a new buffer on the global list */
1297   fail_unless_equals_int (g_list_length (buffers), 1);
1298   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1299
1300   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
1301
1302   rms = 0.0;
1303   for (i = 0; i < 1024; i++)
1304     rms += res[i] * res[i];
1305   rms = sqrt (rms / 1024.0);
1306   fail_unless (rms <= 0.1);
1307
1308   /* cleanup */
1309   cleanup_audiochebband (audiochebband);
1310 }
1311
1312 GST_END_TEST;
1313
1314 /* Test if data containing only one frequency component
1315  * at 0 is preserved with bandreject mode and a 
1316  * 2000Hz frequency band around rate/4 */
1317 GST_START_TEST (test_type2_64_br_0hz)
1318 {
1319   GstElement *audiochebband;
1320   GstBuffer *inbuffer, *outbuffer;
1321   GstCaps *caps;
1322   gdouble *in, *res, rms;
1323   gint i;
1324
1325   audiochebband = setup_audiochebband ();
1326   /* Set to bandreject */
1327   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
1328   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
1329   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
1330   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
1331
1332   fail_unless (gst_element_set_state (audiochebband,
1333           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1334       "could not set to playing");
1335
1336   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
1337       44100 / 4.0 - 1000, NULL);
1338   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
1339       44100 / 4.0 + 1000, NULL);
1340   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
1341   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
1342   for (i = 0; i < 1024; i++)
1343     in[i] = 1.0;
1344
1345   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
1346   gst_buffer_set_caps (inbuffer, caps);
1347   gst_caps_unref (caps);
1348   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1349
1350   /* pushing gives away my reference ... */
1351   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1352   /* ... and puts a new buffer on the global list */
1353   fail_unless_equals_int (g_list_length (buffers), 1);
1354   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1355
1356   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
1357
1358   rms = 0.0;
1359   for (i = 0; i < 1024; i++)
1360     rms += res[i] * res[i];
1361   rms = sqrt (rms / 1024.0);
1362   fail_unless (rms >= 0.9);
1363
1364   /* cleanup */
1365   cleanup_audiochebband (audiochebband);
1366 }
1367
1368 GST_END_TEST;
1369
1370 /* Test if data containing only one frequency component
1371  * at band center is erased with bandreject mode and a 
1372  * 2000Hz frequency band around rate/4 */
1373 GST_START_TEST (test_type2_64_br_11025hz)
1374 {
1375   GstElement *audiochebband;
1376   GstBuffer *inbuffer, *outbuffer;
1377   GstCaps *caps;
1378   gdouble *in, *res, rms;
1379   gint i;
1380
1381   audiochebband = setup_audiochebband ();
1382   /* Set to bandreject */
1383   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
1384   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
1385   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
1386   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
1387
1388   fail_unless (gst_element_set_state (audiochebband,
1389           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1390       "could not set to playing");
1391
1392   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
1393       44100 / 4.0 - 1000, NULL);
1394   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
1395       44100 / 4.0 + 1000, NULL);
1396   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
1397   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
1398   for (i = 0; i < 1024; i += 4) {
1399     in[i] = 0.0;
1400     in[i + 1] = 1.0;
1401     in[i + 2] = 0.0;
1402     in[i + 3] = -1.0;
1403   }
1404
1405   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
1406   gst_buffer_set_caps (inbuffer, caps);
1407   gst_caps_unref (caps);
1408   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1409
1410   /* pushing gives away my reference ... */
1411   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1412   /* ... and puts a new buffer on the global list */
1413   fail_unless_equals_int (g_list_length (buffers), 1);
1414   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1415
1416   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
1417
1418   rms = 0.0;
1419   for (i = 0; i < 1024; i++)
1420     rms += res[i] * res[i];
1421   rms = sqrt (rms / 1024.0);
1422   fail_unless (rms <= 0.1);
1423
1424   /* cleanup */
1425   cleanup_audiochebband (audiochebband);
1426 }
1427
1428 GST_END_TEST;
1429
1430 /* Test if data containing only one frequency component
1431  * at rate/2 is preserved with bandreject mode and a 
1432  * 2000Hz frequency band around rate/4 */
1433 GST_START_TEST (test_type2_64_br_22050hz)
1434 {
1435   GstElement *audiochebband;
1436   GstBuffer *inbuffer, *outbuffer;
1437   GstCaps *caps;
1438   gdouble *in, *res, rms;
1439   gint i;
1440
1441   audiochebband = setup_audiochebband ();
1442   /* Set to bandreject */
1443   g_object_set (G_OBJECT (audiochebband), "mode", 1, NULL);
1444   g_object_set (G_OBJECT (audiochebband), "poles", 8, NULL);
1445   g_object_set (G_OBJECT (audiochebband), "type", 2, NULL);
1446   g_object_set (G_OBJECT (audiochebband), "ripple", 40.0, NULL);
1447
1448   fail_unless (gst_element_set_state (audiochebband,
1449           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1450       "could not set to playing");
1451
1452   g_object_set (G_OBJECT (audiochebband), "lower-frequency",
1453       44100 / 4.0 - 1000, NULL);
1454   g_object_set (G_OBJECT (audiochebband), "upper-frequency",
1455       44100 / 4.0 + 1000, NULL);
1456   inbuffer = gst_buffer_new_and_alloc (1024 * sizeof (gdouble));
1457   in = (gdouble *) GST_BUFFER_DATA (inbuffer);
1458   for (i = 0; i < 1024; i += 2) {
1459     in[i] = 1.0;
1460     in[i + 1] = -1.0;
1461   }
1462
1463   caps = gst_caps_from_string (BUFFER_CAPS_STRING_64);
1464   gst_buffer_set_caps (inbuffer, caps);
1465   gst_caps_unref (caps);
1466   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
1467
1468   /* pushing gives away my reference ... */
1469   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1470   /* ... and puts a new buffer on the global list */
1471   fail_unless_equals_int (g_list_length (buffers), 1);
1472   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1473
1474   res = (gdouble *) GST_BUFFER_DATA (outbuffer);
1475
1476   rms = 0.0;
1477   for (i = 0; i < 1024; i++)
1478     rms += res[i] * res[i];
1479   rms = sqrt (rms / 1024.0);
1480   fail_unless (rms >= 0.9);
1481
1482   /* cleanup */
1483   cleanup_audiochebband (audiochebband);
1484 }
1485
1486 GST_END_TEST;
1487
1488 static Suite *
1489 audiochebband_suite (void)
1490 {
1491   Suite *s = suite_create ("audiochebband");
1492   TCase *tc_chain = tcase_create ("general");
1493
1494   suite_add_tcase (s, tc_chain);
1495   tcase_add_test (tc_chain, test_type1_32_bp_0hz);
1496   tcase_add_test (tc_chain, test_type1_32_bp_11025hz);
1497   tcase_add_test (tc_chain, test_type1_32_bp_22050hz);
1498   tcase_add_test (tc_chain, test_type1_32_br_0hz);
1499   tcase_add_test (tc_chain, test_type1_32_br_11025hz);
1500   tcase_add_test (tc_chain, test_type1_32_br_22050hz);
1501   tcase_add_test (tc_chain, test_type1_64_bp_0hz);
1502   tcase_add_test (tc_chain, test_type1_64_bp_11025hz);
1503   tcase_add_test (tc_chain, test_type1_64_bp_22050hz);
1504   tcase_add_test (tc_chain, test_type1_64_br_0hz);
1505   tcase_add_test (tc_chain, test_type1_64_br_11025hz);
1506   tcase_add_test (tc_chain, test_type1_64_br_22050hz);
1507   tcase_add_test (tc_chain, test_type2_32_bp_0hz);
1508   tcase_add_test (tc_chain, test_type2_32_bp_11025hz);
1509   tcase_add_test (tc_chain, test_type2_32_bp_22050hz);
1510   tcase_add_test (tc_chain, test_type2_32_br_0hz);
1511   tcase_add_test (tc_chain, test_type2_32_br_11025hz);
1512   tcase_add_test (tc_chain, test_type2_32_br_22050hz);
1513   tcase_add_test (tc_chain, test_type2_64_bp_0hz);
1514   tcase_add_test (tc_chain, test_type2_64_bp_11025hz);
1515   tcase_add_test (tc_chain, test_type2_64_bp_22050hz);
1516   tcase_add_test (tc_chain, test_type2_64_br_0hz);
1517   tcase_add_test (tc_chain, test_type2_64_br_11025hz);
1518   tcase_add_test (tc_chain, test_type2_64_br_22050hz);
1519
1520   return s;
1521 }
1522
1523 int
1524 main (int argc, char **argv)
1525 {
1526   int nf;
1527
1528   Suite *s = audiochebband_suite ();
1529   SRunner *sr = srunner_create (s);
1530
1531   gst_check_init (&argc, &argv);
1532
1533   srunner_run_all (sr, CK_NORMAL);
1534   nf = srunner_ntests_failed (sr);
1535   srunner_free (sr);
1536
1537   return nf;
1538 }