From 8def87a3e20ea9e3c7f88dd663797b18569a0a6c Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Sat, 7 Oct 2006 01:20:38 +0000 Subject: [PATCH] expand round-trip tests to include odd bits per sample (all 4<=bps<=24) --- src/test_streams/main.c | 81 +++++++++++++++++++++++++++++-------------------- test/test_flac.sh | 13 ++++---- 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/src/test_streams/main.c b/src/test_streams/main.c index 6685ecf..89939d0 100644 --- a/src/test_streams/main.c +++ b/src/test_streams/main.c @@ -42,6 +42,12 @@ static const char *mode = "w"; #endif +#if !defined _MSC_VER && !defined __MINGW32__ +#define GET_RANDOM_BYTE (((unsigned)random()) & 0xff) +#else +#define GET_RANDOM_BYTE (((unsigned)rand()) & 0xff) +#endif + static FLAC__bool is_big_endian_host; @@ -538,17 +544,6 @@ static FLAC__bool generate_noise(const char *fn, unsigned bytes) { FILE *f; unsigned b; -#if !defined _MSC_VER && !defined __MINGW32__ - struct timeval tv; - - if(gettimeofday(&tv, 0) < 0) { - fprintf(stderr, "WARNING: couldn't seed RNG with time\n"); - tv.tv_usec = 4321; - } - srandom(tv.tv_usec); -#else - srand(time(0)); -#endif if(0 == (f = fopen(fn, mode))) return false; @@ -570,10 +565,11 @@ foo: return false; } -static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsigned channels, unsigned bytes_per_sample, unsigned samples) +static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsigned channels, unsigned bps, unsigned samples) { - const unsigned true_size = channels * bytes_per_sample * samples; + const unsigned true_size = channels * ((bps+7)/8) * samples; const unsigned padded_size = (true_size + 1) & (~1u); + const unsigned shift = 8 - (bps%8); FILE *f; unsigned i; @@ -589,7 +585,7 @@ static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsi goto foo; if(!write_big_endian_uint32(f, samples)) goto foo; - if(!write_big_endian_uint16(f, (FLAC__uint16)(8 * bytes_per_sample))) + if(!write_big_endian_uint16(f, (FLAC__uint16)bps)) goto foo; if(!write_sane_extended(f, sample_rate)) goto foo; @@ -601,7 +597,7 @@ static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsi goto foo; for(i = 0; i < true_size; i++) - if(fputc(i, f) == EOF) + if(fputc(GET_RANDOM_BYTE< 2; - const unsigned true_size = channels * bytes_per_sample * samples; + const FLAC__bool waveformatextensible = strict && (channels > 2 || (bps%8)); + /* ^^^^^^^ + * (bps%8) allows 24 bps which is technically supposed to be WAVEFORMATEXTENSIBLE but we + * write 24bps as WAVEFORMATEX since it's unambiguous and matches how flac writes it + */ + const unsigned true_size = channels * ((bps+7)/8) * samples; const unsigned padded_size = (true_size + 1) & (~1u); + const unsigned shift = (bps%8)? 8 - (bps%8) : 0; FILE *f; unsigned i; @@ -638,16 +639,16 @@ static FLAC__bool generate_wav(const char *filename, unsigned sample_rate, unsig goto foo; if(!write_little_endian_uint32(f, sample_rate)) goto foo; - if(!write_little_endian_uint32(f, sample_rate * channels * bytes_per_sample)) + if(!write_little_endian_uint32(f, sample_rate * channels * ((bps+7)/8))) goto foo; - if(!write_little_endian_uint16(f, (FLAC__uint16)(channels * bytes_per_sample))) /* block align */ + if(!write_little_endian_uint16(f, (FLAC__uint16)(channels * ((bps+7)/8)))) /* block align */ goto foo; - if(!write_little_endian_uint16(f, (FLAC__uint16)(8 * bytes_per_sample))) + if(!write_little_endian_uint16(f, (FLAC__uint16)(bps+shift))) goto foo; if(waveformatextensible) { if(!write_little_endian_uint16(f, (FLAC__uint16)22)) /* cbSize */ goto foo; - if(!write_little_endian_uint16(f, (FLAC__uint16)(8 * bytes_per_sample))) /* validBitsPerSample */ + if(!write_little_endian_uint16(f, (FLAC__uint16)bps)) /* validBitsPerSample */ goto foo; if(!write_little_endian_uint32(f, 0)) /* channelMask */ goto foo; @@ -661,7 +662,7 @@ static FLAC__bool generate_wav(const char *filename, unsigned sample_rate, unsig goto foo; for(i = 0; i < true_size; i++) - if(fputc(i, f) == EOF) + if(fputc(GET_RANDOM_BYTE<flac->flac->wav) encode... " - run_flac $SILENT --force --verify --channel-map=none $f -o rt.flac || die "ERROR" + run_flac $SILENT --force --verify --channel-map=none --lax -o rt.flac $f || die "ERROR" echo -n "re-encode... " - run_flac $SILENT --force --verify -o rt2.flac rt.flac || die "ERROR" + run_flac $SILENT --force --verify --lax -o rt2.flac rt.flac || die "ERROR" echo -n "decode... " run_flac $SILENT --force --decode --channel-map=none -o rt.wav rt2.flac || die "ERROR" echo -n "compare... " -- 2.7.4