tizen 2.0 init
[framework/multimedia/gst-plugins-base0.10.git] / tests / check / elements / audioresample.c
1 /* GStreamer
2  *
3  * unit test for audioresample, based on the audioresample unit test
4  *
5  * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
6  * Copyright (C) <2006> Tim-Philipp Müller <tim at centricular net>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include <unistd.h>
25
26 #include <gst/check/gstcheck.h>
27
28 #include <gst/audio/audio.h>
29
30 #include <gst/fft/gstfft.h>
31 #include <gst/fft/gstffts16.h>
32 #include <gst/fft/gstffts32.h>
33 #include <gst/fft/gstfftf32.h>
34 #include <gst/fft/gstfftf64.h>
35
36 /* For ease of programming we use globals to keep refs for our floating
37  * src and sink pads we create; otherwise we always have to do get_pad,
38  * get_peer, and then remove references in every test function */
39 static GstPad *mysrcpad, *mysinkpad;
40
41 #define RESAMPLE_CAPS_FLOAT             \
42     "audio/x-raw-float, "               \
43     "channels = (int) [ 1, MAX ], "     \
44     "rate = (int) [ 1,  MAX ], "        \
45     "endianness = (int) BYTE_ORDER, "   \
46     "width = (int) { 32, 64 }"
47
48 #define RESAMPLE_CAPS_INT               \
49     "audio/x-raw-int, "                 \
50     "channels = (int) [ 1, MAX ], "     \
51     "rate = (int) [ 1,  MAX ], "        \
52     "endianness = (int) BYTE_ORDER, "   \
53     "width = (int) { 16, 32 }, "        \
54     "depth = (int) { 16, 32 }, "        \
55     "signed = (bool) TRUE"
56
57 #define RESAMPLE_CAPS_TEMPLATE_STRING   \
58     RESAMPLE_CAPS_FLOAT " ; " \
59     RESAMPLE_CAPS_INT
60
61 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
62     GST_PAD_SINK,
63     GST_PAD_ALWAYS,
64     GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING)
65     );
66 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
67     GST_PAD_SRC,
68     GST_PAD_ALWAYS,
69     GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING)
70     );
71
72 static GstElement *
73 setup_audioresample (int channels, int inrate, int outrate, int width,
74     gboolean fp)
75 {
76   GstElement *audioresample;
77   GstCaps *caps;
78   GstStructure *structure;
79
80   GST_DEBUG ("setup_audioresample");
81   audioresample = gst_check_setup_element ("audioresample");
82
83   if (fp)
84     caps = gst_caps_from_string (RESAMPLE_CAPS_FLOAT);
85   else
86     caps = gst_caps_from_string (RESAMPLE_CAPS_INT);
87   structure = gst_caps_get_structure (caps, 0);
88   gst_structure_set (structure, "channels", G_TYPE_INT, channels,
89       "rate", G_TYPE_INT, inrate, "width", G_TYPE_INT, width, NULL);
90   if (!fp)
91     gst_structure_set (structure, "depth", G_TYPE_INT, width, NULL);
92   fail_unless (gst_caps_is_fixed (caps));
93
94   fail_unless (gst_element_set_state (audioresample,
95           GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS,
96       "could not set to paused");
97
98   mysrcpad = gst_check_setup_src_pad (audioresample, &srctemplate, caps);
99   gst_pad_set_caps (mysrcpad, caps);
100   gst_caps_unref (caps);
101
102   if (fp)
103     caps = gst_caps_from_string (RESAMPLE_CAPS_FLOAT);
104   else
105     caps = gst_caps_from_string (RESAMPLE_CAPS_INT);
106   structure = gst_caps_get_structure (caps, 0);
107   gst_structure_set (structure, "channels", G_TYPE_INT, channels,
108       "rate", G_TYPE_INT, outrate, "width", G_TYPE_INT, width, NULL);
109   if (!fp)
110     gst_structure_set (structure, "depth", G_TYPE_INT, width, NULL);
111   fail_unless (gst_caps_is_fixed (caps));
112
113   mysinkpad = gst_check_setup_sink_pad (audioresample, &sinktemplate, caps);
114   /* this installs a getcaps func that will always return the caps we set
115    * later */
116   gst_pad_set_caps (mysinkpad, caps);
117   gst_pad_use_fixed_caps (mysinkpad);
118
119   gst_pad_set_active (mysinkpad, TRUE);
120   gst_pad_set_active (mysrcpad, TRUE);
121
122   gst_caps_unref (caps);
123
124   return audioresample;
125 }
126
127 static void
128 cleanup_audioresample (GstElement * audioresample)
129 {
130   GST_DEBUG ("cleanup_audioresample");
131
132   fail_unless (gst_element_set_state (audioresample,
133           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to NULL");
134
135   gst_pad_set_active (mysrcpad, FALSE);
136   gst_pad_set_active (mysinkpad, FALSE);
137   gst_check_teardown_src_pad (audioresample);
138   gst_check_teardown_sink_pad (audioresample);
139   gst_check_teardown_element (audioresample);
140   gst_check_drop_buffers ();
141 }
142
143 static void
144 fail_unless_perfect_stream (void)
145 {
146   guint64 timestamp = 0L, duration = 0L;
147   guint64 offset = 0L, offset_end = 0L;
148
149   GList *l;
150   GstBuffer *buffer;
151
152   for (l = buffers; l; l = l->next) {
153     buffer = GST_BUFFER (l->data);
154     ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
155     GST_DEBUG ("buffer timestamp %" G_GUINT64_FORMAT ", duration %"
156         G_GUINT64_FORMAT " offset %" G_GUINT64_FORMAT " offset_end %"
157         G_GUINT64_FORMAT,
158         GST_BUFFER_TIMESTAMP (buffer),
159         GST_BUFFER_DURATION (buffer),
160         GST_BUFFER_OFFSET (buffer), GST_BUFFER_OFFSET_END (buffer));
161
162     fail_unless_equals_uint64 (timestamp, GST_BUFFER_TIMESTAMP (buffer));
163     fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET (buffer));
164     duration = GST_BUFFER_DURATION (buffer);
165     offset_end = GST_BUFFER_OFFSET_END (buffer);
166
167     timestamp += duration;
168     offset = offset_end;
169     gst_buffer_unref (buffer);
170   }
171   g_list_free (buffers);
172   buffers = NULL;
173 }
174
175 /* this tests that the output is a perfect stream if the input is */
176 static void
177 test_perfect_stream_instance (int inrate, int outrate, int samples,
178     int numbuffers)
179 {
180   GstElement *audioresample;
181   GstBuffer *inbuffer, *outbuffer;
182   GstCaps *caps;
183   guint64 offset = 0;
184
185   int i, j;
186   gint16 *p;
187
188   audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE);
189   caps = gst_pad_get_negotiated_caps (mysrcpad);
190   fail_unless (gst_caps_is_fixed (caps));
191
192   fail_unless (gst_element_set_state (audioresample,
193           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
194       "could not set to playing");
195
196   for (j = 1; j <= numbuffers; ++j) {
197
198     inbuffer = gst_buffer_new_and_alloc (samples * 4);
199     GST_BUFFER_DURATION (inbuffer) = GST_FRAMES_TO_CLOCK_TIME (samples, inrate);
200     GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_DURATION (inbuffer) * (j - 1);
201     GST_BUFFER_OFFSET (inbuffer) = offset;
202     offset += samples;
203     GST_BUFFER_OFFSET_END (inbuffer) = offset;
204
205     gst_buffer_set_caps (inbuffer, caps);
206
207     p = (gint16 *) GST_BUFFER_DATA (inbuffer);
208
209     /* create a 16 bit signed ramp */
210     for (i = 0; i < samples; ++i) {
211       *p = -32767 + i * (65535 / samples);
212       ++p;
213       *p = -32767 + i * (65535 / samples);
214       ++p;
215     }
216
217     /* pushing gives away my reference ... */
218     fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
219     /* ... but it ends up being collected on the global buffer list */
220     fail_unless_equals_int (g_list_length (buffers), j);
221   }
222
223   /* FIXME: we should make audioresample handle eos by flushing out the last
224    * samples, which will give us one more, small, buffer */
225   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
226   ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
227
228   fail_unless_perfect_stream ();
229
230   /* cleanup */
231   gst_caps_unref (caps);
232   cleanup_audioresample (audioresample);
233 }
234
235
236 /* make sure that outgoing buffers are contiguous in timestamp/duration and
237  * offset/offsetend
238  */
239 GST_START_TEST (test_perfect_stream)
240 {
241   /* integral scalings */
242   test_perfect_stream_instance (48000, 24000, 500, 20);
243   test_perfect_stream_instance (48000, 12000, 500, 20);
244   test_perfect_stream_instance (12000, 24000, 500, 20);
245   test_perfect_stream_instance (12000, 48000, 500, 20);
246
247   /* non-integral scalings */
248   test_perfect_stream_instance (44100, 8000, 500, 20);
249   test_perfect_stream_instance (8000, 44100, 500, 20);
250
251   /* wacky scalings */
252   test_perfect_stream_instance (12345, 54321, 500, 20);
253   test_perfect_stream_instance (101, 99, 500, 20);
254 }
255
256 GST_END_TEST;
257
258 /* this tests that the output is a correct discontinuous stream
259  * if the input is; ie input drops in time come out the same way */
260 static void
261 test_discont_stream_instance (int inrate, int outrate, int samples,
262     int numbuffers)
263 {
264   GstElement *audioresample;
265   GstBuffer *inbuffer, *outbuffer;
266   GstCaps *caps;
267   GstClockTime ints;
268
269   int i, j;
270   gint16 *p;
271
272   GST_DEBUG ("inrate:%d outrate:%d samples:%d numbuffers:%d",
273       inrate, outrate, samples, numbuffers);
274
275   audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE);
276   caps = gst_pad_get_negotiated_caps (mysrcpad);
277   fail_unless (gst_caps_is_fixed (caps));
278
279   fail_unless (gst_element_set_state (audioresample,
280           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
281       "could not set to playing");
282
283   for (j = 1; j <= numbuffers; ++j) {
284
285     inbuffer = gst_buffer_new_and_alloc (samples * 4);
286     GST_BUFFER_DURATION (inbuffer) = samples * GST_SECOND / inrate;
287     /* "drop" half the buffers */
288     ints = GST_BUFFER_DURATION (inbuffer) * 2 * (j - 1);
289     GST_BUFFER_TIMESTAMP (inbuffer) = ints;
290     GST_BUFFER_OFFSET (inbuffer) = (j - 1) * 2 * samples;
291     GST_BUFFER_OFFSET_END (inbuffer) = j * 2 * samples + samples;
292
293     gst_buffer_set_caps (inbuffer, caps);
294
295     p = (gint16 *) GST_BUFFER_DATA (inbuffer);
296
297     /* create a 16 bit signed ramp */
298     for (i = 0; i < samples; ++i) {
299       *p = -32767 + i * (65535 / samples);
300       ++p;
301       *p = -32767 + i * (65535 / samples);
302       ++p;
303     }
304
305     GST_DEBUG ("Sending Buffer time:%" G_GUINT64_FORMAT " duration:%"
306         G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%"
307         G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (inbuffer),
308         GST_BUFFER_DURATION (inbuffer), GST_BUFFER_IS_DISCONT (inbuffer),
309         GST_BUFFER_OFFSET (inbuffer), GST_BUFFER_OFFSET_END (inbuffer));
310     /* pushing gives away my reference ... */
311     fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
312
313     /* check if the timestamp of the pushed buffer matches the incoming one */
314     outbuffer = g_list_nth_data (buffers, g_list_length (buffers) - 1);
315     fail_if (outbuffer == NULL);
316     fail_unless_equals_uint64 (ints, GST_BUFFER_TIMESTAMP (outbuffer));
317     GST_DEBUG ("Got Buffer time:%" G_GUINT64_FORMAT " duration:%"
318         G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%"
319         G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (outbuffer),
320         GST_BUFFER_DURATION (outbuffer), GST_BUFFER_IS_DISCONT (outbuffer),
321         GST_BUFFER_OFFSET (outbuffer), GST_BUFFER_OFFSET_END (outbuffer));
322     if (j > 1) {
323       fail_unless (GST_BUFFER_IS_DISCONT (outbuffer),
324           "expected discont for buffer #%d", j);
325     }
326   }
327
328   /* cleanup */
329   gst_caps_unref (caps);
330   cleanup_audioresample (audioresample);
331 }
332
333 GST_START_TEST (test_discont_stream)
334 {
335   /* integral scalings */
336   test_discont_stream_instance (48000, 24000, 5000, 20);
337   test_discont_stream_instance (48000, 12000, 5000, 20);
338   test_discont_stream_instance (12000, 24000, 5000, 20);
339   test_discont_stream_instance (12000, 48000, 5000, 20);
340
341   /* non-integral scalings */
342   test_discont_stream_instance (44100, 8000, 5000, 20);
343   test_discont_stream_instance (8000, 44100, 5000, 20);
344
345   /* wacky scalings */
346   test_discont_stream_instance (12345, 54321, 5000, 20);
347   test_discont_stream_instance (101, 99, 5000, 20);
348 }
349
350 GST_END_TEST;
351
352
353
354 GST_START_TEST (test_reuse)
355 {
356   GstElement *audioresample;
357   GstEvent *newseg;
358   GstBuffer *inbuffer;
359   GstCaps *caps;
360
361   audioresample = setup_audioresample (1, 9343, 48000, 16, FALSE);
362   caps = gst_pad_get_negotiated_caps (mysrcpad);
363   fail_unless (gst_caps_is_fixed (caps));
364
365   fail_unless (gst_element_set_state (audioresample,
366           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
367       "could not set to playing");
368
369   newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
370   fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
371
372   inbuffer = gst_buffer_new_and_alloc (9343 * 4);
373   memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
374   GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
375   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
376   GST_BUFFER_OFFSET (inbuffer) = 0;
377   gst_buffer_set_caps (inbuffer, caps);
378
379   /* pushing gives away my reference ... */
380   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
381
382   /* ... but it ends up being collected on the global buffer list */
383   fail_unless_equals_int (g_list_length (buffers), 1);
384
385   /* now reset and try again ... */
386   fail_unless (gst_element_set_state (audioresample,
387           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to NULL");
388
389   fail_unless (gst_element_set_state (audioresample,
390           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
391       "could not set to playing");
392
393   newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
394   fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
395
396   inbuffer = gst_buffer_new_and_alloc (9343 * 4);
397   memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
398   GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
399   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
400   GST_BUFFER_OFFSET (inbuffer) = 0;
401   gst_buffer_set_caps (inbuffer, caps);
402
403   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
404
405   /* ... it also ends up being collected on the global buffer list. If we
406    * now have more than 2 buffers, then audioresample probably didn't clean
407    * up its internal buffer properly and tried to push the remaining samples
408    * when it got the second NEWSEGMENT event */
409   fail_unless_equals_int (g_list_length (buffers), 2);
410
411   cleanup_audioresample (audioresample);
412   gst_caps_unref (caps);
413 }
414
415 GST_END_TEST;
416
417 GST_START_TEST (test_shutdown)
418 {
419   GstElement *pipeline, *src, *cf1, *ar, *cf2, *sink;
420   GstCaps *caps;
421   guint i;
422
423   /* create pipeline, force audioresample to actually resample */
424   pipeline = gst_pipeline_new (NULL);
425
426   src = gst_check_setup_element ("audiotestsrc");
427   cf1 = gst_check_setup_element ("capsfilter");
428   ar = gst_check_setup_element ("audioresample");
429   cf2 = gst_check_setup_element ("capsfilter");
430   g_object_set (cf2, "name", "capsfilter2", NULL);
431   sink = gst_check_setup_element ("fakesink");
432
433   caps =
434       gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 11025, NULL);
435   g_object_set (cf1, "caps", caps, NULL);
436   gst_caps_unref (caps);
437
438   caps =
439       gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 48000, NULL);
440   g_object_set (cf2, "caps", caps, NULL);
441   gst_caps_unref (caps);
442
443   /* don't want to sync against the clock, the more throughput the better */
444   g_object_set (src, "is-live", FALSE, NULL);
445   g_object_set (sink, "sync", FALSE, NULL);
446
447   gst_bin_add_many (GST_BIN (pipeline), src, cf1, ar, cf2, sink, NULL);
448   fail_if (!gst_element_link_many (src, cf1, ar, cf2, sink, NULL));
449
450   /* now, wait until pipeline is running and then shut it down again; repeat */
451   for (i = 0; i < 20; ++i) {
452     gst_element_set_state (pipeline, GST_STATE_PAUSED);
453     gst_element_get_state (pipeline, NULL, NULL, -1);
454     gst_element_set_state (pipeline, GST_STATE_PLAYING);
455     g_usleep (100);
456     gst_element_set_state (pipeline, GST_STATE_NULL);
457   }
458
459   gst_object_unref (pipeline);
460 }
461
462 GST_END_TEST;
463
464 static GstFlowReturn
465 live_switch_alloc_only_48000 (GstPad * pad, guint64 offset,
466     guint size, GstCaps * caps, GstBuffer ** buf)
467 {
468   GstStructure *structure;
469   gint rate;
470   gint channels;
471   GstCaps *desired;
472
473   structure = gst_caps_get_structure (caps, 0);
474   fail_unless (gst_structure_get_int (structure, "rate", &rate));
475   fail_unless (gst_structure_get_int (structure, "channels", &channels));
476
477   if (rate < 48000)
478     return GST_FLOW_NOT_NEGOTIATED;
479
480   desired = gst_caps_copy (caps);
481   gst_caps_set_simple (desired, "rate", G_TYPE_INT, 48000, NULL);
482
483   *buf = gst_buffer_new_and_alloc (channels * 48000);
484   gst_buffer_set_caps (*buf, desired);
485   gst_caps_unref (desired);
486
487   return GST_FLOW_OK;
488 }
489
490 static GstCaps *
491 live_switch_get_sink_caps (GstPad * pad)
492 {
493   GstCaps *result;
494
495   result = gst_caps_copy (GST_PAD_CAPS (pad));
496
497   gst_caps_set_simple (result,
498       "rate", GST_TYPE_INT_RANGE, 48000, G_MAXINT, NULL);
499
500   return result;
501 }
502
503 static void
504 live_switch_push (int rate, GstCaps * caps)
505 {
506   GstBuffer *inbuffer;
507   GstCaps *desired;
508   GList *l;
509
510   desired = gst_caps_copy (caps);
511   gst_caps_set_simple (desired, "rate", G_TYPE_INT, rate, NULL);
512   gst_pad_set_caps (mysrcpad, desired);
513
514   fail_unless (gst_pad_alloc_buffer_and_set_caps (mysrcpad,
515           GST_BUFFER_OFFSET_NONE, rate * 4, desired, &inbuffer) == GST_FLOW_OK);
516
517   /* When the basetransform hits the non-configured case it always
518    * returns a buffer with exactly the same caps as we requested so the actual
519    * renegotiation (if needed) will be done in the _chain*/
520   fail_unless (inbuffer != NULL);
521   GST_DEBUG ("desired: %" GST_PTR_FORMAT ".... got: %" GST_PTR_FORMAT,
522       desired, GST_BUFFER_CAPS (inbuffer));
523   fail_unless (gst_caps_is_equal (desired, GST_BUFFER_CAPS (inbuffer)));
524
525   memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
526   GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
527   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
528   GST_BUFFER_OFFSET (inbuffer) = 0;
529
530   /* pushing gives away my reference ... */
531   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
532
533   /* ... but it ends up being collected on the global buffer list */
534   fail_unless_equals_int (g_list_length (buffers), 1);
535
536   for (l = buffers; l; l = l->next) {
537     GstBuffer *buffer = GST_BUFFER (l->data);
538
539     gst_buffer_unref (buffer);
540   }
541
542   g_list_free (buffers);
543   buffers = NULL;
544
545   gst_caps_unref (desired);
546 }
547
548 GST_START_TEST (test_live_switch)
549 {
550   GstElement *audioresample;
551   GstEvent *newseg;
552   GstCaps *caps;
553
554   audioresample = setup_audioresample (4, 48000, 48000, 16, FALSE);
555
556   /* Let the sinkpad act like something that can only handle things of
557    * rate 48000- and can only allocate buffers for that rate, but if someone
558    * tries to get a buffer with a rate higher then 48000 tries to renegotiate
559    * */
560   gst_pad_set_bufferalloc_function (mysinkpad, live_switch_alloc_only_48000);
561   gst_pad_set_getcaps_function (mysinkpad, live_switch_get_sink_caps);
562
563   gst_pad_use_fixed_caps (mysrcpad);
564
565   caps = gst_pad_get_negotiated_caps (mysrcpad);
566   fail_unless (gst_caps_is_fixed (caps));
567
568   fail_unless (gst_element_set_state (audioresample,
569           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
570       "could not set to playing");
571
572   newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
573   fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
574
575   /* downstream can provide the requested rate, a buffer alloc will be passed
576    * on */
577   live_switch_push (48000, caps);
578
579   /* Downstream can never accept this rate, buffer alloc isn't passed on */
580   live_switch_push (40000, caps);
581
582   /* Downstream can provide the requested rate but will re-negotiate */
583   live_switch_push (50000, caps);
584
585   cleanup_audioresample (audioresample);
586   gst_caps_unref (caps);
587 }
588
589 GST_END_TEST;
590
591 #ifndef GST_DISABLE_PARSE
592
593 static GMainLoop *loop;
594 static gint messages = 0;
595
596 static void
597 element_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
598 {
599   gchar *s;
600
601   s = gst_structure_to_string (gst_message_get_structure (message));
602   GST_DEBUG ("Received message: %s", s);
603   g_free (s);
604
605   messages++;
606 }
607
608 static void
609 eos_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
610 {
611   GST_DEBUG ("Received eos");
612   g_main_loop_quit (loop);
613 }
614
615 static void
616 test_pipeline (gint width, gboolean fp, gint inrate, gint outrate, gint quality)
617 {
618   GstElement *pipeline;
619   GstBus *bus;
620   GError *error = NULL;
621   gchar *pipe_str;
622
623   pipe_str =
624       g_strdup_printf
625       ("audiotestsrc num-buffers=10 ! audioconvert ! audio/x-raw-%s,rate=%d,width=%d,channels=2 ! audioresample quality=%d ! audio/x-raw-%s,rate=%d,width=%d ! identity check-imperfect-timestamp=TRUE ! fakesink",
626       (fp) ? "float" : "int", inrate, width, quality, (fp) ? "float" : "int",
627       outrate, width);
628
629   pipeline = gst_parse_launch (pipe_str, &error);
630   fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
631       error ? error->message : "(invalid error)");
632   g_free (pipe_str);
633
634   bus = gst_element_get_bus (pipeline);
635   fail_if (bus == NULL);
636   gst_bus_add_signal_watch (bus);
637   g_signal_connect (bus, "message::element", (GCallback) element_message_cb,
638       NULL);
639   g_signal_connect (bus, "message::eos", (GCallback) eos_message_cb, NULL);
640
641   gst_element_set_state (pipeline, GST_STATE_PLAYING);
642
643   /* run until we receive EOS */
644   loop = g_main_loop_new (NULL, FALSE);
645
646   g_main_loop_run (loop);
647
648   g_main_loop_unref (loop);
649   loop = NULL;
650
651   gst_element_set_state (pipeline, GST_STATE_NULL);
652
653   fail_if (messages > 0, "Received imperfect timestamp messages");
654   gst_object_unref (pipeline);
655 }
656
657 GST_START_TEST (test_pipelines)
658 {
659   gint quality;
660
661   /* Test qualities 0, 5 and 10 */
662   for (quality = 0; quality < 11; quality += 5) {
663     GST_DEBUG ("Checking with quality %d", quality);
664
665     test_pipeline (8, FALSE, 44100, 48000, quality);
666     test_pipeline (8, FALSE, 48000, 44100, quality);
667
668     test_pipeline (16, FALSE, 44100, 48000, quality);
669     test_pipeline (16, FALSE, 48000, 44100, quality);
670
671     test_pipeline (24, FALSE, 44100, 48000, quality);
672     test_pipeline (24, FALSE, 48000, 44100, quality);
673
674     test_pipeline (32, FALSE, 44100, 48000, quality);
675     test_pipeline (32, FALSE, 48000, 44100, quality);
676
677     test_pipeline (32, TRUE, 44100, 48000, quality);
678     test_pipeline (32, TRUE, 48000, 44100, quality);
679
680     test_pipeline (64, TRUE, 44100, 48000, quality);
681     test_pipeline (64, TRUE, 48000, 44100, quality);
682   }
683 }
684
685 GST_END_TEST;
686
687 GST_START_TEST (test_preference_passthrough)
688 {
689   GstStateChangeReturn ret;
690   GstElement *pipeline, *src;
691   GstStructure *s;
692   GstMessage *msg;
693   GstCaps *caps;
694   GstPad *pad;
695   GstBus *bus;
696   GError *error = NULL;
697   gint rate = 0;
698
699   pipeline = gst_parse_launch ("audiotestsrc num-buffers=1 name=src ! "
700       "audioresample ! audio/x-raw-int,channels=1,width=16,depth=16,"
701       "endianness=BYTE_ORDER,signed=true,rate=8000 ! "
702       "fakesink can-activate-pull=false", &error);
703   fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
704       error ? error->message : "(invalid error)");
705
706   ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
707   fail_unless_equals_int (ret, GST_STATE_CHANGE_ASYNC);
708
709   /* run until we receive EOS */
710   bus = gst_element_get_bus (pipeline);
711   fail_if (bus == NULL);
712   msg = gst_bus_timed_pop_filtered (bus, -1, GST_MESSAGE_EOS);
713   gst_message_unref (msg);
714   gst_object_unref (bus);
715
716   src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
717   fail_unless (src != NULL);
718   pad = gst_element_get_static_pad (src, "src");
719   fail_unless (pad != NULL);
720   caps = gst_pad_get_negotiated_caps (pad);
721   GST_LOG ("negotiated audiotestsrc caps: %" GST_PTR_FORMAT, caps);
722   fail_unless (caps != NULL);
723   s = gst_caps_get_structure (caps, 0);
724   fail_unless (gst_structure_get_int (s, "rate", &rate));
725   /* there's no need to resample, audiotestsrc supports any rate, so make
726    * sure audioresample provided upstream with the right caps to negotiate
727    * this correctly */
728   fail_unless_equals_int (rate, 8000);
729   gst_caps_unref (caps);
730   gst_object_unref (pad);
731   gst_object_unref (src);
732
733   gst_element_set_state (pipeline, GST_STATE_NULL);
734   gst_object_unref (pipeline);
735 }
736
737 GST_END_TEST;
738
739 #endif
740
741 static void
742 _message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
743 {
744   GMainLoop *loop = user_data;
745
746   switch (GST_MESSAGE_TYPE (message)) {
747     case GST_MESSAGE_ERROR:
748     case GST_MESSAGE_WARNING:
749       g_assert_not_reached ();
750       break;
751     case GST_MESSAGE_EOS:
752       g_main_loop_quit (loop);
753       break;
754     default:
755       break;
756   }
757 }
758
759 typedef struct
760 {
761   guint64 latency;
762   GstClockTime in_ts;
763
764   GstClockTime next_out_ts;
765   guint64 next_out_off;
766
767   guint64 in_buffer_count, out_buffer_count;
768 } TimestampDriftCtx;
769
770 static void
771 fakesink_handoff_cb (GstElement * object, GstBuffer * buffer, GstPad * pad,
772     gpointer user_data)
773 {
774   TimestampDriftCtx *ctx = user_data;
775
776   ctx->out_buffer_count++;
777   if (ctx->latency == GST_CLOCK_TIME_NONE) {
778     ctx->latency = 1000 - GST_BUFFER_SIZE (buffer) / 8;
779   }
780
781   /* Check if we have a perfectly timestamped stream */
782   if (ctx->next_out_ts != GST_CLOCK_TIME_NONE)
783     fail_unless (ctx->next_out_ts == GST_BUFFER_TIMESTAMP (buffer),
784         "expected timestamp %" GST_TIME_FORMAT " got timestamp %"
785         GST_TIME_FORMAT, GST_TIME_ARGS (ctx->next_out_ts),
786         GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
787
788   /* Check if we have a perfectly offsetted stream */
789   fail_unless (GST_BUFFER_OFFSET_END (buffer) ==
790       GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer) / 8,
791       "expected offset end %" G_GUINT64_FORMAT " got offset end %"
792       G_GUINT64_FORMAT,
793       GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer) / 8,
794       GST_BUFFER_OFFSET_END (buffer));
795   if (ctx->next_out_off != GST_BUFFER_OFFSET_NONE) {
796     fail_unless (GST_BUFFER_OFFSET (buffer) == ctx->next_out_off,
797         "expected offset %" G_GUINT64_FORMAT " got offset %" G_GUINT64_FORMAT,
798         ctx->next_out_off, GST_BUFFER_OFFSET (buffer));
799   }
800
801   if (ctx->in_buffer_count != ctx->out_buffer_count) {
802     GST_INFO ("timestamp %" GST_TIME_FORMAT,
803         GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
804   }
805
806   if (ctx->in_ts != GST_CLOCK_TIME_NONE && ctx->in_buffer_count > 1
807       && ctx->in_buffer_count == ctx->out_buffer_count) {
808     fail_unless (GST_BUFFER_TIMESTAMP (buffer) ==
809         ctx->in_ts - gst_util_uint64_scale_round (ctx->latency, GST_SECOND,
810             4096),
811         "expected output timestamp %" GST_TIME_FORMAT " (%" G_GUINT64_FORMAT
812         ") got output timestamp %" GST_TIME_FORMAT " (%" G_GUINT64_FORMAT ")",
813         GST_TIME_ARGS (ctx->in_ts - gst_util_uint64_scale_round (ctx->latency,
814                 GST_SECOND, 4096)),
815         ctx->in_ts - gst_util_uint64_scale_round (ctx->latency, GST_SECOND,
816             4096), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
817         GST_BUFFER_TIMESTAMP (buffer));
818   }
819
820   ctx->next_out_ts =
821       GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
822   ctx->next_out_off = GST_BUFFER_OFFSET_END (buffer);
823 }
824
825 static void
826 identity_handoff_cb (GstElement * object, GstBuffer * buffer,
827     gpointer user_data)
828 {
829   TimestampDriftCtx *ctx = user_data;
830
831   ctx->in_ts = GST_BUFFER_TIMESTAMP (buffer);
832   ctx->in_buffer_count++;
833 }
834
835 GST_START_TEST (test_timestamp_drift)
836 {
837   TimestampDriftCtx ctx =
838       { GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE,
839     GST_BUFFER_OFFSET_NONE, 0, 0
840   };
841   GstElement *pipeline;
842   GstElement *audiotestsrc, *capsfilter1, *identity, *audioresample,
843       *capsfilter2, *fakesink;
844   GstBus *bus;
845   GMainLoop *loop;
846   GstCaps *caps;
847
848   pipeline = gst_pipeline_new ("pipeline");
849   fail_unless (pipeline != NULL);
850
851   audiotestsrc = gst_element_factory_make ("audiotestsrc", "src");
852   fail_unless (audiotestsrc != NULL);
853   g_object_set (G_OBJECT (audiotestsrc), "num-buffers", 10000,
854       "samplesperbuffer", 4000, NULL);
855
856   capsfilter1 = gst_element_factory_make ("capsfilter", "capsfilter1");
857   fail_unless (capsfilter1 != NULL);
858   caps =
859       gst_caps_from_string
860       ("audio/x-raw-float, channels=1, width=64, rate=16384");
861   g_object_set (G_OBJECT (capsfilter1), "caps", caps, NULL);
862   gst_caps_unref (caps);
863
864   identity = gst_element_factory_make ("identity", "identity");
865   fail_unless (identity != NULL);
866   g_object_set (G_OBJECT (identity), "sync", FALSE, "signal-handoffs", TRUE,
867       NULL);
868   g_signal_connect (identity, "handoff", (GCallback) identity_handoff_cb, &ctx);
869
870   audioresample = gst_element_factory_make ("audioresample", "resample");
871   fail_unless (audioresample != NULL);
872   capsfilter2 = gst_element_factory_make ("capsfilter", "capsfilter2");
873   fail_unless (capsfilter2 != NULL);
874   caps =
875       gst_caps_from_string
876       ("audio/x-raw-float, channels=1, width=64, rate=4096");
877   g_object_set (G_OBJECT (capsfilter2), "caps", caps, NULL);
878   gst_caps_unref (caps);
879
880   fakesink = gst_element_factory_make ("fakesink", "sink");
881   fail_unless (fakesink != NULL);
882   g_object_set (G_OBJECT (fakesink), "sync", FALSE, "async", FALSE,
883       "signal-handoffs", TRUE, NULL);
884   g_signal_connect (fakesink, "handoff", (GCallback) fakesink_handoff_cb, &ctx);
885
886
887   gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, capsfilter1, identity,
888       audioresample, capsfilter2, fakesink, NULL);
889   fail_unless (gst_element_link_many (audiotestsrc, capsfilter1, identity,
890           audioresample, capsfilter2, fakesink, NULL));
891
892   loop = g_main_loop_new (NULL, FALSE);
893
894   bus = gst_element_get_bus (pipeline);
895   gst_bus_add_signal_watch (bus);
896   g_signal_connect (bus, "message", (GCallback) _message_cb, loop);
897
898   fail_unless (gst_element_set_state (pipeline,
899           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
900   g_main_loop_run (loop);
901
902   fail_unless (gst_element_set_state (pipeline,
903           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
904   g_main_loop_unref (loop);
905   gst_object_unref (pipeline);
906
907 } GST_END_TEST;
908
909 #define FFT_HELPERS(type,ffttag,ffttag2,scale);                                                 \
910 static gdouble magnitude##ffttag (const GstFFT##ffttag##Complex *c)                             \
911 {                                                                                               \
912   gdouble mag = (gdouble) c->r * (gdouble) c->r;                                                \
913   mag += (gdouble) c->i * (gdouble) c->i;                                                       \
914   mag /= scale * scale;                                                                         \
915   mag = 10.0 * log10 (mag);                                                                     \
916   return mag;                                                                                   \
917 }                                                                                               \
918 static gdouble find_main_frequency_spot_##ffttag (const GstFFT##ffttag##Complex *v,             \
919                                                   int elements)                                 \
920 {                                                                                               \
921   int i;                                                                                        \
922   gdouble maxmag = -9999;                                                                       \
923   int maxidx = 0;                                                                               \
924   for (i=0; i<elements; ++i) {                                                                  \
925     gdouble mag = magnitude##ffttag (v+i);                                                      \
926     if (mag > maxmag) {                                                                         \
927       maxmag = mag;                                                                             \
928       maxidx = i;                                                                               \
929     }                                                                                           \
930   }                                                                                             \
931   return maxidx / (gdouble) elements;                                                           \
932 }                                                                                               \
933 static gboolean is_zero_except_##ffttag (const GstFFT##ffttag##Complex *v, int elements,        \
934                                 gdouble spot)                                                   \
935 {                                                                                               \
936   int i;                                                                                        \
937   for (i=0; i<elements; ++i) {                                                                  \
938     gdouble pos = i / (gdouble) elements;                                                       \
939     gdouble mag = magnitude##ffttag (v+i);                                                      \
940     if (fabs (pos - spot) > 0.01) {                                                             \
941       if (mag > -55.0) {                                                                        \
942         return FALSE;                                                                           \
943       }                                                                                         \
944     }                                                                                           \
945   }                                                                                             \
946   return TRUE;                                                                                  \
947 }                                                                                               \
948 static void compare_ffts_##ffttag (const GstBuffer *inbuffer, const GstBuffer *outbuffer)       \
949 {                                                                                               \
950   int insamples = GST_BUFFER_SIZE (inbuffer) / sizeof(type) & ~1;                               \
951   int outsamples = GST_BUFFER_SIZE (outbuffer) / sizeof(type) & ~1;                             \
952   gdouble inspot, outspot;                                                                      \
953                                                                                                 \
954   GstFFT##ffttag *inctx = gst_fft_##ffttag2##_new (insamples, FALSE);                           \
955   GstFFT##ffttag##Complex *in = g_new (GstFFT##ffttag##Complex, insamples / 2 + 1);             \
956   GstFFT##ffttag *outctx = gst_fft_##ffttag2##_new (outsamples, FALSE);                         \
957   GstFFT##ffttag##Complex *out = g_new (GstFFT##ffttag##Complex, outsamples / 2 + 1);           \
958                                                                                                 \
959   gst_fft_##ffttag2##_window (inctx, (type*)GST_BUFFER_DATA (inbuffer),                         \
960       GST_FFT_WINDOW_HAMMING);                                                                  \
961   gst_fft_##ffttag2##_fft (inctx, (type*)GST_BUFFER_DATA (inbuffer), in);                       \
962   gst_fft_##ffttag2##_window (outctx, (type*)GST_BUFFER_DATA (outbuffer),                       \
963       GST_FFT_WINDOW_HAMMING);                                                                  \
964   gst_fft_##ffttag2##_fft (outctx, (type*)GST_BUFFER_DATA (outbuffer), out);                    \
965                                                                                                 \
966   inspot = find_main_frequency_spot_##ffttag (in, insamples / 2 + 1);                           \
967   outspot = find_main_frequency_spot_##ffttag (out, outsamples / 2 + 1);                        \
968   GST_LOG ("Spots are %.3f and %.3f", inspot, outspot);                                         \
969   fail_unless (fabs (outspot - inspot) < 0.05);                                                 \
970   fail_unless (is_zero_except_##ffttag (in, insamples / 2 + 1, inspot));                        \
971   fail_unless (is_zero_except_##ffttag (out, outsamples / 2 + 1, outspot));                     \
972                                                                                                 \
973   gst_fft_##ffttag2##_free (inctx);                                                             \
974   gst_fft_##ffttag2##_free (outctx);                                                            \
975   g_free (in);                                                                                  \
976   g_free (out);                                                                                 \
977 }
978 FFT_HELPERS (float, F32, f32, 2048.0f);
979 FFT_HELPERS (double, F64, f64, 2048.0);
980 FFT_HELPERS (gint16, S16, s16, 32767.0);
981 FFT_HELPERS (gint32, S32, s32, 2147483647.0);
982
983 #define FILL_BUFFER(type, desc, value);                         \
984   static void init_##type##_##desc (GstBuffer *buffer)          \
985   {                                                             \
986     type *ptr = (type *) GST_BUFFER_DATA (buffer);              \
987     int i, nsamples = GST_BUFFER_SIZE (buffer) / sizeof (type); \
988     for (i = 0; i < nsamples; ++i) {                            \
989       *ptr++ = value;                                           \
990     }                                                           \
991   }
992
993 FILL_BUFFER (float, silence, 0.0f);
994 FILL_BUFFER (double, silence, 0.0);
995 FILL_BUFFER (gint16, silence, 0);
996 FILL_BUFFER (gint32, silence, 0);
997 FILL_BUFFER (float, sine, sinf (i * 0.01f));
998 FILL_BUFFER (float, sine2, sinf (i * 1.8f));
999 FILL_BUFFER (double, sine, sin (i * 0.01));
1000 FILL_BUFFER (double, sine2, sin (i * 1.8));
1001 FILL_BUFFER (gint16, sine, (gint16) (32767 * sinf (i * 0.01f)));
1002 FILL_BUFFER (gint16, sine2, (gint16) (32767 * sinf (i * 1.8f)));
1003 FILL_BUFFER (gint32, sine, (gint32) (2147483647 * sinf (i * 0.01f)));
1004 FILL_BUFFER (gint32, sine2, (gint32) (2147483647 * sinf (i * 1.8f)));
1005
1006 static void
1007 run_fft_pipeline (int inrate, int outrate, int quality, int width, gboolean fp,
1008     void (*init) (GstBuffer *),
1009     void (*compare_ffts) (const GstBuffer *, const GstBuffer *))
1010 {
1011   GstElement *audioresample;
1012   GstBuffer *inbuffer, *outbuffer;
1013   GstCaps *caps;
1014   const int nsamples = 2048;
1015
1016   audioresample = setup_audioresample (1, inrate, outrate, width, fp);
1017   fail_unless (audioresample != NULL);
1018   g_object_set (audioresample, "quality", quality, NULL);
1019   caps = gst_pad_get_negotiated_caps (mysrcpad);
1020   fail_unless (gst_caps_is_fixed (caps));
1021
1022   fail_unless (gst_element_set_state (audioresample,
1023           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1024       "could not set to playing");
1025
1026   inbuffer = gst_buffer_new_and_alloc (nsamples * width / 8);
1027   GST_BUFFER_DURATION (inbuffer) = GST_FRAMES_TO_CLOCK_TIME (nsamples, inrate);
1028   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
1029   gst_buffer_set_caps (inbuffer, caps);
1030   gst_buffer_ref (inbuffer);
1031
1032   (*init) (inbuffer);
1033
1034   /* pushing gives away my reference ... */
1035   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1036   /* ... but it ends up being collected on the global buffer list */
1037   fail_unless_equals_int (g_list_length (buffers), 1);
1038   /* retrieve out buffer */
1039   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1040
1041   fail_unless (gst_element_set_state (audioresample,
1042           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
1043
1044   (*compare_ffts) (inbuffer, outbuffer);
1045
1046   /* cleanup */
1047   gst_buffer_unref (inbuffer);
1048   gst_caps_unref (caps);
1049   cleanup_audioresample (audioresample);
1050 }
1051
1052 GST_START_TEST (test_fft)
1053 {
1054   int quality;
1055   size_t f0, f1;
1056   static const int frequencies[] =
1057       { 8000, 16000, 44100, 48000, 128000, 12345, 54321 };
1058
1059   /* audioresample uses a mixed float/double code path for floats with quality>8, make sure we test it */
1060   for (quality = 0; quality <= 10; quality += 5) {
1061     for (f0 = 0; f0 < G_N_ELEMENTS (frequencies); ++f0) {
1062       for (f1 = 0; f1 < G_N_ELEMENTS (frequencies); ++f1) {
1063         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, TRUE,
1064             &init_float_silence, &compare_ffts_F32);
1065         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, TRUE,
1066             &init_float_sine, &compare_ffts_F32);
1067         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, TRUE,
1068             &init_float_sine2, &compare_ffts_F32);
1069         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64, TRUE,
1070             &init_double_silence, &compare_ffts_F64);
1071         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64, TRUE,
1072             &init_double_sine, &compare_ffts_F64);
1073         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64, TRUE,
1074             &init_double_sine2, &compare_ffts_F64);
1075         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16, FALSE,
1076             &init_gint16_silence, &compare_ffts_S16);
1077         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16, FALSE,
1078             &init_gint16_sine, &compare_ffts_S16);
1079         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16, FALSE,
1080             &init_gint16_sine2, &compare_ffts_S16);
1081         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, FALSE,
1082             &init_gint32_silence, &compare_ffts_S32);
1083         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, FALSE,
1084             &init_gint32_sine, &compare_ffts_S32);
1085         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32, FALSE,
1086             &init_gint32_sine2, &compare_ffts_S32);
1087       }
1088     }
1089   }
1090 }
1091
1092 GST_END_TEST;
1093
1094 static Suite *
1095 audioresample_suite (void)
1096 {
1097   Suite *s = suite_create ("audioresample");
1098   TCase *tc_chain = tcase_create ("general");
1099
1100   suite_add_tcase (s, tc_chain);
1101   tcase_add_test (tc_chain, test_perfect_stream);
1102   tcase_add_test (tc_chain, test_discont_stream);
1103   tcase_add_test (tc_chain, test_reuse);
1104   tcase_add_test (tc_chain, test_shutdown);
1105   tcase_add_test (tc_chain, test_live_switch);
1106   tcase_add_test (tc_chain, test_timestamp_drift);
1107   tcase_add_test (tc_chain, test_fft);
1108
1109 #ifndef GST_DISABLE_PARSE
1110   tcase_set_timeout (tc_chain, 360);
1111   tcase_add_test (tc_chain, test_pipelines);
1112   tcase_add_test (tc_chain, test_preference_passthrough);
1113 #endif
1114
1115   return s;
1116 }
1117
1118 GST_CHECK_MAIN (audioresample);