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