71c8feeaf45864d62c95a1730093a29cfa8e97d6
[platform/upstream/flac.git] / src / test_streams / main.c
1 /* test_streams - Simple test pattern generator
2  * Copyright (C) 2000,2001,2002,2003  Josh Coalson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18
19 #include <math.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #if defined _MSC_VER || defined __MINGW32__
23 #include <time.h>
24 #else
25 #include <sys/time.h>
26 #endif
27 #include "FLAC/assert.h"
28 #include "FLAC/ordinals.h"
29
30 #ifndef M_PI
31 /* math.h in VC++ doesn't seem to have this (how Microsoft is that?) */
32 #define M_PI 3.14159265358979323846
33 #endif
34
35 #ifdef _WIN32
36         static const char *mode = "wb";
37 #else
38         static const char *mode = "w";
39 #endif
40
41 static FLAC__bool is_big_endian_host;
42
43
44 static FLAC__bool write_little_endian_uint16(FILE *f, FLAC__uint16 x)
45 {
46         return
47                 fputc(x, f) != EOF &&
48                 fputc(x >> 8, f) != EOF
49         ;
50 }
51
52 static FLAC__bool write_little_endian_int16(FILE *f, FLAC__int16 x)
53 {
54         return write_little_endian_uint16(f, (FLAC__uint16)x);
55 }
56
57 static FLAC__bool write_little_endian_uint24(FILE *f, FLAC__uint32 x)
58 {
59         return
60                 fputc(x, f) != EOF &&
61                 fputc(x >> 8, f) != EOF &&
62                 fputc(x >> 16, f) != EOF
63         ;
64 }
65
66 static FLAC__bool write_little_endian_int24(FILE *f, FLAC__int32 x)
67 {
68         return write_little_endian_uint24(f, (FLAC__uint32)x);
69 }
70
71 static FLAC__bool write_little_endian_uint32(FILE *f, FLAC__uint32 x)
72 {
73         return
74                 fputc(x, f) != EOF &&
75                 fputc(x >> 8, f) != EOF &&
76                 fputc(x >> 16, f) != EOF &&
77                 fputc(x >> 24, f) != EOF
78         ;
79 }
80
81 #if 0
82 /* @@@ not used (yet) */
83 static FLAC__bool write_little_endian_int32(FILE *f, FLAC__int32 x)
84 {
85         return write_little_endian_uint32(f, (FLAC__uint32)x);
86 }
87 #endif
88
89 static FLAC__bool write_big_endian_uint16(FILE *f, FLAC__uint16 x)
90 {
91         return
92                 fputc(x >> 8, f) != EOF &&
93                 fputc(x, f) != EOF
94         ;
95 }
96
97 #if 0
98 /* @@@ not used (yet) */
99 static FLAC__bool write_big_endian_int16(FILE *f, FLAC__int16 x)
100 {
101         return write_big_endian_uint16(f, (FLAC__uint16)x);
102 }
103 #endif
104
105 #if 0
106 /* @@@ not used (yet) */
107 static FLAC__bool write_big_endian_uint24(FILE *f, FLAC__uint32 x)
108 {
109         return
110                 fputc(x >> 16, f) != EOF &&
111                 fputc(x >> 8, f) != EOF &&
112                 fputc(x, f) != EOF
113         ;
114 }
115 #endif
116
117 #if 0
118 /* @@@ not used (yet) */
119 static FLAC__bool write_big_endian_int24(FILE *f, FLAC__int32 x)
120 {
121         return write_big_endian_uint24(f, (FLAC__uint32)x);
122 }
123 #endif
124
125 static FLAC__bool write_big_endian_uint32(FILE *f, FLAC__uint32 x)
126 {
127         return
128                 fputc(x >> 24, f) != EOF &&
129                 fputc(x >> 16, f) != EOF &&
130                 fputc(x >> 8, f) != EOF &&
131                 fputc(x, f) != EOF
132         ;
133 }
134
135 #if 0
136 /* @@@ not used (yet) */
137 static FLAC__bool write_big_endian_int32(FILE *f, FLAC__int32 x)
138 {
139         return write_big_endian_uint32(f, (FLAC__uint32)x);
140 }
141 #endif
142
143 static FLAC__bool write_sane_extended(FILE *f, unsigned val)
144         /* Write to 'f' a SANE extended representation of 'val'.  Return false if
145         * the write succeeds; return true otherwise.
146         *
147         * SANE extended is an 80-bit IEEE-754 representation with sign bit, 15 bits
148         * of exponent, and 64 bits of significand (mantissa).  Unlike most IEEE-754
149         * representations, it does not imply a 1 above the MSB of the significand.
150         *
151         * Preconditions:
152         *  val!=0U
153         */
154 {
155         unsigned int shift, exponent;
156
157         FLAC__ASSERT(val!=0U); /* handling 0 would require a special case */
158
159         for(shift= 0U; (val>>(31-shift))==0U; ++shift)
160                 ;
161         val<<= shift;
162         exponent= 63U-(shift+32U); /* add 32 for unused second word */
163
164         if(!write_big_endian_uint16(f, (FLAC__uint16)(exponent+0x3FFF)))
165                 return false;
166         if(!write_big_endian_uint32(f, val))
167                 return false;
168         if(!write_big_endian_uint32(f, 0)) /* unused second word */
169                 return false;
170
171         return true;
172 }
173
174 /* a mono one-sample 16bps stream */
175 static FLAC__bool generate_01()
176 {
177         FILE *f;
178         FLAC__int16 x = -32768;
179
180         if(0 == (f = fopen("test01.raw", mode)))
181                 return false;
182
183         if(!write_little_endian_int16(f, x))
184                 goto foo;
185
186         fclose(f);
187         return true;
188 foo:
189         fclose(f);
190         return false;
191 }
192
193 /* a stereo one-sample 16bps stream */
194 static FLAC__bool generate_02()
195 {
196         FILE *f;
197         FLAC__int16 xl = -32768, xr = 32767;
198
199         if(0 == (f = fopen("test02.raw", mode)))
200                 return false;
201
202         if(!write_little_endian_int16(f, xl))
203                 goto foo;
204         if(!write_little_endian_int16(f, xr))
205                 goto foo;
206
207         fclose(f);
208         return true;
209 foo:
210         fclose(f);
211         return false;
212 }
213
214 /* a mono five-sample 16bps stream */
215 static FLAC__bool generate_03()
216 {
217         FILE *f;
218         FLAC__int16 x[] = { -25, 0, 25, 50, 100 };
219         unsigned i;
220
221         if(0 == (f = fopen("test03.raw", mode)))
222                 return false;
223
224         for(i = 0; i < 5; i++)
225                 if(!write_little_endian_int16(f, x[i]))
226                         goto foo;
227
228         fclose(f);
229         return true;
230 foo:
231         fclose(f);
232         return false;
233 }
234
235 /* a stereo five-sample 16bps stream */
236 static FLAC__bool generate_04()
237 {
238         FILE *f;
239         FLAC__int16 x[] = { -25, 500, 0, 400, 25, 300, 50, 200, 100, 100 };
240         unsigned i;
241
242         if(0 == (f = fopen("test04.raw", mode)))
243                 return false;
244
245         for(i = 0; i < 10; i++)
246                 if(!write_little_endian_int16(f, x[i]))
247                         goto foo;
248
249         fclose(f);
250         return true;
251 foo:
252         fclose(f);
253         return false;
254 }
255
256 /* a mono full-scale deflection 8bps stream */
257 static FLAC__bool generate_fsd8(const char *fn, const int pattern[], unsigned reps)
258 {
259         FILE *f;
260         unsigned rep, p;
261
262         FLAC__ASSERT(pattern != 0);
263
264         if(0 == (f = fopen(fn, mode)))
265                 return false;
266
267         for(rep = 0; rep < reps; rep++) {
268                 for(p = 0; pattern[p]; p++) {
269                         signed char x = pattern[p] > 0? 127 : -128;
270                         if(fwrite(&x, sizeof(x), 1, f) < 1)
271                                 goto foo;
272                 }
273         }
274
275         fclose(f);
276         return true;
277 foo:
278         fclose(f);
279         return false;
280 }
281
282 /* a mono full-scale deflection 16bps stream */
283 static FLAC__bool generate_fsd16(const char *fn, const int pattern[], unsigned reps)
284 {
285         FILE *f;
286         unsigned rep, p;
287
288         FLAC__ASSERT(pattern != 0);
289
290         if(0 == (f = fopen(fn, mode)))
291                 return false;
292
293         for(rep = 0; rep < reps; rep++) {
294                 for(p = 0; pattern[p]; p++) {
295                         FLAC__int16 x = pattern[p] > 0? 32767 : -32768;
296                         if(!write_little_endian_int16(f, x))
297                                 goto foo;
298                 }
299         }
300
301         fclose(f);
302         return true;
303 foo:
304         fclose(f);
305         return false;
306 }
307
308 /* a stereo wasted-bits-per-sample 16bps stream */
309 static FLAC__bool generate_wbps16(const char *fn, unsigned samples)
310 {
311         FILE *f;
312         unsigned sample;
313
314         if(0 == (f = fopen(fn, mode)))
315                 return false;
316
317         for(sample = 0; sample < samples; sample++) {
318                 FLAC__int16 l = (sample % 2000) << 2;
319                 FLAC__int16 r = (sample % 1000) << 3;
320                 if(!write_little_endian_int16(f, l))
321                         goto foo;
322                 if(!write_little_endian_int16(f, r))
323                         goto foo;
324         }
325
326         fclose(f);
327         return true;
328 foo:
329         fclose(f);
330         return false;
331 }
332
333 /* a mono full-scale deflection 24bps stream */
334 static FLAC__bool generate_fsd24(const char *fn, const int pattern[], unsigned reps)
335 {
336         FILE *f;
337         unsigned rep, p;
338
339         FLAC__ASSERT(pattern != 0);
340
341         if(0 == (f = fopen(fn, mode)))
342                 return false;
343
344         for(rep = 0; rep < reps; rep++) {
345                 for(p = 0; pattern[p]; p++) {
346                         FLAC__int32 x = pattern[p] > 0? 8388607 : -8388608;
347                         if(!write_little_endian_int24(f, x))
348                                 goto foo;
349                 }
350         }
351
352         fclose(f);
353         return true;
354 foo:
355         fclose(f);
356         return false;
357 }
358
359 /* a mono sine-wave 8bps stream */
360 static FLAC__bool generate_sine8_1(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2)
361 {
362         const FLAC__int8 full_scale = 127;
363         const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
364         const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
365         FILE *f;
366         double theta1, theta2;
367         unsigned i;
368
369         if(0 == (f = fopen(fn, mode)))
370                 return false;
371
372         for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
373                 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
374                 FLAC__int8 v = (FLAC__int8)(val + 0.5);
375                 if(fwrite(&v, sizeof(v), 1, f) < 1)
376                         goto foo;
377         }
378
379         fclose(f);
380         return true;
381 foo:
382         fclose(f);
383         return false;
384 }
385
386 /* a stereo sine-wave 8bps stream */
387 static FLAC__bool generate_sine8_2(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2, double fmult)
388 {
389         const FLAC__int8 full_scale = 127;
390         const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
391         const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
392         FILE *f;
393         double theta1, theta2;
394         unsigned i;
395
396         if(0 == (f = fopen(fn, mode)))
397                 return false;
398
399         for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
400                 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
401                 FLAC__int8 v = (FLAC__int8)(val + 0.5);
402                 if(fwrite(&v, sizeof(v), 1, f) < 1)
403                         goto foo;
404                 val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
405                 v = (FLAC__int8)(val + 0.5);
406                 if(fwrite(&v, sizeof(v), 1, f) < 1)
407                         goto foo;
408         }
409
410         fclose(f);
411         return true;
412 foo:
413         fclose(f);
414         return false;
415 }
416
417 /* a mono sine-wave 16bps stream */
418 static FLAC__bool generate_sine16_1(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2)
419 {
420         const FLAC__int16 full_scale = 32767;
421         const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
422         const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
423         FILE *f;
424         double theta1, theta2;
425         unsigned i;
426
427         if(0 == (f = fopen(fn, mode)))
428                 return false;
429
430         for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
431                 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
432                 FLAC__int16 v = (FLAC__int16)(val + 0.5);
433                 if(!write_little_endian_int16(f, v))
434                         goto foo;
435         }
436
437         fclose(f);
438         return true;
439 foo:
440         fclose(f);
441         return false;
442 }
443
444 /* a stereo sine-wave 16bps stream */
445 static FLAC__bool generate_sine16_2(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2, double fmult)
446 {
447         const FLAC__int16 full_scale = 32767;
448         const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
449         const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
450         FILE *f;
451         double theta1, theta2;
452         unsigned i;
453
454         if(0 == (f = fopen(fn, mode)))
455                 return false;
456
457         for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
458                 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
459                 FLAC__int16 v = (FLAC__int16)(val + 0.5);
460                 if(!write_little_endian_int16(f, v))
461                         goto foo;
462                 val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
463                 v = (FLAC__int16)(val + 0.5);
464                 if(!write_little_endian_int16(f, v))
465                         goto foo;
466         }
467
468         fclose(f);
469         return true;
470 foo:
471         fclose(f);
472         return false;
473 }
474
475 /* a mono sine-wave 24bps stream */
476 static FLAC__bool generate_sine24_1(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2)
477 {
478         const FLAC__int32 full_scale = 0x7fffff;
479         const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
480         const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
481         FILE *f;
482         double theta1, theta2;
483         unsigned i;
484
485         if(0 == (f = fopen(fn, mode)))
486                 return false;
487
488         for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
489                 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
490                 FLAC__int32 v = (FLAC__int32)(val + 0.5);
491                 if(!write_little_endian_int24(f, v))
492                         goto foo;
493         }
494
495         fclose(f);
496         return true;
497 foo:
498         fclose(f);
499         return false;
500 }
501
502 /* a stereo sine-wave 24bps stream */
503 static FLAC__bool generate_sine24_2(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2, double fmult)
504 {
505         const FLAC__int32 full_scale = 0x7fffff;
506         const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
507         const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
508         FILE *f;
509         double theta1, theta2;
510         unsigned i;
511
512         if(0 == (f = fopen(fn, mode)))
513                 return false;
514
515         for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
516                 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
517                 FLAC__int32 v = (FLAC__int32)(val + 0.5);
518                 if(!write_little_endian_int24(f, v))
519                         goto foo;
520                 val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
521                 v = (FLAC__int32)(val + 0.5);
522                 if(!write_little_endian_int24(f, v))
523                         goto foo;
524         }
525
526         fclose(f);
527         return true;
528 foo:
529         fclose(f);
530         return false;
531 }
532
533 static FLAC__bool generate_noise(const char *fn, unsigned bytes)
534 {
535         FILE *f;
536         unsigned b;
537 #if !defined _MSC_VER && !defined __MINGW32__
538         struct timeval tv;
539
540         if(gettimeofday(&tv, 0) < 0) {
541                 fprintf(stderr, "WARNING: couldn't seed RNG with time\n");
542                 tv.tv_usec = 4321;
543         }
544         srandom(tv.tv_usec);
545 #else
546         srand(time(0));
547 #endif
548
549         if(0 == (f = fopen(fn, mode)))
550                 return false;
551
552         for(b = 0; b < bytes; b++) {
553 #if !defined _MSC_VER && !defined __MINGW32__
554                 FLAC__byte x = (FLAC__byte)(((unsigned)random()) & 0xff);
555 #else
556                 FLAC__byte x = (FLAC__byte)(((unsigned)rand()) & 0xff);
557 #endif
558                 if(fwrite(&x, sizeof(x), 1, f) < 1)
559                         goto foo;
560         }
561
562         fclose(f);
563         return true;
564 foo:
565         fclose(f);
566         return false;
567 }
568
569 static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsigned channels, unsigned bytes_per_sample, unsigned samples)
570 {
571         const unsigned true_size = channels * bytes_per_sample * samples;
572         const unsigned padded_size = (true_size + 1) & (~1u);
573         FILE *f;
574         unsigned i;
575
576         if(0 == (f = fopen(filename, mode)))
577                 return false;
578         if(fwrite("FORM", 1, 4, f) < 4)
579                 goto foo;
580         if(!write_big_endian_uint32(f, padded_size + 46))
581                 goto foo;
582         if(fwrite("AIFFCOMM\000\000\000\022", 1, 12, f) < 12)
583                 goto foo;
584         if(!write_big_endian_uint16(f, (FLAC__uint16)channels))
585                 goto foo;
586         if(!write_big_endian_uint32(f, samples))
587                 goto foo;
588         if(!write_big_endian_uint16(f, (FLAC__uint16)(8 * bytes_per_sample)))
589                 goto foo;
590         if(!write_sane_extended(f, sample_rate))
591                 goto foo;
592         if(fwrite("SSND", 1, 4, f) < 4)
593                 goto foo;
594         if(!write_big_endian_uint32(f, true_size + 8))
595                 goto foo;
596         if(fwrite("\000\000\000\000\000\000\000\000", 1, 8, f) < 8)
597                 goto foo;
598
599         for(i = 0; i < true_size; i++)
600                 if(fputc(i, f) == EOF)
601                         goto foo;
602         for( ; i < padded_size; i++)
603                 if(fputc(0, f) == EOF)
604                         goto foo;
605
606         fclose(f);
607         return true;
608 foo:
609         fclose(f);
610         return false;
611 }
612
613 static FLAC__bool generate_wav(const char *filename, unsigned sample_rate, unsigned channels, unsigned bytes_per_sample, unsigned samples)
614 {
615         const unsigned size = channels * bytes_per_sample * samples;
616         FILE *f;
617         unsigned i;
618
619         if(0 == (f = fopen(filename, mode)))
620                 return false;
621         if(fwrite("RIFF", 1, 4, f) < 4)
622                 goto foo;
623         if(!write_little_endian_uint32(f, size + 36))
624                 goto foo;
625         if(fwrite("WAVEfmt \020\000\000\000\001\000", 1, 14, f) < 14)
626                 goto foo;
627         if(!write_little_endian_uint16(f, (FLAC__uint16)channels))
628                 goto foo;
629         if(!write_little_endian_uint32(f, sample_rate))
630                 goto foo;
631         if(!write_little_endian_uint32(f, sample_rate * channels * bytes_per_sample))
632                 goto foo;
633         if(!write_little_endian_uint16(f, (FLAC__uint16)(channels * bytes_per_sample))) /* block align */
634                 goto foo;
635         if(!write_little_endian_uint16(f, (FLAC__uint16)(8 * bytes_per_sample)))
636                 goto foo;
637         if(fwrite("data", 1, 4, f) < 4)
638                 goto foo;
639         if(!write_little_endian_uint32(f, size))
640                 goto foo;
641
642         for(i = 0; i < size; i++)
643                 if(fputc(i, f) == EOF)
644                         goto foo;
645
646         fclose(f);
647         return true;
648 foo:
649         fclose(f);
650         return false;
651 }
652
653 static FLAC__bool generate_wackywavs()
654 {
655         FILE *f;
656         FLAC__byte wav[] = {
657                 'R', 'I', 'F', 'F',  76,   0,   0,   0,
658                 'W', 'A', 'V', 'E', 'f', 'a', 'c', 't',
659                   4,   0,   0,  0 , 'b', 'l', 'a', 'h',
660                 'p', 'a', 'd', ' ',   4,   0,   0,   0,
661                 'B', 'L', 'A', 'H', 'f', 'm', 't', ' ',
662                  16,   0,   0,   0,   1,   0,   1,   0,
663                 0x44,0xAC,  0,   0,   0,   0,   0,   0,
664                   2,   0,  16,   0, 'd', 'a', 't', 'a',
665                  16,   0,   0,   0,   0,   0,   1,   0,
666                   4,   0,   9,   0,  16,   0,  25,   0,
667                  36,   0,  49,   0, 'p', 'a', 'd', ' ',
668                   4,   0,   0,   0, 'b', 'l', 'a', 'h'
669         };
670
671         if(0 == (f = fopen("wacky1.wav", mode)))
672                 return false;
673         if(fwrite(wav, 1, 84, f) < 84)
674                 goto foo;
675         fclose(f);
676
677         wav[4] += 12;
678         if(0 == (f = fopen("wacky2.wav", mode)))
679                 return false;
680         if(fwrite(wav, 1, 96, f) < 96)
681                 goto foo;
682         fclose(f);
683
684         return true;
685 foo:
686         fclose(f);
687         return false;
688 }
689
690 int main(int argc, char *argv[])
691 {
692         FLAC__uint32 test = 1;
693         unsigned channels;
694
695         int pattern01[] = { 1, -1, 0 };
696         int pattern02[] = { 1, 1, -1, 0 };
697         int pattern03[] = { 1, -1, -1, 0 };
698         int pattern04[] = { 1, -1, 1, -1, 0 };
699         int pattern05[] = { 1, -1, -1, 1, 0 };
700         int pattern06[] = { 1, -1, 1, 1, -1, 0 };
701         int pattern07[] = { 1, -1, -1, 1, -1, 0 };
702
703         (void)argc;
704         (void)argv;
705         is_big_endian_host = (*((FLAC__byte*)(&test)))? false : true;
706
707         if(!generate_01()) return 1;
708         if(!generate_02()) return 1;
709         if(!generate_03()) return 1;
710         if(!generate_04()) return 1;
711
712         if(!generate_fsd8("fsd8-01.raw", pattern01, 100)) return 1;
713         if(!generate_fsd8("fsd8-02.raw", pattern02, 100)) return 1;
714         if(!generate_fsd8("fsd8-03.raw", pattern03, 100)) return 1;
715         if(!generate_fsd8("fsd8-04.raw", pattern04, 100)) return 1;
716         if(!generate_fsd8("fsd8-05.raw", pattern05, 100)) return 1;
717         if(!generate_fsd8("fsd8-06.raw", pattern06, 100)) return 1;
718         if(!generate_fsd8("fsd8-07.raw", pattern07, 100)) return 1;
719
720         if(!generate_fsd16("fsd16-01.raw", pattern01, 100)) return 1;
721         if(!generate_fsd16("fsd16-02.raw", pattern02, 100)) return 1;
722         if(!generate_fsd16("fsd16-03.raw", pattern03, 100)) return 1;
723         if(!generate_fsd16("fsd16-04.raw", pattern04, 100)) return 1;
724         if(!generate_fsd16("fsd16-05.raw", pattern05, 100)) return 1;
725         if(!generate_fsd16("fsd16-06.raw", pattern06, 100)) return 1;
726         if(!generate_fsd16("fsd16-07.raw", pattern07, 100)) return 1;
727
728         if(!generate_fsd24("fsd24-01.raw", pattern01, 100)) return 1;
729         if(!generate_fsd24("fsd24-02.raw", pattern02, 100)) return 1;
730         if(!generate_fsd24("fsd24-03.raw", pattern03, 100)) return 1;
731         if(!generate_fsd24("fsd24-04.raw", pattern04, 100)) return 1;
732         if(!generate_fsd24("fsd24-05.raw", pattern05, 100)) return 1;
733         if(!generate_fsd24("fsd24-06.raw", pattern06, 100)) return 1;
734         if(!generate_fsd24("fsd24-07.raw", pattern07, 100)) return 1;
735
736         if(!generate_wbps16("wbps16-01.raw", 1000)) return 1;
737
738         if(!generate_sine8_1("sine8-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1;
739         if(!generate_sine8_1("sine8-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1;
740         if(!generate_sine8_1("sine8-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1;
741         if(!generate_sine8_1("sine8-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1;
742         if(!generate_sine8_1("sine8-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
743
744         if(!generate_sine8_2("sine8-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
745         if(!generate_sine8_2("sine8-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
746         if(!generate_sine8_2("sine8-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
747         if(!generate_sine8_2("sine8-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
748         if(!generate_sine8_2("sine8-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
749         if(!generate_sine8_2("sine8-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
750         if(!generate_sine8_2("sine8-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
751         if(!generate_sine8_2("sine8-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
752         if(!generate_sine8_2("sine8-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
753         if(!generate_sine8_2("sine8-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
754
755         if(!generate_sine16_1("sine16-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1;
756         if(!generate_sine16_1("sine16-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1;
757         if(!generate_sine16_1("sine16-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1;
758         if(!generate_sine16_1("sine16-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1;
759         if(!generate_sine16_1("sine16-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
760
761         if(!generate_sine16_2("sine16-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
762         if(!generate_sine16_2("sine16-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
763         if(!generate_sine16_2("sine16-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
764         if(!generate_sine16_2("sine16-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
765         if(!generate_sine16_2("sine16-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
766         if(!generate_sine16_2("sine16-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
767         if(!generate_sine16_2("sine16-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
768         if(!generate_sine16_2("sine16-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
769         if(!generate_sine16_2("sine16-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
770         if(!generate_sine16_2("sine16-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
771
772         if(!generate_sine24_1("sine24-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1;
773         if(!generate_sine24_1("sine24-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1;
774         if(!generate_sine24_1("sine24-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1;
775         if(!generate_sine24_1("sine24-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1;
776         if(!generate_sine24_1("sine24-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
777
778         if(!generate_sine24_2("sine24-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
779         if(!generate_sine24_2("sine24-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
780         if(!generate_sine24_2("sine24-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
781         if(!generate_sine24_2("sine24-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
782         if(!generate_sine24_2("sine24-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
783         if(!generate_sine24_2("sine24-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
784         if(!generate_sine24_2("sine24-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
785         if(!generate_sine24_2("sine24-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
786         if(!generate_sine24_2("sine24-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
787         if(!generate_sine24_2("sine24-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
788
789         if(!generate_noise("noise.raw", 65536 * 8 * 3)) return 1;
790         if(!generate_noise("noise8m32.raw", 32)) return 1;
791         if(!generate_wackywavs()) return 1;
792         for(channels = 1; channels <= 8; channels++) {
793                 unsigned bytes_per_sample;
794                 for(bytes_per_sample = 1; bytes_per_sample <= 3; bytes_per_sample++) {
795                         static const unsigned nsamples[] = { 1, 111, 5555 } ;
796                         unsigned samples;
797                         for(samples = 0; samples < sizeof(nsamples)/sizeof(nsamples[0]); samples++) {
798                                 char fn[64];
799
800                                 sprintf(fn, "rt-%u-%u-%u.aiff", channels, bytes_per_sample, nsamples[samples]);
801                                 if(!generate_aiff(fn, 44100, channels, bytes_per_sample, nsamples[samples]))
802                                         return 1;
803
804                                 sprintf(fn, "rt-%u-%u-%u.raw", channels, bytes_per_sample, nsamples[samples]);
805                                 if(!generate_noise(fn, channels * bytes_per_sample * nsamples[samples]))
806                                         return 1;
807
808                                 sprintf(fn, "rt-%u-%u-%u.wav", channels, bytes_per_sample, nsamples[samples]);
809                                 if(!generate_wav(fn, 44100, channels, bytes_per_sample, nsamples[samples]))
810                                         return 1;
811                         }
812                 }
813         }
814
815         return 0;
816 }