Huge Windows utf8 I/O patch.
[flac.git] / src / test_streams / main.c
blobbb1d5fc35f4826f345af920171675b0e5125995e
1 /* test_streams - Simple test pattern generator
2 * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Josh Coalson
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.
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.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #if HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #include <math.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include "share/compat.h"
27 #if defined _MSC_VER || defined __MINGW32__
28 #include <time.h>
29 #else
30 #include <sys/time.h>
31 #endif
32 #include "FLAC/assert.h"
33 #include "FLAC/ordinals.h"
34 #include "share/compat.h"
36 #ifndef M_PI
37 /* math.h in VC++ doesn't seem to have this (how Microsoft is that?) */
38 #define M_PI 3.14159265358979323846
39 #endif
41 #if !defined _MSC_VER && !defined __MINGW32__
42 #define GET_RANDOM_BYTE (((unsigned)random()) & 0xff)
43 #else
44 #define GET_RANDOM_BYTE (((unsigned)rand()) & 0xff)
45 #endif
47 static FLAC__bool is_big_endian_host;
50 static FLAC__bool write_little_endian(FILE *f, FLAC__int32 x, size_t bytes)
52 while(bytes) {
53 if(fputc(x, f) == EOF)
54 return false;
55 x >>= 8;
56 bytes--;
58 return true;
61 static FLAC__bool write_little_endian_uint16(FILE *f, FLAC__uint16 x)
63 return
64 fputc(x, f) != EOF &&
65 fputc(x >> 8, f) != EOF
69 static FLAC__bool write_little_endian_int16(FILE *f, FLAC__int16 x)
71 return write_little_endian_uint16(f, (FLAC__uint16)x);
74 static FLAC__bool write_little_endian_uint24(FILE *f, FLAC__uint32 x)
76 return
77 fputc(x, f) != EOF &&
78 fputc(x >> 8, f) != EOF &&
79 fputc(x >> 16, f) != EOF
83 static FLAC__bool write_little_endian_int24(FILE *f, FLAC__int32 x)
85 return write_little_endian_uint24(f, (FLAC__uint32)x);
88 static FLAC__bool write_little_endian_uint32(FILE *f, FLAC__uint32 x)
90 return
91 fputc(x, f) != EOF &&
92 fputc(x >> 8, f) != EOF &&
93 fputc(x >> 16, f) != EOF &&
94 fputc(x >> 24, f) != EOF
98 #if 0
99 /* @@@ not used (yet) */
100 static FLAC__bool write_little_endian_int32(FILE *f, FLAC__int32 x)
102 return write_little_endian_uint32(f, (FLAC__uint32)x);
104 #endif
106 static FLAC__bool write_little_endian_uint64(FILE *f, FLAC__uint64 x)
108 return
109 fputc(x, f) != EOF &&
110 fputc(x >> 8, f) != EOF &&
111 fputc(x >> 16, f) != EOF &&
112 fputc(x >> 24, f) != EOF &&
113 fputc(x >> 32, f) != EOF &&
114 fputc(x >> 40, f) != EOF &&
115 fputc(x >> 48, f) != EOF &&
116 fputc(x >> 56, f) != EOF
120 static FLAC__bool write_big_endian(FILE *f, FLAC__int32 x, size_t bytes)
122 if(bytes < 4)
123 x <<= 8*(4-bytes);
124 while(bytes) {
125 if(fputc(x>>24, f) == EOF)
126 return false;
127 x <<= 8;
128 bytes--;
130 return true;
133 static FLAC__bool write_big_endian_uint16(FILE *f, FLAC__uint16 x)
135 return
136 fputc(x >> 8, f) != EOF &&
137 fputc(x, f) != EOF
141 #if 0
142 /* @@@ not used (yet) */
143 static FLAC__bool write_big_endian_int16(FILE *f, FLAC__int16 x)
145 return write_big_endian_uint16(f, (FLAC__uint16)x);
147 #endif
149 #if 0
150 /* @@@ not used (yet) */
151 static FLAC__bool write_big_endian_uint24(FILE *f, FLAC__uint32 x)
153 return
154 fputc(x >> 16, f) != EOF &&
155 fputc(x >> 8, f) != EOF &&
156 fputc(x, f) != EOF
159 #endif
161 #if 0
162 /* @@@ not used (yet) */
163 static FLAC__bool write_big_endian_int24(FILE *f, FLAC__int32 x)
165 return write_big_endian_uint24(f, (FLAC__uint32)x);
167 #endif
169 static FLAC__bool write_big_endian_uint32(FILE *f, FLAC__uint32 x)
171 return
172 fputc(x >> 24, f) != EOF &&
173 fputc(x >> 16, f) != EOF &&
174 fputc(x >> 8, f) != EOF &&
175 fputc(x, f) != EOF
179 #if 0
180 /* @@@ not used (yet) */
181 static FLAC__bool write_big_endian_int32(FILE *f, FLAC__int32 x)
183 return write_big_endian_uint32(f, (FLAC__uint32)x);
185 #endif
187 static FLAC__bool write_sane_extended(FILE *f, unsigned val)
188 /* Write to 'f' a SANE extended representation of 'val'. Return false if
189 * the write succeeds; return true otherwise.
191 * SANE extended is an 80-bit IEEE-754 representation with sign bit, 15 bits
192 * of exponent, and 64 bits of significand (mantissa). Unlike most IEEE-754
193 * representations, it does not imply a 1 above the MSB of the significand.
195 * Preconditions:
196 * val!=0U
199 unsigned int shift, exponent;
201 FLAC__ASSERT(val!=0U); /* handling 0 would require a special case */
203 for(shift= 0U; (val>>(31-shift))==0U; ++shift)
205 val<<= shift;
206 exponent= 63U-(shift+32U); /* add 32 for unused second word */
208 if(!write_big_endian_uint16(f, (FLAC__uint16)(exponent+0x3FFF)))
209 return false;
210 if(!write_big_endian_uint32(f, val))
211 return false;
212 if(!write_big_endian_uint32(f, 0)) /* unused second word */
213 return false;
215 return true;
218 /* a mono one-sample 16bps stream */
219 static FLAC__bool generate_01(void)
221 FILE *f;
222 FLAC__int16 x = -32768;
224 if(0 == (f = flac_fopen("test01.raw", "wb")))
225 return false;
227 if(!write_little_endian_int16(f, x))
228 goto foo;
230 fclose(f);
231 return true;
232 foo:
233 fclose(f);
234 return false;
237 /* a stereo one-sample 16bps stream */
238 static FLAC__bool generate_02(void)
240 FILE *f;
241 FLAC__int16 xl = -32768, xr = 32767;
243 if(0 == (f = flac_fopen("test02.raw", "wb")))
244 return false;
246 if(!write_little_endian_int16(f, xl))
247 goto foo;
248 if(!write_little_endian_int16(f, xr))
249 goto foo;
251 fclose(f);
252 return true;
253 foo:
254 fclose(f);
255 return false;
258 /* a mono five-sample 16bps stream */
259 static FLAC__bool generate_03(void)
261 FILE *f;
262 FLAC__int16 x[] = { -25, 0, 25, 50, 100 };
263 unsigned i;
265 if(0 == (f = flac_fopen("test03.raw", "wb")))
266 return false;
268 for(i = 0; i < 5; i++)
269 if(!write_little_endian_int16(f, x[i]))
270 goto foo;
272 fclose(f);
273 return true;
274 foo:
275 fclose(f);
276 return false;
279 /* a stereo five-sample 16bps stream */
280 static FLAC__bool generate_04(void)
282 FILE *f;
283 FLAC__int16 x[] = { -25, 500, 0, 400, 25, 300, 50, 200, 100, 100 };
284 unsigned i;
286 if(0 == (f = flac_fopen("test04.raw", "wb")))
287 return false;
289 for(i = 0; i < 10; i++)
290 if(!write_little_endian_int16(f, x[i]))
291 goto foo;
293 fclose(f);
294 return true;
295 foo:
296 fclose(f);
297 return false;
300 /* a mono full-scale deflection 8bps stream */
301 static FLAC__bool generate_fsd8(const char *fn, const int pattern[], unsigned reps)
303 FILE *f;
304 unsigned rep, p;
306 FLAC__ASSERT(pattern != 0);
308 if(0 == (f = flac_fopen(fn, "wb")))
309 return false;
311 for(rep = 0; rep < reps; rep++) {
312 for(p = 0; pattern[p]; p++) {
313 signed char x = pattern[p] > 0? 127 : -128;
314 if(fwrite(&x, sizeof(x), 1, f) < 1)
315 goto foo;
319 fclose(f);
320 return true;
321 foo:
322 fclose(f);
323 return false;
326 /* a mono full-scale deflection 16bps stream */
327 static FLAC__bool generate_fsd16(const char *fn, const int pattern[], unsigned reps)
329 FILE *f;
330 unsigned rep, p;
332 FLAC__ASSERT(pattern != 0);
334 if(0 == (f = flac_fopen(fn, "wb")))
335 return false;
337 for(rep = 0; rep < reps; rep++) {
338 for(p = 0; pattern[p]; p++) {
339 FLAC__int16 x = pattern[p] > 0? 32767 : -32768;
340 if(!write_little_endian_int16(f, x))
341 goto foo;
345 fclose(f);
346 return true;
347 foo:
348 fclose(f);
349 return false;
352 /* a stereo wasted-bits-per-sample 16bps stream */
353 static FLAC__bool generate_wbps16(const char *fn, unsigned samples)
355 FILE *f;
356 unsigned sample;
358 if(0 == (f = flac_fopen(fn, "wb")))
359 return false;
361 for(sample = 0; sample < samples; sample++) {
362 FLAC__int16 l = (sample % 2000) << 2;
363 FLAC__int16 r = (sample % 1000) << 3;
364 if(!write_little_endian_int16(f, l))
365 goto foo;
366 if(!write_little_endian_int16(f, r))
367 goto foo;
370 fclose(f);
371 return true;
372 foo:
373 fclose(f);
374 return false;
377 /* a mono full-scale deflection 24bps stream */
378 static FLAC__bool generate_fsd24(const char *fn, const int pattern[], unsigned reps)
380 FILE *f;
381 unsigned rep, p;
383 FLAC__ASSERT(pattern != 0);
385 if(0 == (f = flac_fopen(fn, "wb")))
386 return false;
388 for(rep = 0; rep < reps; rep++) {
389 for(p = 0; pattern[p]; p++) {
390 FLAC__int32 x = pattern[p] > 0? 8388607 : -8388608;
391 if(!write_little_endian_int24(f, x))
392 goto foo;
396 fclose(f);
397 return true;
398 foo:
399 fclose(f);
400 return false;
403 /* a mono sine-wave 8bps stream */
404 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)
406 const FLAC__int8 full_scale = 127;
407 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
408 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
409 FILE *f;
410 double theta1, theta2;
411 unsigned i;
413 if(0 == (f = flac_fopen(fn, "wb")))
414 return false;
416 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
417 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
418 FLAC__int8 v = (FLAC__int8)(val + 0.5);
419 if(fwrite(&v, sizeof(v), 1, f) < 1)
420 goto foo;
423 fclose(f);
424 return true;
425 foo:
426 fclose(f);
427 return false;
430 /* a stereo sine-wave 8bps stream */
431 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)
433 const FLAC__int8 full_scale = 127;
434 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
435 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
436 FILE *f;
437 double theta1, theta2;
438 unsigned i;
440 if(0 == (f = flac_fopen(fn, "wb")))
441 return false;
443 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
444 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
445 FLAC__int8 v = (FLAC__int8)(val + 0.5);
446 if(fwrite(&v, sizeof(v), 1, f) < 1)
447 goto foo;
448 val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
449 v = (FLAC__int8)(val + 0.5);
450 if(fwrite(&v, sizeof(v), 1, f) < 1)
451 goto foo;
454 fclose(f);
455 return true;
456 foo:
457 fclose(f);
458 return false;
461 /* a mono sine-wave 16bps stream */
462 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)
464 const FLAC__int16 full_scale = 32767;
465 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
466 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
467 FILE *f;
468 double theta1, theta2;
469 unsigned i;
471 if(0 == (f = flac_fopen(fn, "wb")))
472 return false;
474 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
475 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
476 FLAC__int16 v = (FLAC__int16)(val + 0.5);
477 if(!write_little_endian_int16(f, v))
478 goto foo;
481 fclose(f);
482 return true;
483 foo:
484 fclose(f);
485 return false;
488 /* a stereo sine-wave 16bps stream */
489 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)
491 const FLAC__int16 full_scale = 32767;
492 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
493 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
494 FILE *f;
495 double theta1, theta2;
496 unsigned i;
498 if(0 == (f = flac_fopen(fn, "wb")))
499 return false;
501 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
502 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
503 FLAC__int16 v = (FLAC__int16)(val + 0.5);
504 if(!write_little_endian_int16(f, v))
505 goto foo;
506 val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
507 v = (FLAC__int16)(val + 0.5);
508 if(!write_little_endian_int16(f, v))
509 goto foo;
512 fclose(f);
513 return true;
514 foo:
515 fclose(f);
516 return false;
519 /* a mono sine-wave 24bps stream */
520 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)
522 const FLAC__int32 full_scale = 0x7fffff;
523 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
524 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
525 FILE *f;
526 double theta1, theta2;
527 unsigned i;
529 if(0 == (f = flac_fopen(fn, "wb")))
530 return false;
532 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
533 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
534 FLAC__int32 v = (FLAC__int32)(val + 0.5);
535 if(!write_little_endian_int24(f, v))
536 goto foo;
539 fclose(f);
540 return true;
541 foo:
542 fclose(f);
543 return false;
546 /* a stereo sine-wave 24bps stream */
547 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)
549 const FLAC__int32 full_scale = 0x7fffff;
550 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
551 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
552 FILE *f;
553 double theta1, theta2;
554 unsigned i;
556 if(0 == (f = flac_fopen(fn, "wb")))
557 return false;
559 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
560 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
561 FLAC__int32 v = (FLAC__int32)(val + 0.5);
562 if(!write_little_endian_int24(f, v))
563 goto foo;
564 val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
565 v = (FLAC__int32)(val + 0.5);
566 if(!write_little_endian_int24(f, v))
567 goto foo;
570 fclose(f);
571 return true;
572 foo:
573 fclose(f);
574 return false;
577 static FLAC__bool generate_noise(const char *fn, unsigned bytes)
579 FILE *f;
580 unsigned b;
582 if(0 == (f = flac_fopen(fn, "wb")))
583 return false;
585 for(b = 0; b < bytes; b++) {
586 #if !defined _MSC_VER && !defined __MINGW32__
587 FLAC__byte x = (FLAC__byte)(((unsigned)random()) & 0xff);
588 #else
589 FLAC__byte x = (FLAC__byte)(((unsigned)rand()) & 0xff);
590 #endif
591 if(fwrite(&x, sizeof(x), 1, f) < 1)
592 goto foo;
595 fclose(f);
596 return true;
597 foo:
598 fclose(f);
599 return false;
602 static FLAC__bool generate_raw(const char *filename, unsigned channels, unsigned bytes_per_sample, unsigned samples)
604 const FLAC__int32 full_scale = (1 << (bytes_per_sample*8-1)) - 1;
605 const double f1 = 441.0, a1 = 0.61, f2 = 661.5, a2 = 0.37;
606 const double delta1 = 2.0 * M_PI / ( 44100.0 / f1);
607 const double delta2 = 2.0 * M_PI / ( 44100.0 / f2);
608 double theta1, theta2;
609 FILE *f;
610 unsigned i, j;
612 if(0 == (f = flac_fopen(filename, "wb")))
613 return false;
615 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
616 for(j = 0; j < channels; j++) {
617 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
618 FLAC__int32 v = (FLAC__int32)(val + 0.5) + ((GET_RANDOM_BYTE>>4)-8);
619 if(!write_little_endian(f, v, bytes_per_sample))
620 goto foo;
624 fclose(f);
625 return true;
626 foo:
627 fclose(f);
628 return false;
631 static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsigned channels, unsigned bps, unsigned samples)
633 const unsigned bytes_per_sample = (bps+7)/8;
634 const unsigned true_size = channels * bytes_per_sample * samples;
635 const unsigned padded_size = (true_size + 1) & (~1u);
636 const unsigned shift = (bps%8)? 8 - (bps%8) : 0;
637 const FLAC__int32 full_scale = (1 << (bps-1)) - 1;
638 const double f1 = 441.0, a1 = 0.61, f2 = 661.5, a2 = 0.37;
639 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
640 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
641 double theta1, theta2;
642 FILE *f;
643 unsigned i, j;
645 if(0 == (f = flac_fopen(filename, "wb")))
646 return false;
647 if(fwrite("FORM", 1, 4, f) < 4)
648 goto foo;
649 if(!write_big_endian_uint32(f, padded_size + 46))
650 goto foo;
651 if(fwrite("AIFFCOMM\000\000\000\022", 1, 12, f) < 12)
652 goto foo;
653 if(!write_big_endian_uint16(f, (FLAC__uint16)channels))
654 goto foo;
655 if(!write_big_endian_uint32(f, samples))
656 goto foo;
657 if(!write_big_endian_uint16(f, (FLAC__uint16)bps))
658 goto foo;
659 if(!write_sane_extended(f, sample_rate))
660 goto foo;
661 if(fwrite("SSND", 1, 4, f) < 4)
662 goto foo;
663 if(!write_big_endian_uint32(f, true_size + 8))
664 goto foo;
665 if(fwrite("\000\000\000\000\000\000\000\000", 1, 8, f) < 8)
666 goto foo;
668 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
669 for(j = 0; j < channels; j++) {
670 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
671 FLAC__int32 v = ((FLAC__int32)(val + 0.5) + ((GET_RANDOM_BYTE>>4)-8)) << shift;
672 if(!write_big_endian(f, v, bytes_per_sample))
673 goto foo;
676 for(i = true_size; i < padded_size; i++)
677 if(fputc(0, f) == EOF)
678 goto foo;
680 fclose(f);
681 return true;
682 foo:
683 fclose(f);
684 return false;
687 /* flavor is: 0:WAVE, 1:RF64, 2:WAVE64 */
688 static FLAC__bool generate_wav(const char *filename, unsigned sample_rate, unsigned channels, unsigned bps, unsigned samples, FLAC__bool strict, int flavor)
690 const FLAC__bool waveformatextensible = strict && (channels > 2 || (bps%8));
691 /* ^^^^^^^
692 * (bps%8) allows 24 bps which is technically supposed to be WAVEFORMATEXTENSIBLE but we
693 * write 24bps as WAVEFORMATEX since it's unambiguous and matches how flac writes it
696 const unsigned bytes_per_sample = (bps+7)/8;
697 const unsigned shift = (bps%8)? 8 - (bps%8) : 0;
698 /* this rig is not going over 4G so we're ok with 32-bit sizes here */
699 const FLAC__uint32 true_size = channels * bytes_per_sample * samples;
700 const FLAC__uint32 padded_size = flavor<2? (true_size + 1) & (~1u) : (true_size + 7) & (~7u);
701 const FLAC__int32 full_scale = (1 << (bps-1)) - 1;
702 const double f1 = 441.0, a1 = 0.61, f2 = 661.5, a2 = 0.37;
703 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
704 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
705 double theta1, theta2;
706 FILE *f;
707 unsigned i, j;
709 if(0 == (f = flac_fopen(filename, "wb")))
710 return false;
711 /* RIFFxxxxWAVE or equivalent: */
712 switch(flavor) {
713 case 0:
714 if(fwrite("RIFF", 1, 4, f) < 4)
715 goto foo;
716 /* +4 for WAVE */
717 /* +8+{40,16} for fmt chunk */
718 /* +8 for data chunk header */
719 if(!write_little_endian_uint32(f, 4 + 8+(waveformatextensible?40:16) + 8 + padded_size))
720 goto foo;
721 if(fwrite("WAVE", 1, 4, f) < 4)
722 goto foo;
723 break;
724 case 1:
725 if(fwrite("RF64", 1, 4, f) < 4)
726 goto foo;
727 if(!write_little_endian_uint32(f, 0xffffffff))
728 goto foo;
729 if(fwrite("WAVE", 1, 4, f) < 4)
730 goto foo;
731 break;
732 case 2:
733 /* RIFF GUID 66666972-912E-11CF-A5D6-28DB04C10000 */
734 if(fwrite("\x72\x69\x66\x66\x2E\x91\xCF\x11\xA5\xD6\x28\xDB\x04\xC1\x00\x00", 1, 16, f) < 16)
735 goto foo;
736 /* +(16+8) for RIFF GUID + size */
737 /* +16 for WAVE GUID */
738 /* +16+8+{40,16} for fmt chunk */
739 /* +16+8 for data chunk header */
740 if(!write_little_endian_uint64(f, (16+8) + 16 + 16+8+(waveformatextensible?40:16) + (16+8) + padded_size))
741 goto foo;
742 /* WAVE GUID 65766177-ACF3-11D3-8CD1-00C04F8EDB8A */
743 if(fwrite("\x77\x61\x76\x65\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) < 16)
744 goto foo;
745 break;
746 default:
747 goto foo;
749 if(flavor == 1) { /* rf64 */
750 if(fwrite("ds64", 1, 4, f) < 4)
751 goto foo;
752 if(!write_little_endian_uint32(f, 28)) /* ds64 chunk size */
753 goto foo;
754 if(!write_little_endian_uint64(f, 36 + padded_size + (waveformatextensible?60:36)))
755 goto foo;
756 if(!write_little_endian_uint64(f, true_size))
757 goto foo;
758 if(!write_little_endian_uint64(f, samples))
759 goto foo;
760 if(!write_little_endian_uint32(f, 0)) /* table size */
761 goto foo;
763 /* fmt chunk */
764 if(flavor < 2) {
765 if(fwrite("fmt ", 1, 4, f) < 4)
766 goto foo;
767 /* chunk size */
768 if(!write_little_endian_uint32(f, waveformatextensible?40:16))
769 goto foo;
771 else { /* wave64 */
772 /* fmt GUID 20746D66-ACF3-11D3-8CD1-00C04F8EDB8A */
773 if(fwrite("\x66\x6D\x74\x20\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) < 16)
774 goto foo;
775 /* chunk size (+16+8 for GUID and size fields) */
776 if(!write_little_endian_uint64(f, 16+8+(waveformatextensible?40:16)))
777 goto foo;
779 if(!write_little_endian_uint16(f, (FLAC__uint16)(waveformatextensible?65534:1)))
780 goto foo;
781 if(!write_little_endian_uint16(f, (FLAC__uint16)channels))
782 goto foo;
783 if(!write_little_endian_uint32(f, sample_rate))
784 goto foo;
785 if(!write_little_endian_uint32(f, sample_rate * channels * bytes_per_sample))
786 goto foo;
787 if(!write_little_endian_uint16(f, (FLAC__uint16)(channels * bytes_per_sample))) /* block align */
788 goto foo;
789 if(!write_little_endian_uint16(f, (FLAC__uint16)(bps+shift)))
790 goto foo;
791 if(waveformatextensible) {
792 if(!write_little_endian_uint16(f, (FLAC__uint16)22)) /* cbSize */
793 goto foo;
794 if(!write_little_endian_uint16(f, (FLAC__uint16)bps)) /* validBitsPerSample */
795 goto foo;
796 if(!write_little_endian_uint32(f, 0)) /* channelMask */
797 goto foo;
798 /* GUID = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} */
799 if(fwrite("\x01\x00\x00\x00\x00\x00\x10\x00\x80\x00\x00\xaa\x00\x38\x9b\x71", 1, 16, f) != 16)
800 goto foo;
802 /* data chunk */
803 if(flavor < 2) {
804 if(fwrite("data", 1, 4, f) < 4)
805 goto foo;
806 if(!write_little_endian_uint32(f, flavor==1? 0xffffffff : true_size))
807 goto foo;
809 else { /* wave64 */
810 /* data GUID 61746164-ACF3-11D3-8CD1-00C04F8EDB8A */
811 if(fwrite("\x64\x61\x74\x61\xF3\xAC\xD3\x11\x8C\xD1\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) != 16)
812 goto foo;
813 /* +16+8 for GUID and size fields */
814 if(!write_little_endian_uint64(f, 16+8 + true_size))
815 goto foo;
818 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
819 for(j = 0; j < channels; j++) {
820 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
821 FLAC__int32 v = ((FLAC__int32)(val + 0.5) + ((GET_RANDOM_BYTE>>4)-8)) << shift;
822 if(!write_little_endian(f, v, bytes_per_sample))
823 goto foo;
826 for(i = true_size; i < padded_size; i++)
827 if(fputc(0, f) == EOF)
828 goto foo;
830 fclose(f);
831 return true;
832 foo:
833 fclose(f);
834 return false;
837 static FLAC__bool generate_wackywavs(void)
839 FILE *f;
840 FLAC__byte wav[] = {
841 'R', 'I', 'F', 'F', 76, 0, 0, 0,
842 'W', 'A', 'V', 'E', 'j', 'u', 'n', 'k',
843 4, 0, 0, 0 , 'b', 'l', 'a', 'h',
844 'p', 'a', 'd', ' ', 4, 0, 0, 0,
845 'B', 'L', 'A', 'H', 'f', 'm', 't', ' ',
846 16, 0, 0, 0, 1, 0, 1, 0,
847 0x44,0xAC, 0, 0,0x88,0x58,0x01, 0,
848 2, 0, 16, 0, 'd', 'a', 't', 'a',
849 16, 0, 0, 0, 0, 0, 1, 0,
850 4, 0, 9, 0, 16, 0, 25, 0,
851 36, 0, 49, 0, 'p', 'a', 'd', ' ',
852 4, 0, 0, 0, 'b', 'l', 'a', 'h'
855 if(0 == (f = flac_fopen("wacky1.wav", "wb")))
856 return false;
857 if(fwrite(wav, 1, 84, f) < 84)
858 goto foo;
859 fclose(f);
861 wav[4] += 12;
862 if(0 == (f = flac_fopen("wacky2.wav", "wb")))
863 return false;
864 if(fwrite(wav, 1, 96, f) < 96)
865 goto foo;
866 fclose(f);
868 return true;
869 foo:
870 fclose(f);
871 return false;
874 static FLAC__bool generate_noisy_sine(void)
876 FILE *f;
877 FLAC__byte wav[] = {
878 'R', 'I', 'F', 'F', 76, 0, 0, 0,
879 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ',
880 16, 0, 0, 0, 1, 0, 1, 0,
881 0x44,0xAC, 0, 0,0x88,0x58,0x01, 0,
882 2, 0, 16, 0, 'd', 'a', 't', 'a',
883 0xa8, 0xba, 0x6, 0
885 int32_t randstate = 0x1243456;
886 double sample, last_val = 0.0;
887 int k;
889 if(0 == (f = flac_fopen("noisy-sine.wav", "wb")))
890 return false;
891 if(fwrite(wav, 1, sizeof (wav), f) < sizeof (wav))
892 goto foo;
894 for (k = 0 ; k < 5 * 44100 ; k++) {
895 /* Obvioulsy not a crypto quality RNG. */
896 randstate = 11117 * randstate + 211231;
897 randstate = 11117 * randstate + 211231;
898 randstate = 11117 * randstate + 211231;
900 sample = randstate / (0x7fffffff * 1.000001);
901 sample = 0.2 * sample - 0.9 * last_val;
903 last_val = sample;
905 sample += sin (2.0 * k * M_PI * 1.0 / 32.0);
906 sample *= 0.4;
907 #if !defined _MSC_VER
908 write_little_endian_int16(f, lrintf(sample * 32700.0));
909 #else
910 write_little_endian_int16(f, (FLAC__int16)(sample * 32700.0));
911 #endif
914 fclose(f);
916 return true;
917 foo:
918 fclose(f);
919 return false;
922 static FLAC__bool generate_wackywav64s(void)
924 FILE *f;
925 FLAC__byte wav[] = {
926 0x72,0x69,0x66,0x66,0x2E,0x91,0xCF,0x11, /* RIFF GUID */
927 0xA5,0xD6,0x28,0xDB,0x04,0xC1,0x00,0x00,
928 152, 0, 0, 0, 0, 0, 0, 0,
929 0x77,0x61,0x76,0x65,0xF3,0xAC,0xD3,0x11, /* WAVE GUID */
930 0x8C,0xD1,0x00,0xC0,0x4F,0x8E,0xDB,0x8A,
931 0x6A,0x75,0x6E,0x6B,0xF3,0xAC,0xD3,0x11, /* junk GUID */
932 0x8C,0xD1,0x00,0xC0,0x4F,0x8E,0xDB,0x8A,
933 32, 0, 0, 0 , 0, 0, 0, 0,
934 'b', 'l', 'a', 'h', 'b', 'l', 'a', 'h',
935 0x66,0x6D,0x74,0x20,0xF3,0xAC,0xD3,0x11, /* fmt GUID */
936 0x8C,0xD1,0x00,0xC0,0x4F,0x8E,0xDB,0x8A,
937 40, 0, 0, 0 , 0, 0, 0, 0,
938 1, 0, 1, 0,0x44,0xAC, 0, 0,
939 0x88,0x58,0x01, 0, 2, 0, 16, 0,
940 0x64,0x61,0x74,0x61,0xF3,0xAC,0xD3,0x11, /* data GUID */
941 0x8C,0xD1,0x00,0xC0,0x4F,0x8E,0xDB,0x8A,
942 40, 0, 0, 0 , 0, 0, 0, 0,
943 0, 0, 1, 0, 4, 0, 9, 0,
944 16, 0, 25, 0, 36, 0, 49, 0,
945 0x6A,0x75,0x6E,0x6B,0xF3,0xAC,0xD3,0x11, /* junk GUID */
946 0x8C,0xD1,0x00,0xC0,0x4F,0x8E,0xDB,0x8A,
947 32, 0, 0, 0 , 0, 0, 0, 0,
948 'b', 'l', 'a', 'h', 'b', 'l', 'a', 'h'
951 if(0 == (f = flac_fopen("wacky1.w64", "wb")))
952 return false;
953 if(fwrite(wav, 1, wav[16], f) < wav[16])
954 goto foo;
955 fclose(f);
957 wav[16] += 32;
958 if(0 == (f = flac_fopen("wacky2.w64", "wb")))
959 return false;
960 if(fwrite(wav, 1, wav[16], f) < wav[16])
961 goto foo;
962 fclose(f);
964 return true;
965 foo:
966 fclose(f);
967 return false;
970 static FLAC__bool generate_wackyrf64s(void)
972 FILE *f;
973 FLAC__byte wav[] = {
974 'R', 'F', '6', '4', 255, 255, 255, 255,
975 'W', 'A', 'V', 'E', 'd', 's', '6', '4',
976 28, 0, 0, 0, 112, 0, 0, 0,
977 0, 0, 0, 0, 16, 0, 0, 0,
978 0, 0, 0, 0, 8, 0, 0, 0,
979 0, 0, 0, 0, 0, 0, 0, 0,
980 'j', 'u', 'n', 'k',
981 4, 0, 0, 0, 'b', 'l', 'a', 'h',
982 'p', 'a', 'd', ' ', 4, 0, 0, 0,
983 'B', 'L', 'A', 'H', 'f', 'm', 't', ' ',
984 16, 0, 0, 0, 1, 0, 1, 0,
985 0x44,0xAC, 0, 0,0x88,0x58,0x01, 0,
986 2, 0, 16, 0, 'd', 'a', 't', 'a',
987 255, 255, 255, 255, 0, 0, 1, 0,
988 4, 0, 9, 0, 16, 0, 25, 0,
989 36, 0, 49, 0, 'p', 'a', 'd', ' ',
990 4, 0, 0, 0, 'b', 'l', 'a', 'h'
993 if(0 == (f = flac_fopen("wacky1.rf64", "wb")))
994 return false;
995 if(fwrite(wav, 1, 120, f) < 120)
996 goto foo;
997 fclose(f);
999 wav[20] += 12;
1000 if(0 == (f = flac_fopen("wacky2.rf64", "wb")))
1001 return false;
1002 if(fwrite(wav, 1, 132, f) < 132)
1003 goto foo;
1004 fclose(f);
1006 return true;
1007 foo:
1008 fclose(f);
1009 return false;
1012 int main(int argc, char *argv[])
1014 FLAC__uint32 test = 1;
1015 unsigned channels;
1017 int pattern01[] = { 1, -1, 0 };
1018 int pattern02[] = { 1, 1, -1, 0 };
1019 int pattern03[] = { 1, -1, -1, 0 };
1020 int pattern04[] = { 1, -1, 1, -1, 0 };
1021 int pattern05[] = { 1, -1, -1, 1, 0 };
1022 int pattern06[] = { 1, -1, 1, 1, -1, 0 };
1023 int pattern07[] = { 1, -1, -1, 1, -1, 0 };
1025 (void)argc;
1026 (void)argv;
1027 is_big_endian_host = (*((FLAC__byte*)(&test)))? false : true;
1029 #if !defined _MSC_VER && !defined __MINGW32__
1031 struct timeval tv;
1033 if(gettimeofday(&tv, 0) < 0) {
1034 fprintf(stderr, "WARNING: couldn't seed RNG with time\n");
1035 tv.tv_usec = 4321;
1037 srandom(tv.tv_usec);
1039 #else
1040 srand((unsigned)time(0));
1041 #endif
1043 if(!generate_01()) return 1;
1044 if(!generate_02()) return 1;
1045 if(!generate_03()) return 1;
1046 if(!generate_04()) return 1;
1048 if(!generate_fsd8("fsd8-01.raw", pattern01, 100)) return 1;
1049 if(!generate_fsd8("fsd8-02.raw", pattern02, 100)) return 1;
1050 if(!generate_fsd8("fsd8-03.raw", pattern03, 100)) return 1;
1051 if(!generate_fsd8("fsd8-04.raw", pattern04, 100)) return 1;
1052 if(!generate_fsd8("fsd8-05.raw", pattern05, 100)) return 1;
1053 if(!generate_fsd8("fsd8-06.raw", pattern06, 100)) return 1;
1054 if(!generate_fsd8("fsd8-07.raw", pattern07, 100)) return 1;
1056 if(!generate_fsd16("fsd16-01.raw", pattern01, 100)) return 1;
1057 if(!generate_fsd16("fsd16-02.raw", pattern02, 100)) return 1;
1058 if(!generate_fsd16("fsd16-03.raw", pattern03, 100)) return 1;
1059 if(!generate_fsd16("fsd16-04.raw", pattern04, 100)) return 1;
1060 if(!generate_fsd16("fsd16-05.raw", pattern05, 100)) return 1;
1061 if(!generate_fsd16("fsd16-06.raw", pattern06, 100)) return 1;
1062 if(!generate_fsd16("fsd16-07.raw", pattern07, 100)) return 1;
1064 if(!generate_fsd24("fsd24-01.raw", pattern01, 100)) return 1;
1065 if(!generate_fsd24("fsd24-02.raw", pattern02, 100)) return 1;
1066 if(!generate_fsd24("fsd24-03.raw", pattern03, 100)) return 1;
1067 if(!generate_fsd24("fsd24-04.raw", pattern04, 100)) return 1;
1068 if(!generate_fsd24("fsd24-05.raw", pattern05, 100)) return 1;
1069 if(!generate_fsd24("fsd24-06.raw", pattern06, 100)) return 1;
1070 if(!generate_fsd24("fsd24-07.raw", pattern07, 100)) return 1;
1072 if(!generate_wbps16("wbps16-01.raw", 1000)) return 1;
1074 if(!generate_sine8_1("sine8-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1;
1075 if(!generate_sine8_1("sine8-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1;
1076 if(!generate_sine8_1("sine8-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1;
1077 if(!generate_sine8_1("sine8-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1;
1078 if(!generate_sine8_1("sine8-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
1080 if(!generate_sine8_2("sine8-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
1081 if(!generate_sine8_2("sine8-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
1082 if(!generate_sine8_2("sine8-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
1083 if(!generate_sine8_2("sine8-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
1084 if(!generate_sine8_2("sine8-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
1085 if(!generate_sine8_2("sine8-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
1086 if(!generate_sine8_2("sine8-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
1087 if(!generate_sine8_2("sine8-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
1088 if(!generate_sine8_2("sine8-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
1089 if(!generate_sine8_2("sine8-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
1091 if(!generate_sine16_1("sine16-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1;
1092 if(!generate_sine16_1("sine16-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1;
1093 if(!generate_sine16_1("sine16-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1;
1094 if(!generate_sine16_1("sine16-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1;
1095 if(!generate_sine16_1("sine16-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
1097 if(!generate_sine16_2("sine16-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
1098 if(!generate_sine16_2("sine16-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
1099 if(!generate_sine16_2("sine16-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
1100 if(!generate_sine16_2("sine16-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
1101 if(!generate_sine16_2("sine16-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
1102 if(!generate_sine16_2("sine16-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
1103 if(!generate_sine16_2("sine16-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
1104 if(!generate_sine16_2("sine16-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
1105 if(!generate_sine16_2("sine16-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
1106 if(!generate_sine16_2("sine16-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
1108 if(!generate_sine24_1("sine24-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1;
1109 if(!generate_sine24_1("sine24-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1;
1110 if(!generate_sine24_1("sine24-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1;
1111 if(!generate_sine24_1("sine24-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1;
1112 if(!generate_sine24_1("sine24-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
1114 if(!generate_sine24_2("sine24-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
1115 if(!generate_sine24_2("sine24-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
1116 if(!generate_sine24_2("sine24-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
1117 if(!generate_sine24_2("sine24-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
1118 if(!generate_sine24_2("sine24-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
1119 if(!generate_sine24_2("sine24-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
1120 if(!generate_sine24_2("sine24-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
1121 if(!generate_sine24_2("sine24-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
1122 if(!generate_sine24_2("sine24-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
1123 if(!generate_sine24_2("sine24-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
1125 /* WATCHOUT: the size of noise.raw is hardcoded into test/test_flac.sh */
1126 if(!generate_noise("noise.raw", 65536 * 8 * 3)) return 1;
1127 if(!generate_noise("noise8m32.raw", 32)) return 1;
1128 if(!generate_wackywavs()) return 1;
1129 if(!generate_wackywav64s()) return 1;
1130 if(!generate_wackyrf64s()) return 1;
1131 if(!generate_noisy_sine()) return 1;
1132 for(channels = 1; channels <= 8; channels *= 2) {
1133 unsigned bits_per_sample;
1134 for(bits_per_sample = 8; bits_per_sample <= 24; bits_per_sample += 4) {
1135 static const unsigned nsamples[] = { 1, 111, 4777 } ;
1136 unsigned samples;
1137 for(samples = 0; samples < sizeof(nsamples)/sizeof(nsamples[0]); samples++) {
1138 char fn[64];
1140 flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.aiff", channels, bits_per_sample, nsamples[samples]);
1141 if(!generate_aiff(fn, 44100, channels, bits_per_sample, nsamples[samples]))
1142 return 1;
1144 flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.wav", channels, bits_per_sample, nsamples[samples]);
1145 if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/0))
1146 return 1;
1148 flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.rf64", channels, bits_per_sample, nsamples[samples]);
1149 if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/1))
1150 return 1;
1152 flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.w64", channels, bits_per_sample, nsamples[samples]);
1153 if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/2))
1154 return 1;
1156 if(bits_per_sample % 8 == 0) {
1157 flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.raw", channels, bits_per_sample, nsamples[samples]);
1158 if(!generate_raw(fn, channels, bits_per_sample/8, nsamples[samples]))
1159 return 1;
1165 return 0;