Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / elements / rganalysis.c
1 /* GStreamer ReplayGain analysis
2  *
3  * Copyright (C) 2006 Rene Stadler <mail@renestadler.de>
4  *
5  * rganalysis.c: Unit test for the rganalysis 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 /* Some things to note about the RMS window length of the analysis algorithm and
24  * thus the implementation used in the element: Processing divides input data
25  * into 50ms windows at some point.  Some details about this that normally do
26  * not matter:
27  *
28  *  1. At the end of a stream, the remainder of data that did not fill up the
29  *     last 50ms window is simply discarded.
30  *
31  *  2. If the sample rate changes during a stream, the currently running window
32  *     is discarded and the equal loudness filter gets reset as if a new stream
33  *     started.
34  *
35  *  3. For the album gain, it is not entirely correct to think of obtaining it
36  *     like "as if all the tracks are analyzed as one track".  There isn't a
37  *     separate window being tracked for album processing, so at stream (track)
38  *     end, the remaining unfilled window does not contribute to the album gain
39  *     either.
40  *
41  *  4. If a waveform with a result gain G is concatenated to itself and the
42  *     result processed as a track, the gain can be different from G if and only
43  *     if the duration of the original waveform is not an integer multiple of
44  *     50ms.  If the original waveform gets processed as a single track and then
45  *     the same data again as a subsequent track, the album result gain will
46  *     always match G (this is implied by 3.).
47  *
48  *  5. A stream shorter than 50ms cannot be analyzed.  At 8000 and 48000 Hz,
49  *     this corresponds to 400 resp. 2400 frames.  If a stream is shorter than
50  *     50ms, the element will not generate tags at EOS (only if an album
51  *     finished, but only album tags are generated then).  This is not an
52  *     erroneous condition, the element should behave normally.
53  *
54  * The limitations outlined in 1.-4. do not apply to the peak values.  Every
55  * single sample is accounted for when looking for the peak.  Thus the album
56  * peak is guaranteed to be the maximum value of all track peaks.
57  *
58  * In normal day-to-day use, these little facts are unlikely to be relevant, but
59  * they have to be kept in mind for writing the tests here.
60  */
61
62 #include <gst/check/gstcheck.h>
63
64 /* For ease of programming we use globals to keep refs for our floating src and
65  * sink pads we create; otherwise we always have to do get_pad, get_peer, and
66  * then remove references in every test function */
67 static GstPad *mysrcpad, *mysinkpad;
68
69 /* Mapping from supported sample rates to the correct result gain for the
70  * following test waveform: 20 * 512 samples with a quarter-full amplitude of
71  * toggling sign, changing every 48 samples and starting with the positive
72  * value.
73  *
74  * Even if we would generate a wave describing a signal with the same frequency
75  * at each sampling rate, the results would vary (slightly).  Hence the simple
76  * generation method, since we cannot use a constant value as expected result
77  * anyways.  For all sample rates, changing the sign every 48 frames gives a
78  * sane frequency.  Buffers containing data that forms such a waveform is
79  * created using the test_buffer_square_{float,int16}_{mono,stereo} functions
80  * below.
81  *
82  * The results have been checked against what the metaflac and wavegain programs
83  * generate for such a stream.  If you want to verify these, be sure that the
84  * metaflac program does not produce incorrect results in your environment: I
85  * found a strange bug in the (defacto) reference code for the analysis that
86  * sometimes leads to incorrect RMS window lengths. */
87
88 struct rate_test
89 {
90   guint sample_rate;
91   gdouble gain;
92 };
93
94 static const struct rate_test supported_rates[] = {
95   {8000, -0.91},
96   {11025, -2.80},
97   {12000, -3.13},
98   {16000, -4.26},
99   {22050, -5.64},
100   {24000, -5.87},
101   {32000, -6.03},
102   {44100, -6.20},
103   {48000, -6.14}
104 };
105
106 /* Lookup the correct gain adjustment result in above array. */
107
108 static gdouble
109 get_expected_gain (guint sample_rate)
110 {
111   gint i;
112
113   for (i = G_N_ELEMENTS (supported_rates); i--;)
114     if (supported_rates[i].sample_rate == sample_rate)
115       return supported_rates[i].gain;
116   g_return_val_if_reached (0.0);
117 }
118
119 #define SILENCE_GAIN 64.82
120
121 #define REPLAY_GAIN_CAPS                                \
122   "channels = (int) { 1, 2 }, "                         \
123   "rate = (int) { 8000, 11025, 12000, 16000, 22050, "   \
124   "24000, 32000, 44100, 48000 }"
125
126 #define RG_ANALYSIS_CAPS_TEMPLATE_STRING  \
127   "audio/x-raw-float, "                   \
128   "width = (int) 32, "                    \
129   "endianness = (int) BYTE_ORDER, "       \
130   REPLAY_GAIN_CAPS                        \
131   "; "                                    \
132   "audio/x-raw-int, "                     \
133   "width = (int) 16, "                    \
134   "depth = (int) [ 1, 16 ], "             \
135   "signed = (boolean) true, "             \
136   "endianness = (int) BYTE_ORDER, "       \
137   REPLAY_GAIN_CAPS
138
139 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
140     GST_PAD_SINK,
141     GST_PAD_ALWAYS,
142     GST_STATIC_CAPS (RG_ANALYSIS_CAPS_TEMPLATE_STRING)
143     );
144 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
145     GST_PAD_SRC,
146     GST_PAD_ALWAYS,
147     GST_STATIC_CAPS (RG_ANALYSIS_CAPS_TEMPLATE_STRING)
148     );
149
150 static GstElement *
151 setup_rganalysis (void)
152 {
153   GstElement *analysis;
154   GstBus *bus;
155
156   GST_DEBUG ("setup_rganalysis");
157   analysis = gst_check_setup_element ("rganalysis");
158   mysrcpad = gst_check_setup_src_pad (analysis, &srctemplate, NULL);
159   mysinkpad = gst_check_setup_sink_pad (analysis, &sinktemplate, NULL);
160   gst_pad_set_active (mysrcpad, TRUE);
161   gst_pad_set_active (mysinkpad, TRUE);
162
163   bus = gst_bus_new ();
164   gst_element_set_bus (analysis, bus);
165   /* gst_element_set_bus does not steal a reference. */
166   gst_object_unref (bus);
167
168   return analysis;
169 }
170
171 static void
172 cleanup_rganalysis (GstElement * element)
173 {
174   GST_DEBUG ("cleanup_rganalysis");
175
176   g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
177   g_list_free (buffers);
178   buffers = NULL;
179
180   /* The bus owns references to the element: */
181   gst_element_set_bus (element, NULL);
182
183   gst_pad_set_active (mysrcpad, FALSE);
184   gst_pad_set_active (mysinkpad, FALSE);
185   gst_check_teardown_src_pad (element);
186   gst_check_teardown_sink_pad (element);
187   gst_check_teardown_element (element);
188 }
189
190 static void
191 set_playing_state (GstElement * element)
192 {
193   fail_unless (gst_element_set_state (element,
194           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
195       "Could not set state to PLAYING");
196 }
197
198 static void
199 send_eos_event (GstElement * element)
200 {
201   GstBus *bus = gst_element_get_bus (element);
202   GstPad *pad = gst_element_get_static_pad (element, "sink");
203   GstEvent *event = gst_event_new_eos ();
204
205   fail_unless (gst_pad_send_event (pad, event),
206       "Cannot send EOS event: Not handled.");
207
208   /* There is no sink element, so _we_ post the EOS message on the bus here.  Of
209    * course we generate any EOS ourselves, but this allows us to poll for the
210    * EOS message in poll_eos if we expect the element to _not_ generate a TAG
211    * message.  That's better than waiting for a timeout to lapse. */
212   fail_unless (gst_bus_post (bus, gst_message_new_eos (NULL)));
213
214   gst_object_unref (bus);
215   gst_object_unref (pad);
216 }
217
218 static void
219 send_tag_event (GstElement * element, GstTagList * tag_list)
220 {
221   GstPad *pad = gst_element_get_static_pad (element, "sink");
222   GstEvent *event = gst_event_new_tag (tag_list);
223
224   fail_unless (gst_pad_send_event (pad, event),
225       "Cannot send TAG event: Not handled.");
226
227   gst_object_unref (pad);
228 }
229
230 static void
231 poll_eos (GstElement * element)
232 {
233   GstBus *bus = gst_element_get_bus (element);
234   GstMessage *message;
235
236   message = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_TAG, GST_SECOND);
237   fail_unless (message != NULL, "Could not poll for EOS message: Timed out");
238   fail_unless (message->type == GST_MESSAGE_EOS,
239       "Could not poll for eos message: got message of type %s instead",
240       gst_message_type_get_name (message->type));
241
242   gst_message_unref (message);
243   gst_object_unref (bus);
244 }
245
246 /* This also polls for EOS since the TAG message comes right before the end of
247  * streams. */
248
249 static GstTagList *
250 poll_tags (GstElement * element)
251 {
252   GstBus *bus = gst_element_get_bus (element);
253   GstTagList *tag_list;
254   GstMessage *message;
255
256   message = gst_bus_poll (bus, GST_MESSAGE_TAG, GST_SECOND);
257   fail_unless (message != NULL, "Could not poll for TAG message: Timed out");
258
259   gst_message_parse_tag (message, &tag_list);
260   gst_message_unref (message);
261   gst_object_unref (bus);
262
263   poll_eos (element);
264
265   return tag_list;
266 }
267
268 #define MATCH_PEAK(p1, p2) ((p1 < p2 + 1e-6) && (p2 < p1 + 1e-6))
269 #define MATCH_GAIN(g1, g2) ((g1 < g2 + 1e-13) && (g2 < g1 + 1e-13))
270
271 static void
272 fail_unless_track_gain (const GstTagList * tag_list, gdouble gain)
273 {
274   gdouble result;
275
276   fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_TRACK_GAIN, &result),
277       "Tag list contains no track gain value");
278   fail_unless (MATCH_GAIN (gain, result),
279       "Track gain %+.2f does not match, expected %+.2f", result, gain);
280 }
281
282 static void
283 fail_unless_track_peak (const GstTagList * tag_list, gdouble peak)
284 {
285   gdouble result;
286
287   fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_TRACK_PEAK, &result),
288       "Tag list contains no track peak value");
289   fail_unless (MATCH_PEAK (peak, result),
290       "Track peak %f does not match, expected %f", result, peak);
291 }
292
293 static void
294 fail_unless_album_gain (const GstTagList * tag_list, gdouble gain)
295 {
296   gdouble result;
297
298   fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_GAIN, &result),
299       "Tag list contains no album gain value");
300   fail_unless (MATCH_GAIN (result, gain),
301       "Album gain %+.2f does not match, expected %+.2f", result, gain);
302 }
303
304 static void
305 fail_unless_album_peak (const GstTagList * tag_list, gdouble peak)
306 {
307   gdouble result;
308
309   fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_PEAK, &result),
310       "Tag list contains no album peak value");
311   fail_unless (MATCH_PEAK (peak, result),
312       "Album peak %f does not match, expected %f", result, peak);
313 }
314
315 static void
316 fail_if_track_tags (const GstTagList * tag_list)
317 {
318   gdouble result;
319
320   fail_if (gst_tag_list_get_double (tag_list, GST_TAG_TRACK_GAIN, &result),
321       "Tag list contains track gain value (but should not)");
322   fail_if (gst_tag_list_get_double (tag_list, GST_TAG_TRACK_PEAK, &result),
323       "Tag list contains track peak value (but should not)");
324 }
325
326 static void
327 fail_if_album_tags (const GstTagList * tag_list)
328 {
329   gdouble result;
330
331   fail_if (gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_GAIN, &result),
332       "Tag list contains album gain value (but should not)");
333   fail_if (gst_tag_list_get_double (tag_list, GST_TAG_ALBUM_PEAK, &result),
334       "Tag list contains album peak value (but should not)");
335 }
336
337 static void
338 fail_unless_num_tracks (GstElement * element, guint num_tracks)
339 {
340   guint current;
341
342   g_object_get (element, "num-tracks", &current, NULL);
343   fail_unless (current == num_tracks,
344       "num-tracks property has incorrect value %u, expected %u",
345       current, num_tracks);
346 }
347
348 /* Functions that create buffers with constant sample values, for peak
349  * tests. */
350
351 static GstBuffer *
352 test_buffer_const_float_mono (gint sample_rate, gsize n_frames, gfloat value)
353 {
354   GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gfloat));
355   gfloat *data = (gfloat *) GST_BUFFER_DATA (buf);
356   GstCaps *caps;
357   gint i;
358
359   for (i = n_frames; i--;)
360     *data++ = value;
361
362   caps = gst_caps_new_simple ("audio/x-raw-float",
363       "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 1,
364       "endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
365   gst_buffer_set_caps (buf, caps);
366   gst_caps_unref (caps);
367
368   ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
369
370   return buf;
371 }
372
373 static GstBuffer *
374 test_buffer_const_float_stereo (gint sample_rate, gsize n_frames,
375     gfloat value_l, gfloat value_r)
376 {
377   GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gfloat) * 2);
378   gfloat *data = (gfloat *) GST_BUFFER_DATA (buf);
379   GstCaps *caps;
380   gint i;
381
382   for (i = n_frames; i--;) {
383     *data++ = value_l;
384     *data++ = value_r;
385   }
386
387   caps = gst_caps_new_simple ("audio/x-raw-float",
388       "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 2,
389       "endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
390   gst_buffer_set_caps (buf, caps);
391   gst_caps_unref (caps);
392
393   ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
394
395   return buf;
396 }
397
398 static GstBuffer *
399 test_buffer_const_int16_mono (gint sample_rate, gint depth, gsize n_frames,
400     gint16 value)
401 {
402   GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gint16));
403   gint16 *data = (gint16 *) GST_BUFFER_DATA (buf);
404   GstCaps *caps;
405   gint i;
406
407   for (i = n_frames; i--;)
408     *data++ = value;
409
410   caps = gst_caps_new_simple ("audio/x-raw-int",
411       "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 1,
412       "endianness", G_TYPE_INT, G_BYTE_ORDER, "signed", G_TYPE_BOOLEAN, TRUE,
413       "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, depth, NULL);
414   gst_buffer_set_caps (buf, caps);
415   gst_caps_unref (caps);
416
417   ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
418
419   return buf;
420 }
421
422 static GstBuffer *
423 test_buffer_const_int16_stereo (gint sample_rate, gint depth, gsize n_frames,
424     gint16 value_l, gint16 value_r)
425 {
426   GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gint16) * 2);
427   gint16 *data = (gint16 *) GST_BUFFER_DATA (buf);
428   GstCaps *caps;
429   gint i;
430
431   for (i = n_frames; i--;) {
432     *data++ = value_l;
433     *data++ = value_r;
434   }
435
436   caps = gst_caps_new_simple ("audio/x-raw-int",
437       "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 2,
438       "endianness", G_TYPE_INT, G_BYTE_ORDER, "signed", G_TYPE_BOOLEAN, TRUE,
439       "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, depth, NULL);
440   gst_buffer_set_caps (buf, caps);
441   gst_caps_unref (caps);
442
443   ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
444
445   return buf;
446 }
447
448 /* Functions that create data buffers containing square signal
449  * waveforms. */
450
451 static GstBuffer *
452 test_buffer_square_float_mono (gint * accumulator, gint sample_rate,
453     gsize n_frames, gfloat value)
454 {
455   GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gfloat));
456   gfloat *data = (gfloat *) GST_BUFFER_DATA (buf);
457   GstCaps *caps;
458   gint i;
459
460   for (i = n_frames; i--;) {
461     *accumulator += 1;
462     *accumulator %= 96;
463
464     if (*accumulator < 48)
465       *data++ = value;
466     else
467       *data++ = -value;
468   }
469
470   caps = gst_caps_new_simple ("audio/x-raw-float",
471       "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 1,
472       "endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
473   gst_buffer_set_caps (buf, caps);
474   gst_caps_unref (caps);
475
476   ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
477
478   return buf;
479 }
480
481 static GstBuffer *
482 test_buffer_square_float_stereo (gint * accumulator, gint sample_rate,
483     gsize n_frames, gfloat value_l, gfloat value_r)
484 {
485   GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gfloat) * 2);
486   gfloat *data = (gfloat *) GST_BUFFER_DATA (buf);
487   GstCaps *caps;
488   gint i;
489
490   for (i = n_frames; i--;) {
491     *accumulator += 1;
492     *accumulator %= 96;
493
494     if (*accumulator < 48) {
495       *data++ = value_l;
496       *data++ = value_r;
497     } else {
498       *data++ = -value_l;
499       *data++ = -value_r;
500     }
501   }
502
503   caps = gst_caps_new_simple ("audio/x-raw-float",
504       "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 2,
505       "endianness", G_TYPE_INT, G_BYTE_ORDER, "width", G_TYPE_INT, 32, NULL);
506   gst_buffer_set_caps (buf, caps);
507   gst_caps_unref (caps);
508
509   ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
510
511   return buf;
512 }
513
514 static GstBuffer *
515 test_buffer_square_int16_mono (gint * accumulator, gint sample_rate,
516     gint depth, gsize n_frames, gint16 value)
517 {
518   GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gint16));
519   gint16 *data = (gint16 *) GST_BUFFER_DATA (buf);
520   GstCaps *caps;
521   gint i;
522
523   for (i = n_frames; i--;) {
524     *accumulator += 1;
525     *accumulator %= 96;
526
527     if (*accumulator < 48)
528       *data++ = value;
529     else
530       *data++ = -MAX (value, -32767);
531   }
532
533   caps = gst_caps_new_simple ("audio/x-raw-int",
534       "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 1,
535       "endianness", G_TYPE_INT, G_BYTE_ORDER, "signed", G_TYPE_BOOLEAN, TRUE,
536       "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, depth, NULL);
537   gst_buffer_set_caps (buf, caps);
538   gst_caps_unref (caps);
539
540   ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
541
542   return buf;
543 }
544
545 static GstBuffer *
546 test_buffer_square_int16_stereo (gint * accumulator, gint sample_rate,
547     gint depth, gsize n_frames, gint16 value_l, gint16 value_r)
548 {
549   GstBuffer *buf = gst_buffer_new_and_alloc (n_frames * sizeof (gint16) * 2);
550   gint16 *data = (gint16 *) GST_BUFFER_DATA (buf);
551   GstCaps *caps;
552   gint i;
553
554   for (i = n_frames; i--;) {
555     *accumulator += 1;
556     *accumulator %= 96;
557
558     if (*accumulator < 48) {
559       *data++ = value_l;
560       *data++ = value_r;
561     } else {
562       *data++ = -MAX (value_l, -32767);
563       *data++ = -MAX (value_r, -32767);
564     }
565   }
566
567   caps = gst_caps_new_simple ("audio/x-raw-int",
568       "rate", G_TYPE_INT, sample_rate, "channels", G_TYPE_INT, 2,
569       "endianness", G_TYPE_INT, G_BYTE_ORDER, "signed", G_TYPE_BOOLEAN, TRUE,
570       "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, depth, NULL);
571   gst_buffer_set_caps (buf, caps);
572   gst_caps_unref (caps);
573
574   ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
575
576   return buf;
577 }
578
579 static void
580 push_buffer (GstBuffer * buf)
581 {
582   /* gst_pad_push steals a reference. */
583   fail_unless (gst_pad_push (mysrcpad, buf) == GST_FLOW_OK);
584   ASSERT_BUFFER_REFCOUNT (buf, "buf", 1);
585 }
586
587 /*** Start of the tests. ***/
588
589 /* This test looks redundant, but early versions of the element
590  * crashed when doing, well, nothing: */
591
592 GST_START_TEST (test_no_buffer)
593 {
594   GstElement *element = setup_rganalysis ();
595
596   set_playing_state (element);
597   send_eos_event (element);
598   poll_eos (element);
599
600   cleanup_rganalysis (element);
601 }
602
603 GST_END_TEST;
604
605 GST_START_TEST (test_no_buffer_album_1)
606 {
607   GstElement *element = setup_rganalysis ();
608
609   set_playing_state (element);
610
611   /* Single track: */
612   send_eos_event (element);
613   poll_eos (element);
614
615   /* First album: */
616   g_object_set (element, "num-tracks", 3, NULL);
617
618   send_eos_event (element);
619   poll_eos (element);
620   fail_unless_num_tracks (element, 2);
621
622   send_eos_event (element);
623   poll_eos (element);
624   fail_unless_num_tracks (element, 1);
625
626   send_eos_event (element);
627   poll_eos (element);
628   fail_unless_num_tracks (element, 0);
629
630   /* Second album: */
631   g_object_set (element, "num-tracks", 2, NULL);
632
633   send_eos_event (element);
634   poll_eos (element);
635   fail_unless_num_tracks (element, 1);
636
637   send_eos_event (element);
638   poll_eos (element);
639   fail_unless_num_tracks (element, 0);
640
641   /* Single track: */
642   send_eos_event (element);
643   poll_eos (element);
644   fail_unless_num_tracks (element, 0);
645
646   cleanup_rganalysis (element);
647 }
648
649 GST_END_TEST;
650
651 GST_START_TEST (test_no_buffer_album_2)
652 {
653   GstElement *element = setup_rganalysis ();
654   GstTagList *tag_list;
655   gint accumulator = 0;
656   gint i;
657
658   g_object_set (element, "num-tracks", 3, NULL);
659   set_playing_state (element);
660
661   /* No buffer for the first track. */
662
663   send_eos_event (element);
664   /* No tags should be posted, there was nothing to analyze: */
665   poll_eos (element);
666   fail_unless_num_tracks (element, 2);
667
668   /* A test waveform with known gain result as second track: */
669
670   for (i = 20; i--;)
671     push_buffer (test_buffer_square_float_mono (&accumulator, 44100, 512,
672             0.25));
673   send_eos_event (element);
674   tag_list = poll_tags (element);
675   fail_unless_track_peak (tag_list, 0.25);
676   fail_unless_track_gain (tag_list, -6.20);
677   /* Album is not finished yet: */
678   fail_if_album_tags (tag_list);
679   gst_tag_list_free (tag_list);
680   fail_unless_num_tracks (element, 1);
681
682   /* No buffer for the last track. */
683
684   send_eos_event (element);
685
686   tag_list = poll_tags (element);
687   fail_unless_album_peak (tag_list, 0.25);
688   fail_unless_album_gain (tag_list, -6.20);
689   /* No track tags should be posted, as there was no data for it: */
690   fail_if_track_tags (tag_list);
691   gst_tag_list_free (tag_list);
692   fail_unless_num_tracks (element, 0);
693
694   cleanup_rganalysis (element);
695 }
696
697 GST_END_TEST;
698
699 GST_START_TEST (test_empty_buffers)
700 {
701   GstElement *element = setup_rganalysis ();
702
703   set_playing_state (element);
704
705   /* Single track: */
706   push_buffer (test_buffer_const_float_stereo (44100, 0, 0.0, 0.0));
707   send_eos_event (element);
708   poll_eos (element);
709
710   /* First album: */
711   g_object_set (element, "num-tracks", 2, NULL);
712
713   push_buffer (test_buffer_const_float_stereo (44100, 0, 0.0, 0.0));
714   send_eos_event (element);
715   poll_eos (element);
716   fail_unless_num_tracks (element, 1);
717
718   push_buffer (test_buffer_const_float_stereo (44100, 0, 0.0, 0.0));
719   send_eos_event (element);
720   poll_eos (element);
721   fail_unless_num_tracks (element, 0);
722
723   /* Second album, with a single track: */
724   g_object_set (element, "num-tracks", 1, NULL);
725   push_buffer (test_buffer_const_float_stereo (44100, 0, 0.0, 0.0));
726   send_eos_event (element);
727   poll_eos (element);
728   fail_unless_num_tracks (element, 0);
729
730   /* Single track: */
731   push_buffer (test_buffer_const_float_stereo (44100, 0, 0.0, 0.0));
732   send_eos_event (element);
733   poll_eos (element);
734
735   cleanup_rganalysis (element);
736 }
737
738 GST_END_TEST;
739
740 /* Tests for correctness of the peak values. */
741
742 /* Float peak test.  For stereo, one channel has the constant value of -1.369,
743  * the other one 0.0.  This tests many things: The result peak value should
744  * occur on any channel.  The peak is of course the absolute amplitude, so 1.369
745  * should be the result.  This will also detect if the code uses the absolute
746  * value during the comparison.  If it is buggy it will return 0.0 since 0.0 >
747  * -1.369.  Furthermore, this makes sure that there is no problem with headroom
748  * (exceeding 0dBFS).  In the wild you get float samples > 1.0 from stuff like
749  * vorbis. */
750
751 GST_START_TEST (test_peak_float)
752 {
753   GstElement *element = setup_rganalysis ();
754   GstTagList *tag_list;
755
756   set_playing_state (element);
757   push_buffer (test_buffer_const_float_stereo (8000, 512, -1.369, 0.0));
758   send_eos_event (element);
759   tag_list = poll_tags (element);
760   fail_unless_track_peak (tag_list, 1.369);
761   gst_tag_list_free (tag_list);
762
763   /* Swapped channels. */
764   push_buffer (test_buffer_const_float_stereo (8000, 512, 0.0, -1.369));
765   send_eos_event (element);
766   tag_list = poll_tags (element);
767   fail_unless_track_peak (tag_list, 1.369);
768   gst_tag_list_free (tag_list);
769
770   /* Mono. */
771   push_buffer (test_buffer_const_float_mono (8000, 512, -1.369));
772   send_eos_event (element);
773   tag_list = poll_tags (element);
774   fail_unless_track_peak (tag_list, 1.369);
775   gst_tag_list_free (tag_list);
776
777   cleanup_rganalysis (element);
778 }
779
780 GST_END_TEST;
781
782 GST_START_TEST (test_peak_int16_16)
783 {
784   GstElement *element = setup_rganalysis ();
785   GstTagList *tag_list;
786
787   set_playing_state (element);
788
789   /* Half amplitude. */
790   push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 1 << 14, 0));
791   send_eos_event (element);
792   tag_list = poll_tags (element);
793   fail_unless_track_peak (tag_list, 0.5);
794   gst_tag_list_free (tag_list);
795
796   /* Swapped channels. */
797   push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 0, 1 << 14));
798   send_eos_event (element);
799   tag_list = poll_tags (element);
800   fail_unless_track_peak (tag_list, 0.5);
801   gst_tag_list_free (tag_list);
802
803   /* Mono. */
804   push_buffer (test_buffer_const_int16_mono (8000, 16, 512, 1 << 14));
805   send_eos_event (element);
806   tag_list = poll_tags (element);
807   fail_unless_track_peak (tag_list, 0.5);
808   gst_tag_list_free (tag_list);
809
810   /* Half amplitude, negative variant. */
811   push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, -1 << 14, 0));
812   send_eos_event (element);
813   tag_list = poll_tags (element);
814   fail_unless_track_peak (tag_list, 0.5);
815   gst_tag_list_free (tag_list);
816
817   /* Swapped channels. */
818   push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 0, -1 << 14));
819   send_eos_event (element);
820   tag_list = poll_tags (element);
821   fail_unless_track_peak (tag_list, 0.5);
822   gst_tag_list_free (tag_list);
823
824   /* Mono. */
825   push_buffer (test_buffer_const_int16_mono (8000, 16, 512, -1 << 14));
826   send_eos_event (element);
827   tag_list = poll_tags (element);
828   fail_unless_track_peak (tag_list, 0.5);
829   gst_tag_list_free (tag_list);
830
831
832   /* Now check for correct normalization of the peak value: Sample
833    * values of this format range from -32768 to 32767.  So for the
834    * highest positive amplitude we do not reach 1.0, only for
835    * -32768! */
836
837   push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 32767, 0));
838   send_eos_event (element);
839   tag_list = poll_tags (element);
840   fail_unless_track_peak (tag_list, 32767. / 32768.);
841   gst_tag_list_free (tag_list);
842
843   /* Swapped channels. */
844   push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 0, 32767));
845   send_eos_event (element);
846   tag_list = poll_tags (element);
847   fail_unless_track_peak (tag_list, 32767. / 32768.);
848   gst_tag_list_free (tag_list);
849
850   /* Mono. */
851   push_buffer (test_buffer_const_int16_mono (8000, 16, 512, 32767));
852   send_eos_event (element);
853   tag_list = poll_tags (element);
854   fail_unless_track_peak (tag_list, 32767. / 32768.);
855   gst_tag_list_free (tag_list);
856
857
858   /* Negative variant, reaching 1.0. */
859   push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, -32768, 0));
860   send_eos_event (element);
861   tag_list = poll_tags (element);
862   fail_unless_track_peak (tag_list, 1.0);
863   gst_tag_list_free (tag_list);
864
865   /* Swapped channels. */
866   push_buffer (test_buffer_const_int16_stereo (8000, 16, 512, 0, -32768));
867   send_eos_event (element);
868   tag_list = poll_tags (element);
869   fail_unless_track_peak (tag_list, 1.0);
870   gst_tag_list_free (tag_list);
871
872   /* Mono. */
873   push_buffer (test_buffer_const_int16_mono (8000, 16, 512, -32768));
874   send_eos_event (element);
875   tag_list = poll_tags (element);
876   fail_unless_track_peak (tag_list, 1.0);
877   gst_tag_list_free (tag_list);
878
879   cleanup_rganalysis (element);
880 }
881
882 GST_END_TEST;
883
884 /* Same as the test before, but with 8 bits (packed into 16 bits). */
885
886 GST_START_TEST (test_peak_int16_8)
887 {
888   GstElement *element = setup_rganalysis ();
889   GstTagList *tag_list;
890
891   set_playing_state (element);
892
893   /* Half amplitude. */
894   push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, 1 << 6, 0));
895   send_eos_event (element);
896   tag_list = poll_tags (element);
897   fail_unless_track_peak (tag_list, 0.5);
898   gst_tag_list_free (tag_list);
899
900   /* Swapped channels. */
901   push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, 0, 1 << 6));
902   send_eos_event (element);
903   tag_list = poll_tags (element);
904   fail_unless_track_peak (tag_list, 0.5);
905   gst_tag_list_free (tag_list);
906
907   /* Mono. */
908   push_buffer (test_buffer_const_int16_mono (8000, 8, 512, 1 << 6));
909   send_eos_event (element);
910   tag_list = poll_tags (element);
911   fail_unless_track_peak (tag_list, 0.5);
912   gst_tag_list_free (tag_list);
913
914
915   /* Half amplitude, negative variant. */
916   push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, -1 << 6, 0));
917   send_eos_event (element);
918   tag_list = poll_tags (element);
919   fail_unless_track_peak (tag_list, 0.5);
920   gst_tag_list_free (tag_list);
921
922   /* Swapped channels. */
923   push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, 0, -1 << 6));
924   send_eos_event (element);
925   tag_list = poll_tags (element);
926   fail_unless_track_peak (tag_list, 0.5);
927   gst_tag_list_free (tag_list);
928
929   /* Mono. */
930   push_buffer (test_buffer_const_int16_mono (8000, 8, 512, -1 << 6));
931   send_eos_event (element);
932   tag_list = poll_tags (element);
933   fail_unless_track_peak (tag_list, 0.5);
934   gst_tag_list_free (tag_list);
935
936
937   /* Almost full amplitude (maximum positive value). */
938   push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, (1 << 7) - 1, 0));
939   send_eos_event (element);
940   tag_list = poll_tags (element);
941   fail_unless_track_peak (tag_list, 0.9921875);
942   gst_tag_list_free (tag_list);
943
944   /* Swapped channels. */
945   push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, 0, (1 << 7) - 1));
946   send_eos_event (element);
947   tag_list = poll_tags (element);
948   fail_unless_track_peak (tag_list, 0.9921875);
949   gst_tag_list_free (tag_list);
950
951   /* Mono. */
952   push_buffer (test_buffer_const_int16_mono (8000, 8, 512, (1 << 7) - 1));
953   send_eos_event (element);
954   tag_list = poll_tags (element);
955   fail_unless_track_peak (tag_list, 0.9921875);
956   gst_tag_list_free (tag_list);
957
958
959   /* Full amplitude (maximum negative value). */
960   push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, -1 << 7, 0));
961   send_eos_event (element);
962   tag_list = poll_tags (element);
963   fail_unless_track_peak (tag_list, 1.0);
964   gst_tag_list_free (tag_list);
965
966   /* Swapped channels. */
967   push_buffer (test_buffer_const_int16_stereo (8000, 8, 512, 0, -1 << 7));
968   send_eos_event (element);
969   tag_list = poll_tags (element);
970   fail_unless_track_peak (tag_list, 1.0);
971   gst_tag_list_free (tag_list);
972
973   /* Mono. */
974   push_buffer (test_buffer_const_int16_mono (8000, 8, 512, -1 << 7));
975   send_eos_event (element);
976   tag_list = poll_tags (element);
977   fail_unless_track_peak (tag_list, 1.0);
978   gst_tag_list_free (tag_list);
979
980   cleanup_rganalysis (element);
981 }
982
983 GST_END_TEST;
984
985 GST_START_TEST (test_peak_album)
986 {
987   GstElement *element = setup_rganalysis ();
988   GstTagList *tag_list;
989
990   g_object_set (element, "num-tracks", 2, NULL);
991   set_playing_state (element);
992
993   push_buffer (test_buffer_const_float_stereo (8000, 1024, 1.0, 0.0));
994   send_eos_event (element);
995   tag_list = poll_tags (element);
996   fail_unless_track_peak (tag_list, 1.0);
997   fail_if_album_tags (tag_list);
998   gst_tag_list_free (tag_list);
999   fail_unless_num_tracks (element, 1);
1000
1001   push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.0, 0.5));
1002   send_eos_event (element);
1003   tag_list = poll_tags (element);
1004   fail_unless_track_peak (tag_list, 0.5);
1005   fail_unless_album_peak (tag_list, 1.0);
1006   gst_tag_list_free (tag_list);
1007   fail_unless_num_tracks (element, 0);
1008
1009   /* Try a second album: */
1010   g_object_set (element, "num-tracks", 3, NULL);
1011
1012   push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.4, 0.4));
1013   send_eos_event (element);
1014   tag_list = poll_tags (element);
1015   fail_unless_track_peak (tag_list, 0.4);
1016   fail_if_album_tags (tag_list);
1017   gst_tag_list_free (tag_list);
1018   fail_unless_num_tracks (element, 2);
1019
1020   push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.45, 0.45));
1021   send_eos_event (element);
1022   tag_list = poll_tags (element);
1023   fail_unless_track_peak (tag_list, 0.45);
1024   fail_if_album_tags (tag_list);
1025   gst_tag_list_free (tag_list);
1026   fail_unless_num_tracks (element, 1);
1027
1028   push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.2, 0.2));
1029   send_eos_event (element);
1030   tag_list = poll_tags (element);
1031   fail_unless_track_peak (tag_list, 0.2);
1032   fail_unless_album_peak (tag_list, 0.45);
1033   gst_tag_list_free (tag_list);
1034   fail_unless_num_tracks (element, 0);
1035
1036   /* And now a single track, not in album mode (num-tracks is 0
1037    * now): */
1038   push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.1, 0.1));
1039   send_eos_event (element);
1040   tag_list = poll_tags (element);
1041   fail_unless_track_peak (tag_list, 0.1);
1042   fail_if_album_tags (tag_list);
1043   gst_tag_list_free (tag_list);
1044
1045   cleanup_rganalysis (element);
1046 }
1047
1048 GST_END_TEST;
1049
1050 /* Switching from track to album mode. */
1051
1052 GST_START_TEST (test_peak_track_album)
1053 {
1054   GstElement *element = setup_rganalysis ();
1055   GstTagList *tag_list;
1056
1057   set_playing_state (element);
1058
1059   push_buffer (test_buffer_const_float_mono (8000, 1024, 1.0));
1060   send_eos_event (element);
1061   tag_list = poll_tags (element);
1062   fail_unless_track_peak (tag_list, 1.0);
1063   fail_if_album_tags (tag_list);
1064   gst_tag_list_free (tag_list);
1065
1066   g_object_set (element, "num-tracks", 1, NULL);
1067   push_buffer (test_buffer_const_float_mono (8000, 1024, 0.5));
1068   send_eos_event (element);
1069   tag_list = poll_tags (element);
1070   fail_unless_track_peak (tag_list, 0.5);
1071   fail_unless_album_peak (tag_list, 0.5);
1072   gst_tag_list_free (tag_list);
1073   fail_unless_num_tracks (element, 0);
1074
1075   cleanup_rganalysis (element);
1076 }
1077
1078 GST_END_TEST;
1079
1080 /* Disabling album processing before the end of the album.  Probably a rare edge
1081  * case and applications should not rely on this to work.  They need to send the
1082  * element to the READY state to clear up after an aborted album anyway since
1083  * they might need to process another album afterwards. */
1084
1085 GST_START_TEST (test_peak_album_abort_to_track)
1086 {
1087   GstElement *element = setup_rganalysis ();
1088   GstTagList *tag_list;
1089
1090   g_object_set (element, "num-tracks", 2, NULL);
1091   set_playing_state (element);
1092
1093   push_buffer (test_buffer_const_float_stereo (8000, 1024, 1.0, 0.0));
1094   send_eos_event (element);
1095   tag_list = poll_tags (element);
1096   fail_unless_track_peak (tag_list, 1.0);
1097   fail_if_album_tags (tag_list);
1098   gst_tag_list_free (tag_list);
1099   fail_unless_num_tracks (element, 1);
1100
1101   g_object_set (element, "num-tracks", 0, NULL);
1102
1103   push_buffer (test_buffer_const_float_stereo (8000, 1024, 0.0, 0.5));
1104   send_eos_event (element);
1105   tag_list = poll_tags (element);
1106   fail_unless_track_peak (tag_list, 0.5);
1107   fail_if_album_tags (tag_list);
1108   gst_tag_list_free (tag_list);
1109
1110   cleanup_rganalysis (element);
1111 }
1112
1113 GST_END_TEST;
1114
1115 GST_START_TEST (test_gain_album)
1116 {
1117   GstElement *element = setup_rganalysis ();
1118   GstTagList *tag_list;
1119   gint accumulator;
1120   gint i;
1121
1122   g_object_set (element, "num-tracks", 3, NULL);
1123   set_playing_state (element);
1124
1125   /* The three tracks are constructed such that if any of these is in fact
1126    * ignored for the album gain, the album gain will differ. */
1127
1128   accumulator = 0;
1129   for (i = 8; i--;)
1130     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1131             0.75, 0.75));
1132   send_eos_event (element);
1133   tag_list = poll_tags (element);
1134   fail_unless_track_peak (tag_list, 0.75);
1135   fail_unless_track_gain (tag_list, -15.70);
1136   fail_if_album_tags (tag_list);
1137   gst_tag_list_free (tag_list);
1138
1139   accumulator = 0;
1140   for (i = 12; i--;)
1141     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1142             0.5, 0.5));
1143   send_eos_event (element);
1144   tag_list = poll_tags (element);
1145   fail_unless_track_peak (tag_list, 0.5);
1146   fail_unless_track_gain (tag_list, -12.22);
1147   fail_if_album_tags (tag_list);
1148   gst_tag_list_free (tag_list);
1149
1150   accumulator = 0;
1151   for (i = 180; i--;)
1152     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1153             0.25, 0.25));
1154   send_eos_event (element);
1155
1156   tag_list = poll_tags (element);
1157   fail_unless_track_peak (tag_list, 0.25);
1158   fail_unless_track_gain (tag_list, -6.20);
1159   fail_unless_album_peak (tag_list, 0.75);
1160   /* Strangely, wavegain reports -12.17 for the album, but the fixed
1161    * metaflac agrees to us.  Could be a 32767 vs. 32768 issue. */
1162   fail_unless_album_gain (tag_list, -12.18);
1163   gst_tag_list_free (tag_list);
1164
1165   cleanup_rganalysis (element);
1166 }
1167
1168 GST_END_TEST;
1169
1170 /* Checks ensuring that the "forced" property works as advertised. */
1171
1172 GST_START_TEST (test_forced)
1173 {
1174   GstElement *element = setup_rganalysis ();
1175   GstTagList *tag_list;
1176   gint accumulator = 0;
1177   gint i;
1178
1179   g_object_set (element, "forced", FALSE, NULL);
1180   set_playing_state (element);
1181
1182   tag_list = gst_tag_list_new ();
1183   /* Provided values are totally arbitrary. */
1184   gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
1185       GST_TAG_TRACK_PEAK, 1.0, GST_TAG_TRACK_GAIN, 2.21, NULL);
1186   send_tag_event (element, tag_list);
1187
1188   for (i = 20; i--;)
1189     push_buffer (test_buffer_const_float_stereo (44100, 512, 0.5, 0.5));
1190   send_eos_event (element);
1191   /* This fails if a tag message is generated: */
1192   poll_eos (element);
1193
1194   /* Now back to a track without tags. */
1195
1196   for (i = 20; i--;)
1197     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1198             0.25, 0.25));
1199   send_eos_event (element);
1200   tag_list = poll_tags (element);
1201   fail_unless_track_peak (tag_list, 0.25);
1202   fail_unless_track_gain (tag_list, get_expected_gain (44100));
1203   gst_tag_list_free (tag_list);
1204
1205   cleanup_rganalysis (element);
1206 }
1207
1208 GST_END_TEST;
1209
1210 /* Sending track gain and peak in separate tag lists. */
1211
1212 GST_START_TEST (test_forced_separate)
1213 {
1214   GstElement *element = setup_rganalysis ();
1215   GstTagList *tag_list;
1216   gint accumulator = 0;
1217   gint i;
1218
1219   g_object_set (element, "forced", FALSE, NULL);
1220   set_playing_state (element);
1221
1222   tag_list = gst_tag_list_new ();
1223   gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, GST_TAG_TRACK_GAIN, 2.21,
1224       NULL);
1225   send_tag_event (element, tag_list);
1226
1227   tag_list = gst_tag_list_new ();
1228   gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, GST_TAG_TRACK_PEAK, 1.0,
1229       NULL);
1230   send_tag_event (element, tag_list);
1231
1232   for (i = 20; i--;)
1233     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1234             0.5, 0.5));
1235   send_eos_event (element);
1236   /* This fails if a tag message is generated: */
1237   poll_eos (element);
1238
1239   /* Now a track without tags. */
1240
1241   accumulator = 0;
1242   for (i = 20; i--;)
1243     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1244             0.25, 0.25));
1245   send_eos_event (element);
1246   tag_list = poll_tags (element);
1247   fail_unless_track_peak (tag_list, 0.25);
1248   fail_unless_track_gain (tag_list, get_expected_gain (44100));
1249   fail_if_album_tags (tag_list);
1250   gst_tag_list_free (tag_list);
1251
1252   cleanup_rganalysis (element);
1253 }
1254
1255 GST_END_TEST;
1256
1257 /* A TAG event is sent _after_ data has already been processed.  In real
1258  * pipelines, this could happen if there is more than one rganalysis element (by
1259  * accident).  While it would have analyzed all the data prior to receiving the
1260  * event, I expect it to not post its results if not forced.  This test is
1261  * almost equivalent to test_forced. */
1262
1263 GST_START_TEST (test_forced_after_data)
1264 {
1265   GstElement *element = setup_rganalysis ();
1266   GstTagList *tag_list;
1267   gint accumulator = 0;
1268   gint i;
1269
1270   g_object_set (element, "forced", FALSE, NULL);
1271   set_playing_state (element);
1272
1273   for (i = 20; i--;)
1274     push_buffer (test_buffer_const_float_stereo (8000, 512, 0.5, 0.5));
1275
1276   tag_list = gst_tag_list_new ();
1277   gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
1278       GST_TAG_TRACK_PEAK, 1.0, GST_TAG_TRACK_GAIN, 2.21, NULL);
1279   send_tag_event (element, tag_list);
1280
1281   send_eos_event (element);
1282   poll_eos (element);
1283
1284   /* Now back to a normal track, this one has no tags: */
1285   for (i = 20; i--;)
1286     push_buffer (test_buffer_square_float_stereo (&accumulator, 8000, 512, 0.25,
1287             0.25));
1288   send_eos_event (element);
1289   tag_list = poll_tags (element);
1290   fail_unless_track_peak (tag_list, 0.25);
1291   fail_unless_track_gain (tag_list, get_expected_gain (8000));
1292   gst_tag_list_free (tag_list);
1293
1294   cleanup_rganalysis (element);
1295 }
1296
1297 GST_END_TEST;
1298
1299 /* Like test_forced, but *analyze* an album afterwards.  The two tests following
1300  * this one check the *skipping* of albums. */
1301
1302 GST_START_TEST (test_forced_album)
1303 {
1304   GstElement *element = setup_rganalysis ();
1305   GstTagList *tag_list;
1306   gint accumulator;
1307   gint i;
1308
1309   g_object_set (element, "forced", FALSE, NULL);
1310   set_playing_state (element);
1311
1312   tag_list = gst_tag_list_new ();
1313   /* Provided values are totally arbitrary. */
1314   gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
1315       GST_TAG_TRACK_PEAK, 1.0, GST_TAG_TRACK_GAIN, 2.21, NULL);
1316   send_tag_event (element, tag_list);
1317
1318   accumulator = 0;
1319   for (i = 20; i--;)
1320     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1321             0.5, 0.5));
1322   send_eos_event (element);
1323   /* This fails if a tag message is generated: */
1324   poll_eos (element);
1325
1326   /* Now an album without tags. */
1327   g_object_set (element, "num-tracks", 2, NULL);
1328
1329   accumulator = 0;
1330   for (i = 20; i--;)
1331     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1332             0.25, 0.25));
1333   send_eos_event (element);
1334   tag_list = poll_tags (element);
1335   fail_unless_track_peak (tag_list, 0.25);
1336   fail_unless_track_gain (tag_list, get_expected_gain (44100));
1337   fail_if_album_tags (tag_list);
1338   gst_tag_list_free (tag_list);
1339   fail_unless_num_tracks (element, 1);
1340
1341   accumulator = 0;
1342   for (i = 20; i--;)
1343     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1344             0.25, 0.25));
1345   send_eos_event (element);
1346   tag_list = poll_tags (element);
1347   fail_unless_track_peak (tag_list, 0.25);
1348   fail_unless_track_gain (tag_list, get_expected_gain (44100));
1349   fail_unless_album_peak (tag_list, 0.25);
1350   fail_unless_album_gain (tag_list, get_expected_gain (44100));
1351   gst_tag_list_free (tag_list);
1352   fail_unless_num_tracks (element, 0);
1353
1354   cleanup_rganalysis (element);
1355 }
1356
1357 GST_END_TEST;
1358
1359 GST_START_TEST (test_forced_album_skip)
1360 {
1361   GstElement *element = setup_rganalysis ();
1362   GstTagList *tag_list;
1363   gint accumulator = 0;
1364   gint i;
1365
1366   g_object_set (element, "forced", FALSE, "num-tracks", 2, NULL);
1367   set_playing_state (element);
1368
1369   tag_list = gst_tag_list_new ();
1370   /* Provided values are totally arbitrary. */
1371   gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
1372       GST_TAG_TRACK_PEAK, 0.75, GST_TAG_TRACK_GAIN, 2.21,
1373       GST_TAG_ALBUM_PEAK, 0.80, GST_TAG_ALBUM_GAIN, -0.11, NULL);
1374   send_tag_event (element, tag_list);
1375
1376   for (i = 20; i--;)
1377     push_buffer (test_buffer_square_float_stereo (&accumulator, 8000, 512, 0.25,
1378             0.25));
1379   send_eos_event (element);
1380   poll_eos (element);
1381   fail_unless_num_tracks (element, 1);
1382
1383   /* This track has no tags, but needs to be skipped anyways since we
1384    * are in album processing mode. */
1385   for (i = 20; i--;)
1386     push_buffer (test_buffer_const_float_stereo (8000, 512, 0.0, 0.0));
1387   send_eos_event (element);
1388   poll_eos (element);
1389   fail_unless_num_tracks (element, 0);
1390
1391   /* Normal track after the album.  Of course not to be skipped. */
1392   accumulator = 0;
1393   for (i = 20; i--;)
1394     push_buffer (test_buffer_square_float_stereo (&accumulator, 8000, 512, 0.25,
1395             0.25));
1396   send_eos_event (element);
1397   tag_list = poll_tags (element);
1398   fail_unless_track_peak (tag_list, 0.25);
1399   fail_unless_track_gain (tag_list, get_expected_gain (8000));
1400   fail_if_album_tags (tag_list);
1401   gst_tag_list_free (tag_list);
1402
1403   cleanup_rganalysis (element);
1404 }
1405
1406 GST_END_TEST;
1407
1408 GST_START_TEST (test_forced_album_no_skip)
1409 {
1410   GstElement *element = setup_rganalysis ();
1411   GstTagList *tag_list;
1412   gint accumulator = 0;
1413   gint i;
1414
1415   g_object_set (element, "forced", FALSE, "num-tracks", 2, NULL);
1416   set_playing_state (element);
1417
1418   for (i = 20; i--;)
1419     push_buffer (test_buffer_square_float_stereo (&accumulator, 8000, 512, 0.25,
1420             0.25));
1421   send_eos_event (element);
1422   tag_list = poll_tags (element);
1423   fail_unless_track_peak (tag_list, 0.25);
1424   fail_unless_track_gain (tag_list, get_expected_gain (8000));
1425   fail_if_album_tags (tag_list);
1426   gst_tag_list_free (tag_list);
1427   fail_unless_num_tracks (element, 1);
1428
1429   /* The second track has indeed full tags, but although being not forced, this
1430    * one has to be processed because album processing is on. */
1431   tag_list = gst_tag_list_new ();
1432   /* Provided values are totally arbitrary. */
1433   gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
1434       GST_TAG_TRACK_PEAK, 0.75, GST_TAG_TRACK_GAIN, 2.21,
1435       GST_TAG_ALBUM_PEAK, 0.80, GST_TAG_ALBUM_GAIN, -0.11, NULL);
1436   send_tag_event (element, tag_list);
1437   for (i = 20; i--;)
1438     push_buffer (test_buffer_const_float_stereo (8000, 512, 0.0, 0.0));
1439   send_eos_event (element);
1440   tag_list = poll_tags (element);
1441   fail_unless_track_peak (tag_list, 0.0);
1442   fail_unless_track_gain (tag_list, SILENCE_GAIN);
1443   /* Second track was just silence so the album peak equals the first
1444    * track's peak. */
1445   fail_unless_album_peak (tag_list, 0.25);
1446   /* Statistical processing leads to the second track being
1447    * ignored for the gain (because it is so short): */
1448   fail_unless_album_gain (tag_list, get_expected_gain (8000));
1449   gst_tag_list_free (tag_list);
1450   fail_unless_num_tracks (element, 0);
1451
1452   cleanup_rganalysis (element);
1453 }
1454
1455 GST_END_TEST;
1456
1457 GST_START_TEST (test_forced_abort_album_no_skip)
1458 {
1459   GstElement *element = setup_rganalysis ();
1460   GstTagList *tag_list;
1461   gint accumulator = 0;
1462   gint i;
1463
1464   g_object_set (element, "forced", FALSE, "num-tracks", 2, NULL);
1465   set_playing_state (element);
1466
1467   for (i = 20; i--;)
1468     push_buffer (test_buffer_square_float_stereo (&accumulator, 8000, 512, 0.25,
1469             0.25));
1470   send_eos_event (element);
1471   tag_list = poll_tags (element);
1472   fail_unless_track_peak (tag_list, 0.25);
1473   fail_unless_track_gain (tag_list, get_expected_gain (8000));
1474   fail_if_album_tags (tag_list);
1475   gst_tag_list_free (tag_list);
1476   fail_unless_num_tracks (element, 1);
1477
1478   /* Disabling album processing before end of album: */
1479   g_object_set (element, "num-tracks", 0, NULL);
1480
1481   /* Processing a track that has to be skipped. */
1482   tag_list = gst_tag_list_new ();
1483   /* Provided values are totally arbitrary. */
1484   gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
1485       GST_TAG_TRACK_PEAK, 0.75, GST_TAG_TRACK_GAIN, 2.21,
1486       GST_TAG_ALBUM_PEAK, 0.80, GST_TAG_ALBUM_GAIN, -0.11, NULL);
1487   send_tag_event (element, tag_list);
1488   for (i = 20; i--;)
1489     push_buffer (test_buffer_const_float_stereo (8000, 512, 0.0, 0.0));
1490   send_eos_event (element);
1491   poll_eos (element);
1492
1493   cleanup_rganalysis (element);
1494 }
1495
1496 GST_END_TEST;
1497
1498 GST_START_TEST (test_reference_level)
1499 {
1500   GstElement *element = setup_rganalysis ();
1501   GstTagList *tag_list;
1502   gdouble ref_level;
1503   gint accumulator = 0;
1504   gint i;
1505
1506   set_playing_state (element);
1507
1508   for (i = 20; i--;)
1509     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1510             0.25, 0.25));
1511   send_eos_event (element);
1512   tag_list = poll_tags (element);
1513   fail_unless_track_peak (tag_list, 0.25);
1514   fail_unless_track_gain (tag_list, get_expected_gain (44100));
1515   fail_if_album_tags (tag_list);
1516   fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_REFERENCE_LEVEL,
1517           &ref_level) && MATCH_GAIN (ref_level, 89.),
1518       "Incorrect reference level tag");
1519   gst_tag_list_free (tag_list);
1520
1521   g_object_set (element, "reference-level", 83., "num-tracks", 2, NULL);
1522
1523   for (i = 20; i--;)
1524     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1525             0.25, 0.25));
1526   send_eos_event (element);
1527   tag_list = poll_tags (element);
1528   fail_unless_track_peak (tag_list, 0.25);
1529   fail_unless_track_gain (tag_list, get_expected_gain (44100) - 6.);
1530   fail_if_album_tags (tag_list);
1531   fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_REFERENCE_LEVEL,
1532           &ref_level) && MATCH_GAIN (ref_level, 83.),
1533       "Incorrect reference level tag");
1534   gst_tag_list_free (tag_list);
1535
1536   accumulator = 0;
1537   for (i = 20; i--;)
1538     push_buffer (test_buffer_square_float_stereo (&accumulator, 44100, 512,
1539             0.25, 0.25));
1540   send_eos_event (element);
1541   tag_list = poll_tags (element);
1542   fail_unless_track_peak (tag_list, 0.25);
1543   fail_unless_track_gain (tag_list, get_expected_gain (44100) - 6.);
1544   fail_unless_album_peak (tag_list, 0.25);
1545   /* We provided the same waveform twice, with a reset separating
1546    * them.  Therefore, the album gain matches the track gain. */
1547   fail_unless_album_gain (tag_list, get_expected_gain (44100) - 6.);
1548   fail_unless (gst_tag_list_get_double (tag_list, GST_TAG_REFERENCE_LEVEL,
1549           &ref_level) && MATCH_GAIN (ref_level, 83.),
1550       "Incorrect reference level tag");
1551   gst_tag_list_free (tag_list);
1552
1553   cleanup_rganalysis (element);
1554 }
1555
1556 GST_END_TEST;
1557
1558 GST_START_TEST (test_all_formats)
1559 {
1560   GstElement *element = setup_rganalysis ();
1561   GstTagList *tag_list;
1562   gint accumulator = 0;
1563   gint i, j;
1564
1565   set_playing_state (element);
1566   for (i = G_N_ELEMENTS (supported_rates); i--;) {
1567     accumulator = 0;
1568     for (j = 0; j < 4; j++)
1569       push_buffer (test_buffer_square_float_stereo (&accumulator,
1570               supported_rates[i].sample_rate, 512, 0.25, 0.25));
1571     for (j = 0; j < 3; j++)
1572       push_buffer (test_buffer_square_float_mono (&accumulator,
1573               supported_rates[i].sample_rate, 512, 0.25));
1574     for (j = 0; j < 4; j++)
1575       push_buffer (test_buffer_square_int16_stereo (&accumulator,
1576               supported_rates[i].sample_rate, 16, 512, 1 << 13, 1 << 13));
1577     for (j = 0; j < 3; j++)
1578       push_buffer (test_buffer_square_int16_mono (&accumulator,
1579               supported_rates[i].sample_rate, 16, 512, 1 << 13));
1580     for (j = 0; j < 3; j++)
1581       push_buffer (test_buffer_square_int16_stereo (&accumulator,
1582               supported_rates[i].sample_rate, 8, 512, 1 << 5, 1 << 5));
1583     for (j = 0; j < 3; j++)
1584       push_buffer (test_buffer_square_int16_mono (&accumulator,
1585               supported_rates[i].sample_rate, 8, 512, 1 << 5));
1586     send_eos_event (element);
1587     tag_list = poll_tags (element);
1588     fail_unless_track_peak (tag_list, 0.25);
1589     fail_unless_track_gain (tag_list, supported_rates[i].gain);
1590     gst_tag_list_free (tag_list);
1591   }
1592
1593   cleanup_rganalysis (element);
1594 }
1595
1596 GST_END_TEST;
1597
1598 /* Checks ensuring all advertised supported sample rates are really
1599  * accepted, for integer and float, mono and stereo.  This also
1600  * verifies that the correct gain is computed for all formats (except
1601  * odd bit depths). */
1602
1603 #define MAKE_GAIN_TEST_FLOAT_MONO(sample_rate)                        \
1604   GST_START_TEST (test_gain_float_mono_##sample_rate)                 \
1605 {                                                                     \
1606   GstElement *element = setup_rganalysis ();                          \
1607   GstTagList *tag_list;                                               \
1608   gint accumulator = 0;                                               \
1609   gint i;                                                             \
1610                                                                       \
1611   set_playing_state (element);                                        \
1612                                                                       \
1613   for (i = 0; i < 20; i++)                                            \
1614     push_buffer (test_buffer_square_float_mono (&accumulator,         \
1615             sample_rate, 512, 0.25));                                 \
1616   send_eos_event (element);                                           \
1617   tag_list = poll_tags (element);                                     \
1618   fail_unless_track_peak (tag_list, 0.25);                            \
1619   fail_unless_track_gain (tag_list,                                   \
1620       get_expected_gain (sample_rate));                               \
1621   gst_tag_list_free (tag_list);                                       \
1622                                                                       \
1623   cleanup_rganalysis (element);                                       \
1624 }                                                                     \
1625                                                                       \
1626 GST_END_TEST;
1627
1628 #define MAKE_GAIN_TEST_FLOAT_STEREO(sample_rate)                      \
1629   GST_START_TEST (test_gain_float_stereo_##sample_rate)               \
1630 {                                                                     \
1631   GstElement *element = setup_rganalysis ();                          \
1632   GstTagList *tag_list;                                               \
1633   gint accumulator = 0;                                               \
1634   gint i;                                                             \
1635                                                                       \
1636   set_playing_state (element);                                        \
1637                                                                       \
1638   for (i = 0; i < 20; i++)                                            \
1639     push_buffer (test_buffer_square_float_stereo (&accumulator,       \
1640             sample_rate, 512, 0.25, 0.25));                           \
1641   send_eos_event (element);                                           \
1642   tag_list = poll_tags (element);                                     \
1643   fail_unless_track_peak (tag_list, 0.25);                            \
1644   fail_unless_track_gain (tag_list,                                   \
1645       get_expected_gain (sample_rate));                               \
1646   gst_tag_list_free (tag_list);                                       \
1647                                                                       \
1648   cleanup_rganalysis (element);                                       \
1649 }                                                                     \
1650                                                                       \
1651 GST_END_TEST;
1652
1653 #define MAKE_GAIN_TEST_INT16_MONO(sample_rate, depth)                 \
1654   GST_START_TEST (test_gain_int16_##depth##_mono_##sample_rate)       \
1655 {                                                                     \
1656   GstElement *element = setup_rganalysis ();                          \
1657   GstTagList *tag_list;                                               \
1658   gint accumulator = 0;                                               \
1659   gint i;                                                             \
1660                                                                       \
1661   set_playing_state (element);                                        \
1662                                                                       \
1663   for (i = 0; i < 20; i++)                                            \
1664     push_buffer (test_buffer_square_int16_mono (&accumulator,         \
1665             sample_rate, depth, 512, 1 << (13 + depth - 16)));        \
1666                                                                       \
1667   send_eos_event (element);                                           \
1668   tag_list = poll_tags (element);                                     \
1669   fail_unless_track_peak (tag_list, 0.25);                            \
1670   fail_unless_track_gain (tag_list,                                   \
1671       get_expected_gain (sample_rate));                               \
1672   gst_tag_list_free (tag_list);                                       \
1673                                                                       \
1674   cleanup_rganalysis (element);                                       \
1675 }                                                                     \
1676                                                                       \
1677 GST_END_TEST;
1678
1679 #define MAKE_GAIN_TEST_INT16_STEREO(sample_rate, depth)               \
1680   GST_START_TEST (test_gain_int16_##depth##_stereo_##sample_rate)     \
1681 {                                                                     \
1682   GstElement *element = setup_rganalysis ();                          \
1683   GstTagList *tag_list;                                               \
1684   gint accumulator = 0;                                               \
1685   gint i;                                                             \
1686                                                                       \
1687   set_playing_state (element);                                        \
1688                                                                       \
1689   for (i = 0; i < 20; i++)                                            \
1690     push_buffer (test_buffer_square_int16_stereo (&accumulator,       \
1691             sample_rate, depth, 512, 1 << (13 + depth - 16),          \
1692             1 << (13 + depth - 16)));                                 \
1693   send_eos_event (element);                                           \
1694   tag_list = poll_tags (element);                                     \
1695   fail_unless_track_peak (tag_list, 0.25);                            \
1696   fail_unless_track_gain (tag_list,                                   \
1697       get_expected_gain (sample_rate));                               \
1698   gst_tag_list_free (tag_list);                                       \
1699                                                                       \
1700   cleanup_rganalysis (element);                                       \
1701 }                                                                     \
1702                                                                       \
1703 GST_END_TEST;
1704
1705 MAKE_GAIN_TEST_FLOAT_MONO (8000);
1706 MAKE_GAIN_TEST_FLOAT_MONO (11025);
1707 MAKE_GAIN_TEST_FLOAT_MONO (12000);
1708 MAKE_GAIN_TEST_FLOAT_MONO (16000);
1709 MAKE_GAIN_TEST_FLOAT_MONO (22050);
1710 MAKE_GAIN_TEST_FLOAT_MONO (24000);
1711 MAKE_GAIN_TEST_FLOAT_MONO (32000);
1712 MAKE_GAIN_TEST_FLOAT_MONO (44100);
1713 MAKE_GAIN_TEST_FLOAT_MONO (48000);
1714
1715 MAKE_GAIN_TEST_FLOAT_STEREO (8000);
1716 MAKE_GAIN_TEST_FLOAT_STEREO (11025);
1717 MAKE_GAIN_TEST_FLOAT_STEREO (12000);
1718 MAKE_GAIN_TEST_FLOAT_STEREO (16000);
1719 MAKE_GAIN_TEST_FLOAT_STEREO (22050);
1720 MAKE_GAIN_TEST_FLOAT_STEREO (24000);
1721 MAKE_GAIN_TEST_FLOAT_STEREO (32000);
1722 MAKE_GAIN_TEST_FLOAT_STEREO (44100);
1723 MAKE_GAIN_TEST_FLOAT_STEREO (48000);
1724
1725 MAKE_GAIN_TEST_INT16_MONO (8000, 16);
1726 MAKE_GAIN_TEST_INT16_MONO (11025, 16);
1727 MAKE_GAIN_TEST_INT16_MONO (12000, 16);
1728 MAKE_GAIN_TEST_INT16_MONO (16000, 16);
1729 MAKE_GAIN_TEST_INT16_MONO (22050, 16);
1730 MAKE_GAIN_TEST_INT16_MONO (24000, 16);
1731 MAKE_GAIN_TEST_INT16_MONO (32000, 16);
1732 MAKE_GAIN_TEST_INT16_MONO (44100, 16);
1733 MAKE_GAIN_TEST_INT16_MONO (48000, 16);
1734
1735 MAKE_GAIN_TEST_INT16_STEREO (8000, 16);
1736 MAKE_GAIN_TEST_INT16_STEREO (11025, 16);
1737 MAKE_GAIN_TEST_INT16_STEREO (12000, 16);
1738 MAKE_GAIN_TEST_INT16_STEREO (16000, 16);
1739 MAKE_GAIN_TEST_INT16_STEREO (22050, 16);
1740 MAKE_GAIN_TEST_INT16_STEREO (24000, 16);
1741 MAKE_GAIN_TEST_INT16_STEREO (32000, 16);
1742 MAKE_GAIN_TEST_INT16_STEREO (44100, 16);
1743 MAKE_GAIN_TEST_INT16_STEREO (48000, 16);
1744
1745 MAKE_GAIN_TEST_INT16_MONO (8000, 8);
1746 MAKE_GAIN_TEST_INT16_MONO (11025, 8);
1747 MAKE_GAIN_TEST_INT16_MONO (12000, 8);
1748 MAKE_GAIN_TEST_INT16_MONO (16000, 8);
1749 MAKE_GAIN_TEST_INT16_MONO (22050, 8);
1750 MAKE_GAIN_TEST_INT16_MONO (24000, 8);
1751 MAKE_GAIN_TEST_INT16_MONO (32000, 8);
1752 MAKE_GAIN_TEST_INT16_MONO (44100, 8);
1753 MAKE_GAIN_TEST_INT16_MONO (48000, 8);
1754
1755 MAKE_GAIN_TEST_INT16_STEREO (8000, 8);
1756 MAKE_GAIN_TEST_INT16_STEREO (11025, 8);
1757 MAKE_GAIN_TEST_INT16_STEREO (12000, 8);
1758 MAKE_GAIN_TEST_INT16_STEREO (16000, 8);
1759 MAKE_GAIN_TEST_INT16_STEREO (22050, 8);
1760 MAKE_GAIN_TEST_INT16_STEREO (24000, 8);
1761 MAKE_GAIN_TEST_INT16_STEREO (32000, 8);
1762 MAKE_GAIN_TEST_INT16_STEREO (44100, 8);
1763 MAKE_GAIN_TEST_INT16_STEREO (48000, 8);
1764
1765 static Suite *
1766 rganalysis_suite (void)
1767 {
1768   Suite *s = suite_create ("rganalysis");
1769   TCase *tc_chain = tcase_create ("general");
1770
1771   suite_add_tcase (s, tc_chain);
1772
1773   tcase_add_test (tc_chain, test_no_buffer);
1774   tcase_add_test (tc_chain, test_no_buffer_album_1);
1775   tcase_add_test (tc_chain, test_no_buffer_album_2);
1776   tcase_add_test (tc_chain, test_empty_buffers);
1777
1778   tcase_add_test (tc_chain, test_peak_float);
1779   tcase_add_test (tc_chain, test_peak_int16_16);
1780   tcase_add_test (tc_chain, test_peak_int16_8);
1781
1782   tcase_add_test (tc_chain, test_peak_album);
1783   tcase_add_test (tc_chain, test_peak_track_album);
1784   tcase_add_test (tc_chain, test_peak_album_abort_to_track);
1785
1786   tcase_add_test (tc_chain, test_gain_album);
1787
1788   tcase_add_test (tc_chain, test_forced);
1789   tcase_add_test (tc_chain, test_forced_separate);
1790   tcase_add_test (tc_chain, test_forced_after_data);
1791   tcase_add_test (tc_chain, test_forced_album);
1792   tcase_add_test (tc_chain, test_forced_album_skip);
1793   tcase_add_test (tc_chain, test_forced_album_no_skip);
1794   tcase_add_test (tc_chain, test_forced_abort_album_no_skip);
1795
1796   tcase_add_test (tc_chain, test_reference_level);
1797
1798   tcase_add_test (tc_chain, test_all_formats);
1799
1800   tcase_add_test (tc_chain, test_gain_float_mono_8000);
1801   tcase_add_test (tc_chain, test_gain_float_mono_11025);
1802   tcase_add_test (tc_chain, test_gain_float_mono_12000);
1803   tcase_add_test (tc_chain, test_gain_float_mono_16000);
1804   tcase_add_test (tc_chain, test_gain_float_mono_22050);
1805   tcase_add_test (tc_chain, test_gain_float_mono_24000);
1806   tcase_add_test (tc_chain, test_gain_float_mono_32000);
1807   tcase_add_test (tc_chain, test_gain_float_mono_44100);
1808   tcase_add_test (tc_chain, test_gain_float_mono_48000);
1809
1810   tcase_add_test (tc_chain, test_gain_float_stereo_8000);
1811   tcase_add_test (tc_chain, test_gain_float_stereo_11025);
1812   tcase_add_test (tc_chain, test_gain_float_stereo_12000);
1813   tcase_add_test (tc_chain, test_gain_float_stereo_16000);
1814   tcase_add_test (tc_chain, test_gain_float_stereo_22050);
1815   tcase_add_test (tc_chain, test_gain_float_stereo_24000);
1816   tcase_add_test (tc_chain, test_gain_float_stereo_32000);
1817   tcase_add_test (tc_chain, test_gain_float_stereo_44100);
1818   tcase_add_test (tc_chain, test_gain_float_stereo_48000);
1819
1820   tcase_add_test (tc_chain, test_gain_int16_16_mono_8000);
1821   tcase_add_test (tc_chain, test_gain_int16_16_mono_11025);
1822   tcase_add_test (tc_chain, test_gain_int16_16_mono_12000);
1823   tcase_add_test (tc_chain, test_gain_int16_16_mono_16000);
1824   tcase_add_test (tc_chain, test_gain_int16_16_mono_22050);
1825   tcase_add_test (tc_chain, test_gain_int16_16_mono_24000);
1826   tcase_add_test (tc_chain, test_gain_int16_16_mono_32000);
1827   tcase_add_test (tc_chain, test_gain_int16_16_mono_44100);
1828   tcase_add_test (tc_chain, test_gain_int16_16_mono_48000);
1829
1830   tcase_add_test (tc_chain, test_gain_int16_16_stereo_8000);
1831   tcase_add_test (tc_chain, test_gain_int16_16_stereo_11025);
1832   tcase_add_test (tc_chain, test_gain_int16_16_stereo_12000);
1833   tcase_add_test (tc_chain, test_gain_int16_16_stereo_16000);
1834   tcase_add_test (tc_chain, test_gain_int16_16_stereo_22050);
1835   tcase_add_test (tc_chain, test_gain_int16_16_stereo_24000);
1836   tcase_add_test (tc_chain, test_gain_int16_16_stereo_32000);
1837   tcase_add_test (tc_chain, test_gain_int16_16_stereo_44100);
1838   tcase_add_test (tc_chain, test_gain_int16_16_stereo_48000);
1839
1840   tcase_add_test (tc_chain, test_gain_int16_8_mono_8000);
1841   tcase_add_test (tc_chain, test_gain_int16_8_mono_11025);
1842   tcase_add_test (tc_chain, test_gain_int16_8_mono_12000);
1843   tcase_add_test (tc_chain, test_gain_int16_8_mono_16000);
1844   tcase_add_test (tc_chain, test_gain_int16_8_mono_22050);
1845   tcase_add_test (tc_chain, test_gain_int16_8_mono_24000);
1846   tcase_add_test (tc_chain, test_gain_int16_8_mono_32000);
1847   tcase_add_test (tc_chain, test_gain_int16_8_mono_44100);
1848   tcase_add_test (tc_chain, test_gain_int16_8_mono_48000);
1849
1850   tcase_add_test (tc_chain, test_gain_int16_8_stereo_8000);
1851   tcase_add_test (tc_chain, test_gain_int16_8_stereo_11025);
1852   tcase_add_test (tc_chain, test_gain_int16_8_stereo_12000);
1853   tcase_add_test (tc_chain, test_gain_int16_8_stereo_16000);
1854   tcase_add_test (tc_chain, test_gain_int16_8_stereo_22050);
1855   tcase_add_test (tc_chain, test_gain_int16_8_stereo_24000);
1856   tcase_add_test (tc_chain, test_gain_int16_8_stereo_32000);
1857   tcase_add_test (tc_chain, test_gain_int16_8_stereo_44100);
1858   tcase_add_test (tc_chain, test_gain_int16_8_stereo_48000);
1859
1860   return s;
1861 }
1862
1863 int
1864 main (int argc, char **argv)
1865 {
1866   gint nf;
1867
1868   Suite *s = rganalysis_suite ();
1869   SRunner *sr = srunner_create (s);
1870
1871   gst_check_init (&argc, &argv);
1872
1873   srunner_run_all (sr, CK_ENV);
1874   nf = srunner_ntests_failed (sr);
1875   srunner_free (sr);
1876
1877   return nf;
1878 }