1 /* test_streams - Simple test pattern generator
2 * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007,2008 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
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.
26 #if defined _MSC_VER || defined __MINGW32__
31 #include "FLAC/assert.h"
32 #include "FLAC/ordinals.h"
35 /* math.h in VC++ doesn't seem to have this (how Microsoft is that?) */
36 #define M_PI 3.14159265358979323846
39 #if !defined _MSC_VER && !defined __MINGW32__
40 #define GET_RANDOM_BYTE (((unsigned)random()) & 0xff)
42 #define GET_RANDOM_BYTE (((unsigned)rand()) & 0xff)
45 static FLAC__bool is_big_endian_host;
48 static FLAC__bool write_little_endian(FILE *f, FLAC__int32 x, size_t bytes)
51 if(fputc(x, f) == EOF)
59 static FLAC__bool write_little_endian_uint16(FILE *f, FLAC__uint16 x)
63 fputc(x >> 8, f) != EOF
67 static FLAC__bool write_little_endian_int16(FILE *f, FLAC__int16 x)
69 return write_little_endian_uint16(f, (FLAC__uint16)x);
72 static FLAC__bool write_little_endian_uint24(FILE *f, FLAC__uint32 x)
76 fputc(x >> 8, f) != EOF &&
77 fputc(x >> 16, f) != EOF
81 static FLAC__bool write_little_endian_int24(FILE *f, FLAC__int32 x)
83 return write_little_endian_uint24(f, (FLAC__uint32)x);
86 static FLAC__bool write_little_endian_uint32(FILE *f, FLAC__uint32 x)
90 fputc(x >> 8, f) != EOF &&
91 fputc(x >> 16, f) != EOF &&
92 fputc(x >> 24, f) != EOF
97 /* @@@ not used (yet) */
98 static FLAC__bool write_little_endian_int32(FILE *f, FLAC__int32 x)
100 return write_little_endian_uint32(f, (FLAC__uint32)x);
104 static FLAC__bool write_little_endian_uint64(FILE *f, FLAC__uint64 x)
107 fputc(x, f) != EOF &&
108 fputc(x >> 8, f) != EOF &&
109 fputc(x >> 16, f) != EOF &&
110 fputc(x >> 24, f) != EOF &&
111 fputc(x >> 32, f) != EOF &&
112 fputc(x >> 40, f) != EOF &&
113 fputc(x >> 48, f) != EOF &&
114 fputc(x >> 56, f) != EOF
118 static FLAC__bool write_big_endian(FILE *f, FLAC__int32 x, size_t bytes)
123 if(fputc(x>>24, f) == EOF)
131 static FLAC__bool write_big_endian_uint16(FILE *f, FLAC__uint16 x)
134 fputc(x >> 8, f) != EOF &&
140 /* @@@ not used (yet) */
141 static FLAC__bool write_big_endian_int16(FILE *f, FLAC__int16 x)
143 return write_big_endian_uint16(f, (FLAC__uint16)x);
148 /* @@@ not used (yet) */
149 static FLAC__bool write_big_endian_uint24(FILE *f, FLAC__uint32 x)
152 fputc(x >> 16, f) != EOF &&
153 fputc(x >> 8, f) != EOF &&
160 /* @@@ not used (yet) */
161 static FLAC__bool write_big_endian_int24(FILE *f, FLAC__int32 x)
163 return write_big_endian_uint24(f, (FLAC__uint32)x);
167 static FLAC__bool write_big_endian_uint32(FILE *f, FLAC__uint32 x)
170 fputc(x >> 24, f) != EOF &&
171 fputc(x >> 16, f) != EOF &&
172 fputc(x >> 8, f) != EOF &&
178 /* @@@ not used (yet) */
179 static FLAC__bool write_big_endian_int32(FILE *f, FLAC__int32 x)
181 return write_big_endian_uint32(f, (FLAC__uint32)x);
185 static FLAC__bool write_sane_extended(FILE *f, unsigned val)
186 /* Write to 'f' a SANE extended representation of 'val'. Return false if
187 * the write succeeds; return true otherwise.
189 * SANE extended is an 80-bit IEEE-754 representation with sign bit, 15 bits
190 * of exponent, and 64 bits of significand (mantissa). Unlike most IEEE-754
191 * representations, it does not imply a 1 above the MSB of the significand.
197 unsigned int shift, exponent;
199 FLAC__ASSERT(val!=0U); /* handling 0 would require a special case */
201 for(shift= 0U; (val>>(31-shift))==0U; ++shift)
204 exponent= 63U-(shift+32U); /* add 32 for unused second word */
206 if(!write_big_endian_uint16(f, (FLAC__uint16)(exponent+0x3FFF)))
208 if(!write_big_endian_uint32(f, val))
210 if(!write_big_endian_uint32(f, 0)) /* unused second word */
216 /* a mono one-sample 16bps stream */
217 static FLAC__bool generate_01(void)
220 FLAC__int16 x = -32768;
222 if(0 == (f = fopen("test01.raw", "wb")))
225 if(!write_little_endian_int16(f, x))
235 /* a stereo one-sample 16bps stream */
236 static FLAC__bool generate_02(void)
239 FLAC__int16 xl = -32768, xr = 32767;
241 if(0 == (f = fopen("test02.raw", "wb")))
244 if(!write_little_endian_int16(f, xl))
246 if(!write_little_endian_int16(f, xr))
256 /* a mono five-sample 16bps stream */
257 static FLAC__bool generate_03(void)
260 FLAC__int16 x[] = { -25, 0, 25, 50, 100 };
263 if(0 == (f = fopen("test03.raw", "wb")))
266 for(i = 0; i < 5; i++)
267 if(!write_little_endian_int16(f, x[i]))
277 /* a stereo five-sample 16bps stream */
278 static FLAC__bool generate_04(void)
281 FLAC__int16 x[] = { -25, 500, 0, 400, 25, 300, 50, 200, 100, 100 };
284 if(0 == (f = fopen("test04.raw", "wb")))
287 for(i = 0; i < 10; i++)
288 if(!write_little_endian_int16(f, x[i]))
298 /* a mono full-scale deflection 8bps stream */
299 static FLAC__bool generate_fsd8(const char *fn, const int pattern[], unsigned reps)
304 FLAC__ASSERT(pattern != 0);
306 if(0 == (f = fopen(fn, "wb")))
309 for(rep = 0; rep < reps; rep++) {
310 for(p = 0; pattern[p]; p++) {
311 signed char x = pattern[p] > 0? 127 : -128;
312 if(fwrite(&x, sizeof(x), 1, f) < 1)
324 /* a mono full-scale deflection 16bps stream */
325 static FLAC__bool generate_fsd16(const char *fn, const int pattern[], unsigned reps)
330 FLAC__ASSERT(pattern != 0);
332 if(0 == (f = fopen(fn, "wb")))
335 for(rep = 0; rep < reps; rep++) {
336 for(p = 0; pattern[p]; p++) {
337 FLAC__int16 x = pattern[p] > 0? 32767 : -32768;
338 if(!write_little_endian_int16(f, x))
350 /* a stereo wasted-bits-per-sample 16bps stream */
351 static FLAC__bool generate_wbps16(const char *fn, unsigned samples)
356 if(0 == (f = fopen(fn, "wb")))
359 for(sample = 0; sample < samples; sample++) {
360 FLAC__int16 l = (sample % 2000) << 2;
361 FLAC__int16 r = (sample % 1000) << 3;
362 if(!write_little_endian_int16(f, l))
364 if(!write_little_endian_int16(f, r))
375 /* a mono full-scale deflection 24bps stream */
376 static FLAC__bool generate_fsd24(const char *fn, const int pattern[], unsigned reps)
381 FLAC__ASSERT(pattern != 0);
383 if(0 == (f = fopen(fn, "wb")))
386 for(rep = 0; rep < reps; rep++) {
387 for(p = 0; pattern[p]; p++) {
388 FLAC__int32 x = pattern[p] > 0? 8388607 : -8388608;
389 if(!write_little_endian_int24(f, x))
401 /* a mono sine-wave 8bps stream */
402 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)
404 const FLAC__int8 full_scale = 127;
405 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
406 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
408 double theta1, theta2;
411 if(0 == (f = fopen(fn, "wb")))
414 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
415 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
416 FLAC__int8 v = (FLAC__int8)(val + 0.5);
417 if(fwrite(&v, sizeof(v), 1, f) < 1)
428 /* a stereo sine-wave 8bps stream */
429 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)
431 const FLAC__int8 full_scale = 127;
432 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
433 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
435 double theta1, theta2;
438 if(0 == (f = fopen(fn, "wb")))
441 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
442 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
443 FLAC__int8 v = (FLAC__int8)(val + 0.5);
444 if(fwrite(&v, sizeof(v), 1, f) < 1)
446 val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
447 v = (FLAC__int8)(val + 0.5);
448 if(fwrite(&v, sizeof(v), 1, f) < 1)
459 /* a mono sine-wave 16bps stream */
460 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)
462 const FLAC__int16 full_scale = 32767;
463 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
464 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
466 double theta1, theta2;
469 if(0 == (f = fopen(fn, "wb")))
472 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
473 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
474 FLAC__int16 v = (FLAC__int16)(val + 0.5);
475 if(!write_little_endian_int16(f, v))
486 /* a stereo sine-wave 16bps stream */
487 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)
489 const FLAC__int16 full_scale = 32767;
490 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
491 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
493 double theta1, theta2;
496 if(0 == (f = fopen(fn, "wb")))
499 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
500 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
501 FLAC__int16 v = (FLAC__int16)(val + 0.5);
502 if(!write_little_endian_int16(f, v))
504 val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
505 v = (FLAC__int16)(val + 0.5);
506 if(!write_little_endian_int16(f, v))
517 /* a mono sine-wave 24bps stream */
518 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)
520 const FLAC__int32 full_scale = 0x7fffff;
521 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
522 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
524 double theta1, theta2;
527 if(0 == (f = fopen(fn, "wb")))
530 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
531 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
532 FLAC__int32 v = (FLAC__int32)(val + 0.5);
533 if(!write_little_endian_int24(f, v))
544 /* a stereo sine-wave 24bps stream */
545 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)
547 const FLAC__int32 full_scale = 0x7fffff;
548 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
549 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
551 double theta1, theta2;
554 if(0 == (f = fopen(fn, "wb")))
557 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
558 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
559 FLAC__int32 v = (FLAC__int32)(val + 0.5);
560 if(!write_little_endian_int24(f, v))
562 val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
563 v = (FLAC__int32)(val + 0.5);
564 if(!write_little_endian_int24(f, v))
575 static FLAC__bool generate_noise(const char *fn, unsigned bytes)
580 if(0 == (f = fopen(fn, "wb")))
583 for(b = 0; b < bytes; b++) {
584 #if !defined _MSC_VER && !defined __MINGW32__
585 FLAC__byte x = (FLAC__byte)(((unsigned)random()) & 0xff);
587 FLAC__byte x = (FLAC__byte)(((unsigned)rand()) & 0xff);
589 if(fwrite(&x, sizeof(x), 1, f) < 1)
600 static FLAC__bool generate_raw(const char *filename, unsigned channels, unsigned bytes_per_sample, unsigned samples)
602 const FLAC__int32 full_scale = (1 << (bytes_per_sample*8-1)) - 1;
603 const double f1 = 441.0, a1 = 0.61, f2 = 661.5, a2 = 0.37;
604 const double delta1 = 2.0 * M_PI / ( 44100.0 / f1);
605 const double delta2 = 2.0 * M_PI / ( 44100.0 / f2);
606 double theta1, theta2;
610 if(0 == (f = fopen(filename, "wb")))
613 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
614 for(j = 0; j < channels; j++) {
615 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
616 FLAC__int32 v = (FLAC__int32)(val + 0.5) + ((GET_RANDOM_BYTE>>4)-8);
617 if(!write_little_endian(f, v, bytes_per_sample))
629 static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsigned channels, unsigned bps, unsigned samples)
631 const unsigned bytes_per_sample = (bps+7)/8;
632 const unsigned true_size = channels * bytes_per_sample * samples;
633 const unsigned padded_size = (true_size + 1) & (~1u);
634 const unsigned shift = (bps%8)? 8 - (bps%8) : 0;
635 const FLAC__int32 full_scale = (1 << (bps-1)) - 1;
636 const double f1 = 441.0, a1 = 0.61, f2 = 661.5, a2 = 0.37;
637 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
638 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
639 double theta1, theta2;
643 if(0 == (f = fopen(filename, "wb")))
645 if(fwrite("FORM", 1, 4, f) < 4)
647 if(!write_big_endian_uint32(f, padded_size + 46))
649 if(fwrite("AIFFCOMM\000\000\000\022", 1, 12, f) < 12)
651 if(!write_big_endian_uint16(f, (FLAC__uint16)channels))
653 if(!write_big_endian_uint32(f, samples))
655 if(!write_big_endian_uint16(f, (FLAC__uint16)bps))
657 if(!write_sane_extended(f, sample_rate))
659 if(fwrite("SSND", 1, 4, f) < 4)
661 if(!write_big_endian_uint32(f, true_size + 8))
663 if(fwrite("\000\000\000\000\000\000\000\000", 1, 8, f) < 8)
666 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
667 for(j = 0; j < channels; j++) {
668 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
669 FLAC__int32 v = ((FLAC__int32)(val + 0.5) + ((GET_RANDOM_BYTE>>4)-8)) << shift;
670 if(!write_big_endian(f, v, bytes_per_sample))
674 for(i = true_size; i < padded_size; i++)
675 if(fputc(0, f) == EOF)
685 /* flavor is: 0:WAVE, 1:RF64, 2:WAVE64 */
686 static FLAC__bool generate_wav(const char *filename, unsigned sample_rate, unsigned channels, unsigned bps, unsigned samples, FLAC__bool strict, int flavor)
688 const FLAC__bool waveformatextensible = strict && (channels > 2 || (bps%8));
690 * (bps%8) allows 24 bps which is technically supposed to be WAVEFORMATEXTENSIBLE but we
691 * write 24bps as WAVEFORMATEX since it's unambiguous and matches how flac writes it
694 const unsigned bytes_per_sample = (bps+7)/8;
695 const unsigned shift = (bps%8)? 8 - (bps%8) : 0;
696 /* this rig is not going over 4G so we're ok with 32-bit sizes here */
697 const FLAC__uint32 true_size = channels * bytes_per_sample * samples;
698 const FLAC__uint32 padded_size = flavor<2? (true_size + 1) & (~1u) : (true_size + 7) & (~7u);
699 const FLAC__int32 full_scale = (1 << (bps-1)) - 1;
700 const double f1 = 441.0, a1 = 0.61, f2 = 661.5, a2 = 0.37;
701 const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
702 const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
703 double theta1, theta2;
707 if(0 == (f = fopen(filename, "wb")))
709 /* RIFFxxxxWAVE or equivalent: */
712 if(fwrite("RIFF", 1, 4, f) < 4)
715 /* +8+{40,16} for fmt chunk */
716 /* +8 for data chunk header */
717 if(!write_little_endian_uint32(f, 4 + 8+(waveformatextensible?40:16) + 8 + padded_size))
719 if(fwrite("WAVE", 1, 4, f) < 4)
723 if(fwrite("RF64", 1, 4, f) < 4)
725 if(!write_little_endian_uint32(f, 0xffffffff))
727 if(fwrite("WAVE", 1, 4, f) < 4)
731 /* RIFF GUID 66666972-912E-11CF-A5D6-28DB04C10000 */
732 if(fwrite("\x72\x69\x66\x66\x2E\x91\xCF\x11\xD6\xA5\x28\xDB\x04\xC1\x00\x00", 1, 16, f) < 16)
734 /* +(16+8) for RIFF GUID + size */
735 /* +16 for WAVE GUID */
736 /* +16+8+{40,16} for fmt chunk */
737 /* +16+8 for data chunk header */
738 if(!write_little_endian_uint64(f, (16+8) + 16 + 16+8+(waveformatextensible?40:16) + (16+8) + padded_size))
740 /* WAVE GUID 65766177-ACF3-11D3-8CD1-00C04F8EDB8A */
741 if(fwrite("\x77\x61\x76\x65\xF3\xAC\xD3\x11\xD1\x8C\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) < 16)
747 if(flavor == 1) { /* rf64 */
748 if(fwrite("ds64", 1, 4, f) < 4)
750 if(!write_little_endian_uint32(f, 28)) /* ds64 chunk size */
752 if(!write_little_endian_uint64(f, 36 + padded_size + (waveformatextensible?60:36)))
754 if(!write_little_endian_uint64(f, true_size))
756 if(!write_little_endian_uint64(f, samples))
758 if(!write_little_endian_uint32(f, 0)) /* table size */
763 if(fwrite("fmt ", 1, 4, f) < 4)
766 if(!write_little_endian_uint32(f, waveformatextensible?40:16))
770 /* fmt GUID 20746D66-ACF3-11D3-8CD1-00C04F8EDB8A */
771 if(fwrite("\x66\x6D\x74\x20\xF3\xAC\xD3\x11\xD1\x8C\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) < 16)
773 /* chunk size (+16+8 for GUID and size fields) */
774 if(!write_little_endian_uint64(f, 16+8+(waveformatextensible?40:16)))
777 if(!write_little_endian_uint16(f, (FLAC__uint16)(waveformatextensible?65534:1)))
779 if(!write_little_endian_uint16(f, (FLAC__uint16)channels))
781 if(!write_little_endian_uint32(f, sample_rate))
783 if(!write_little_endian_uint32(f, sample_rate * channels * bytes_per_sample))
785 if(!write_little_endian_uint16(f, (FLAC__uint16)(channels * bytes_per_sample))) /* block align */
787 if(!write_little_endian_uint16(f, (FLAC__uint16)(bps+shift)))
789 if(waveformatextensible) {
790 if(!write_little_endian_uint16(f, (FLAC__uint16)22)) /* cbSize */
792 if(!write_little_endian_uint16(f, (FLAC__uint16)bps)) /* validBitsPerSample */
794 if(!write_little_endian_uint32(f, 0)) /* channelMask */
796 /* GUID = {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} */
797 if(fwrite("\x01\x00\x00\x00\x00\x00\x10\x00\x80\x00\x00\xaa\x00\x38\x9b\x71", 1, 16, f) != 16)
802 if(fwrite("data", 1, 4, f) < 4)
804 if(!write_little_endian_uint32(f, flavor==1? 0xffffffff : true_size))
808 /* data GUID 61746164-ACF3-11D3-8CD1-00C04F8EDB8A */
809 if(fwrite("\x64\x61\x74\x61\xF3\xAC\xD3\x11\xD1\x8C\x00\xC0\x4F\x8E\xDB\x8A", 1, 16, f) != 16)
811 /* +16+8 for GUID and size fields */
812 if(!write_little_endian_uint64(f, 16+8 + true_size))
816 for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
817 for(j = 0; j < channels; j++) {
818 double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
819 FLAC__int32 v = ((FLAC__int32)(val + 0.5) + ((GET_RANDOM_BYTE>>4)-8)) << shift;
820 if(!write_little_endian(f, v, bytes_per_sample))
824 for(i = true_size; i < padded_size; i++)
825 if(fputc(0, f) == EOF)
835 static FLAC__bool generate_wackywavs(void)
839 'R', 'I', 'F', 'F', 76, 0, 0, 0,
840 'W', 'A', 'V', 'E', 'j', 'u', 'n', 'k',
841 4, 0, 0, 0 , 'b', 'l', 'a', 'h',
842 'p', 'a', 'd', ' ', 4, 0, 0, 0,
843 'B', 'L', 'A', 'H', 'f', 'm', 't', ' ',
844 16, 0, 0, 0, 1, 0, 1, 0,
845 0x44,0xAC, 0, 0,0x88,0x58,0x01, 0,
846 2, 0, 16, 0, 'd', 'a', 't', 'a',
847 16, 0, 0, 0, 0, 0, 1, 0,
848 4, 0, 9, 0, 16, 0, 25, 0,
849 36, 0, 49, 0, 'p', 'a', 'd', ' ',
850 4, 0, 0, 0, 'b', 'l', 'a', 'h'
853 if(0 == (f = fopen("wacky1.wav", "wb")))
855 if(fwrite(wav, 1, 84, f) < 84)
860 if(0 == (f = fopen("wacky2.wav", "wb")))
862 if(fwrite(wav, 1, 96, f) < 96)
872 static FLAC__bool generate_wackywav64s(void)
876 0x72,0x69,0x66,0x66,0x2E,0x91,0xCF,0x11, /* RIFF GUID */
877 0xD6,0xA5,0x28,0xDB,0x04,0xC1,0x00,0x00,
878 152, 0, 0, 0, 0, 0, 0, 0,
879 0x77,0x61,0x76,0x65,0xF3,0xAC,0xD3,0x11, /* WAVE GUID */
880 0xD1,0x8C,0x00,0xC0,0x4F,0x8E,0xDB,0x8A,
881 0x6A,0x75,0x6E,0x6B,0xF3,0xAC,0xD3,0x11, /* junk GUID */
882 0xD1,0x8C,0x00,0xC0,0x4F,0x8E,0xDB,0x8A,
883 32, 0, 0, 0 , 0, 0, 0, 0,
884 'b', 'l', 'a', 'h', 'b', 'l', 'a', 'h',
885 0x66,0x6D,0x74,0x20,0xF3,0xAC,0xD3,0x11, /* fmt GUID */
886 0xD1,0x8C,0x00,0xC0,0x4F,0x8E,0xDB,0x8A,
887 40, 0, 0, 0 , 0, 0, 0, 0,
888 1, 0, 1, 0,0x44,0xAC, 0, 0,
889 0x88,0x58,0x01, 0, 2, 0, 16, 0,
890 0x64,0x61,0x74,0x61,0xF3,0xAC,0xD3,0x11, /* data GUID */
891 0xD1,0x8C,0x00,0xC0,0x4F,0x8E,0xDB,0x8A,
892 40, 0, 0, 0 , 0, 0, 0, 0,
893 0, 0, 1, 0, 4, 0, 9, 0,
894 16, 0, 25, 0, 36, 0, 49, 0,
895 0x6A,0x75,0x6E,0x6B,0xF3,0xAC,0xD3,0x11, /* junk GUID */
896 0xD1,0x8C,0x00,0xC0,0x4F,0x8E,0xDB,0x8A,
897 32, 0, 0, 0 , 0, 0, 0, 0,
898 'b', 'l', 'a', 'h', 'b', 'l', 'a', 'h'
901 if(0 == (f = fopen("wacky1.w64", "wb")))
903 if(fwrite(wav, 1, wav[16], f) < wav[16])
908 if(0 == (f = fopen("wacky2.w64", "wb")))
910 if(fwrite(wav, 1, wav[16], f) < wav[16])
920 static FLAC__bool generate_wackyrf64s(void)
924 'R', 'F', '6', '4', 255, 255, 255, 255,
925 'W', 'A', 'V', 'E', 'd', 's', '6', '4',
926 28, 0, 0, 0, 112, 0, 0, 0,
927 0, 0, 0, 0, 16, 0, 0, 0,
928 0, 0, 0, 0, 8, 0, 0, 0,
929 0, 0, 0, 0, 0, 0, 0, 0,
931 4, 0, 0, 0, 'b', 'l', 'a', 'h',
932 'p', 'a', 'd', ' ', 4, 0, 0, 0,
933 'B', 'L', 'A', 'H', 'f', 'm', 't', ' ',
934 16, 0, 0, 0, 1, 0, 1, 0,
935 0x44,0xAC, 0, 0,0x88,0x58,0x01, 0,
936 2, 0, 16, 0, 'd', 'a', 't', 'a',
937 255, 255, 255, 255, 0, 0, 1, 0,
938 4, 0, 9, 0, 16, 0, 25, 0,
939 36, 0, 49, 0, 'p', 'a', 'd', ' ',
940 4, 0, 0, 0, 'b', 'l', 'a', 'h'
943 if(0 == (f = fopen("wacky1.rf64", "wb")))
945 if(fwrite(wav, 1, 120, f) < 120)
950 if(0 == (f = fopen("wacky2.rf64", "wb")))
952 if(fwrite(wav, 1, 132, f) < 132)
962 int main(int argc, char *argv[])
964 FLAC__uint32 test = 1;
967 int pattern01[] = { 1, -1, 0 };
968 int pattern02[] = { 1, 1, -1, 0 };
969 int pattern03[] = { 1, -1, -1, 0 };
970 int pattern04[] = { 1, -1, 1, -1, 0 };
971 int pattern05[] = { 1, -1, -1, 1, 0 };
972 int pattern06[] = { 1, -1, 1, 1, -1, 0 };
973 int pattern07[] = { 1, -1, -1, 1, -1, 0 };
977 is_big_endian_host = (*((FLAC__byte*)(&test)))? false : true;
979 #if !defined _MSC_VER && !defined __MINGW32__
983 if(gettimeofday(&tv, 0) < 0) {
984 fprintf(stderr, "WARNING: couldn't seed RNG with time\n");
990 srand((unsigned)time(0));
993 if(!generate_01()) return 1;
994 if(!generate_02()) return 1;
995 if(!generate_03()) return 1;
996 if(!generate_04()) return 1;
998 if(!generate_fsd8("fsd8-01.raw", pattern01, 100)) return 1;
999 if(!generate_fsd8("fsd8-02.raw", pattern02, 100)) return 1;
1000 if(!generate_fsd8("fsd8-03.raw", pattern03, 100)) return 1;
1001 if(!generate_fsd8("fsd8-04.raw", pattern04, 100)) return 1;
1002 if(!generate_fsd8("fsd8-05.raw", pattern05, 100)) return 1;
1003 if(!generate_fsd8("fsd8-06.raw", pattern06, 100)) return 1;
1004 if(!generate_fsd8("fsd8-07.raw", pattern07, 100)) return 1;
1006 if(!generate_fsd16("fsd16-01.raw", pattern01, 100)) return 1;
1007 if(!generate_fsd16("fsd16-02.raw", pattern02, 100)) return 1;
1008 if(!generate_fsd16("fsd16-03.raw", pattern03, 100)) return 1;
1009 if(!generate_fsd16("fsd16-04.raw", pattern04, 100)) return 1;
1010 if(!generate_fsd16("fsd16-05.raw", pattern05, 100)) return 1;
1011 if(!generate_fsd16("fsd16-06.raw", pattern06, 100)) return 1;
1012 if(!generate_fsd16("fsd16-07.raw", pattern07, 100)) return 1;
1014 if(!generate_fsd24("fsd24-01.raw", pattern01, 100)) return 1;
1015 if(!generate_fsd24("fsd24-02.raw", pattern02, 100)) return 1;
1016 if(!generate_fsd24("fsd24-03.raw", pattern03, 100)) return 1;
1017 if(!generate_fsd24("fsd24-04.raw", pattern04, 100)) return 1;
1018 if(!generate_fsd24("fsd24-05.raw", pattern05, 100)) return 1;
1019 if(!generate_fsd24("fsd24-06.raw", pattern06, 100)) return 1;
1020 if(!generate_fsd24("fsd24-07.raw", pattern07, 100)) return 1;
1022 if(!generate_wbps16("wbps16-01.raw", 1000)) return 1;
1024 if(!generate_sine8_1("sine8-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1;
1025 if(!generate_sine8_1("sine8-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1;
1026 if(!generate_sine8_1("sine8-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1;
1027 if(!generate_sine8_1("sine8-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1;
1028 if(!generate_sine8_1("sine8-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
1030 if(!generate_sine8_2("sine8-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
1031 if(!generate_sine8_2("sine8-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
1032 if(!generate_sine8_2("sine8-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
1033 if(!generate_sine8_2("sine8-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
1034 if(!generate_sine8_2("sine8-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
1035 if(!generate_sine8_2("sine8-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
1036 if(!generate_sine8_2("sine8-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
1037 if(!generate_sine8_2("sine8-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
1038 if(!generate_sine8_2("sine8-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
1039 if(!generate_sine8_2("sine8-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
1041 if(!generate_sine16_1("sine16-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1;
1042 if(!generate_sine16_1("sine16-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1;
1043 if(!generate_sine16_1("sine16-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1;
1044 if(!generate_sine16_1("sine16-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1;
1045 if(!generate_sine16_1("sine16-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
1047 if(!generate_sine16_2("sine16-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
1048 if(!generate_sine16_2("sine16-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
1049 if(!generate_sine16_2("sine16-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
1050 if(!generate_sine16_2("sine16-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
1051 if(!generate_sine16_2("sine16-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
1052 if(!generate_sine16_2("sine16-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
1053 if(!generate_sine16_2("sine16-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
1054 if(!generate_sine16_2("sine16-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
1055 if(!generate_sine16_2("sine16-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
1056 if(!generate_sine16_2("sine16-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
1058 if(!generate_sine24_1("sine24-00.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49)) return 1;
1059 if(!generate_sine24_1("sine24-01.raw", 96000.0, 200000, 441.0, 0.61, 661.5, 0.37)) return 1;
1060 if(!generate_sine24_1("sine24-02.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49)) return 1;
1061 if(!generate_sine24_1("sine24-03.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49)) return 1;
1062 if(!generate_sine24_1("sine24-04.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
1064 if(!generate_sine24_2("sine24-10.raw", 48000.0, 200000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
1065 if(!generate_sine24_2("sine24-11.raw", 48000.0, 200000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
1066 if(!generate_sine24_2("sine24-12.raw", 96000.0, 200000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
1067 if(!generate_sine24_2("sine24-13.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
1068 if(!generate_sine24_2("sine24-14.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
1069 if(!generate_sine24_2("sine24-15.raw", 44100.0, 200000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
1070 if(!generate_sine24_2("sine24-16.raw", 44100.0, 200000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
1071 if(!generate_sine24_2("sine24-17.raw", 44100.0, 200000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
1072 if(!generate_sine24_2("sine24-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
1073 if(!generate_sine24_2("sine24-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
1075 /* WATCHOUT: the size of noise.raw is hardcoded into test/test_flac.sh */
1076 if(!generate_noise("noise.raw", 65536 * 8 * 3)) return 1;
1077 if(!generate_noise("noise8m32.raw", 32)) return 1;
1078 if(!generate_wackywavs()) return 1;
1079 if(!generate_wackywav64s()) return 1;
1080 if(!generate_wackyrf64s()) return 1;
1081 for(channels = 1; channels <= 8; channels++) {
1082 unsigned bits_per_sample;
1083 for(bits_per_sample = 4; bits_per_sample <= 24; bits_per_sample++) {
1084 static const unsigned nsamples[] = { 1, 111, 4777 } ;
1086 for(samples = 0; samples < sizeof(nsamples)/sizeof(nsamples[0]); samples++) {
1089 sprintf(fn, "rt-%u-%u-%u.aiff", channels, bits_per_sample, nsamples[samples]);
1090 if(!generate_aiff(fn, 44100, channels, bits_per_sample, nsamples[samples]))
1093 sprintf(fn, "rt-%u-%u-%u.wav", channels, bits_per_sample, nsamples[samples]);
1094 if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/0))
1097 sprintf(fn, "rt-%u-%u-%u.rf64", channels, bits_per_sample, nsamples[samples]);
1098 if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/1))
1101 sprintf(fn, "rt-%u-%u-%u.w64", channels, bits_per_sample, nsamples[samples]);
1102 if(!generate_wav(fn, 44100, channels, bits_per_sample, nsamples[samples], /*strict=*/true, /*flavor=*/2))
1105 if(bits_per_sample % 8 == 0) {
1106 sprintf(fn, "rt-%u-%u-%u.raw", channels, bits_per_sample, nsamples[samples]);
1107 if(!generate_raw(fn, channels, bits_per_sample/8, nsamples[samples]))