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