From f6237c8c3b594b45e456fff261f0b1fccd3b23d5 Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Wed, 28 Feb 2001 23:43:29 +0000 Subject: [PATCH] add support for new 24-bit streams --- src/test_streams/main.c | 170 ++++++++++++++++++++++++++++++++++++++++++------ test/test_streams.sh | 46 +++++++------ 2 files changed, 177 insertions(+), 39 deletions(-) diff --git a/src/test_streams/main.c b/src/test_streams/main.c index c84bbb6..3b7b4c6 100644 --- a/src/test_streams/main.c +++ b/src/test_streams/main.c @@ -41,6 +41,20 @@ static void swap16(int16 *i) } } +static void swap24(byte *x) +{ + if(is_big_endian_host) { + x[0] = x[1]; + x[1] = x[2]; + x[2] = x[3]; + } + else { + byte b = x[0]; + x[0] = x[2]; + x[2] = b; + } +} + /* a mono one-sample 16bps stream */ static bool generate_01() { @@ -184,10 +198,38 @@ foo: return false; } +/* a mono full-scale deflection 24bps stream */ +static bool generate_fsd24(const char *fn, const int pattern[], unsigned reps) +{ + FILE *f; + unsigned rep, p; + + assert(pattern != 0); + + if(0 == (f = fopen(fn, mode))) + return false; + + for(rep = 0; rep < reps; rep++) { + for(p = 0; pattern[p]; p++) { + int32 x = pattern[p] > 0? 8388607 : -8388608; + byte *b = (byte*)(&x); + swap24(b); + if(fwrite(b, 3, 1, f) < 1) + goto foo; + } + } + + fclose(f); + return true; +foo: + fclose(f); + return false; +} + /* a mono sine-wave 16bps stream */ static 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) { - const signed short full_scale = 32767; + const int16 full_scale = 32767; const double delta1 = 2.0 * M_PI / ( sample_rate / f1); const double delta2 = 2.0 * M_PI / ( sample_rate / f2); FILE *f; @@ -215,7 +257,7 @@ foo: /* a stereo sine-wave 16bps stream */ static 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) { - const signed short full_scale = 32767; + const int16 full_scale = 32767; const double delta1 = 2.0 * M_PI / ( sample_rate / f1); const double delta2 = 2.0 * M_PI / ( sample_rate / f2); FILE *f; @@ -245,6 +287,69 @@ foo: return false; } +/* a mono sine-wave 24bps stream */ +static 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) +{ + const int32 full_scale = 0x7fffff; + const double delta1 = 2.0 * M_PI / ( sample_rate / f1); + const double delta2 = 2.0 * M_PI / ( sample_rate / f2); + FILE *f; + double theta1, theta2; + unsigned i; + + if(0 == (f = fopen(fn, mode))) + return false; + + for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { + double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; + int32 v = (int32)(val + 0.5); + byte *b = (byte*)(&v); + swap24(b); + if(fwrite(b, 3, 1, f) < 1) + goto foo; + } + + fclose(f); + return true; +foo: + fclose(f); + return false; +} + +/* a stereo sine-wave 24bps stream */ +static 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) +{ + const int32 full_scale = 0x7fffff; + const double delta1 = 2.0 * M_PI / ( sample_rate / f1); + const double delta2 = 2.0 * M_PI / ( sample_rate / f2); + FILE *f; + double theta1, theta2; + unsigned i; + + if(0 == (f = fopen(fn, mode))) + return false; + + for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) { + double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; + int32 v = (int32)(val + 0.5); + byte *b = (byte*)(&v); + swap24(b); + if(fwrite(b, 3, 1, f) < 1) + goto foo; + val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale; + v = (int32)(val + 0.5); + swap24(b); + if(fwrite(b, 3, 1, f) < 1) + goto foo; + } + + fclose(f); + return true; +foo: + fclose(f); + return false; +} + static bool generate_noise(const char *fn, unsigned bytes) { FILE *f; @@ -310,24 +415,49 @@ int main(int argc, char *argv[]) if(!generate_fsd16("fsd16-06.raw", pattern06, 100)) return 1; if(!generate_fsd16("fsd16-07.raw", pattern07, 100)) return 1; - if(!generate_sine16_1("sine-00.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49)) return 1; - if(!generate_sine16_1("sine-01.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37)) return 1; - if(!generate_sine16_1("sine-02.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49)) return 1; - if(!generate_sine16_1("sine-03.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49)) return 1; - if(!generate_sine16_1("sine-04.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29)) return 1; - - if(!generate_sine16_2("sine-10.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1; - if(!generate_sine16_2("sine-11.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1; - if(!generate_sine16_2("sine-12.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1; - if(!generate_sine16_2("sine-13.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1; - if(!generate_sine16_2("sine-14.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1; - if(!generate_sine16_2("sine-15.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1; - if(!generate_sine16_2("sine-16.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1; - if(!generate_sine16_2("sine-17.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1; - if(!generate_sine16_2("sine-18.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1; - if(!generate_sine16_2("sine-19.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1; - - if(!generate_noise("noise.raw", 65536 * 2)) return 1; + if(!generate_fsd24("fsd24-01.raw", pattern01, 100)) return 1; + if(!generate_fsd24("fsd24-02.raw", pattern02, 100)) return 1; + if(!generate_fsd24("fsd24-03.raw", pattern03, 100)) return 1; + if(!generate_fsd24("fsd24-04.raw", pattern04, 100)) return 1; + if(!generate_fsd24("fsd24-05.raw", pattern05, 100)) return 1; + if(!generate_fsd24("fsd24-06.raw", pattern06, 100)) return 1; + if(!generate_fsd24("fsd24-07.raw", pattern07, 100)) return 1; + + if(!generate_sine16_1("sine16-00.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49)) return 1; + if(!generate_sine16_1("sine16-01.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37)) return 1; + if(!generate_sine16_1("sine16-02.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49)) return 1; + if(!generate_sine16_1("sine16-03.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49)) return 1; + if(!generate_sine16_1("sine16-04.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29)) return 1; + + if(!generate_sine16_2("sine16-10.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1; + if(!generate_sine16_2("sine16-11.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1; + if(!generate_sine16_2("sine16-12.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1; + if(!generate_sine16_2("sine16-13.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1; + if(!generate_sine16_2("sine16-14.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1; + if(!generate_sine16_2("sine16-15.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1; + if(!generate_sine16_2("sine16-16.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1; + if(!generate_sine16_2("sine16-17.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1; + if(!generate_sine16_2("sine16-18.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1; + if(!generate_sine16_2("sine16-19.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1; + + if(!generate_sine24_1("sine24-00.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49)) return 1; + if(!generate_sine24_1("sine24-01.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37)) return 1; + if(!generate_sine24_1("sine24-02.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49)) return 1; + if(!generate_sine24_1("sine24-03.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49)) return 1; + if(!generate_sine24_1("sine24-04.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29)) return 1; + + if(!generate_sine24_2("sine24-10.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1; + if(!generate_sine24_2("sine24-11.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1; + if(!generate_sine24_2("sine24-12.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1; + if(!generate_sine24_2("sine24-13.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1; + if(!generate_sine24_2("sine24-14.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1; + if(!generate_sine24_2("sine24-15.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1; + if(!generate_sine24_2("sine24-16.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1; + if(!generate_sine24_2("sine24-17.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1; + if(!generate_sine24_2("sine24-18.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1; + if(!generate_sine24_2("sine24-19.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1; + + if(!generate_noise("noise.raw", 65536 * 8 * 3)) return 1; return 0; } diff --git a/test/test_streams.sh b/test/test_streams.sh index 0a2d643..30f8d3a 100755 --- a/test/test_streams.sh +++ b/test/test_streams.sh @@ -4,6 +4,7 @@ LD_LIBRARY_PATH=../src/libFLAC/.libs:../obj/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH PATH=../src/flac:../src/test_streams:../obj/bin:$PATH +echo "Generating streams..." if test_streams ; then : ; else echo "ERROR during test_streams" 1>&2 exit 1 @@ -59,38 +60,45 @@ for b in 01 02 03 04 05 06 07 ; do test_file fsd16-$b 1 16 "-0 -l 8 -m -e -q 15" done -echo "Testing sine wave streams..." -for b in 00 01 02 03 04 ; do - test_file sine-$b 1 16 "-0 -l 8 -m -e" +echo "Testing 24-bit full-scale deflection streams..." +for b in 01 02 03 04 05 06 07 ; do + test_file fsd24-$b 1 24 "-0 -l 8 -m -e -q 7" done -for b in 10 11 12 13 14 15 16 17 18 19 ; do - test_file sine-$b 2 16 "-0 -l 8 -m -e" + +for bps in 16 24 ; do + echo "Testing $bps-bit sine wave streams..." + for b in 00 01 02 03 04 ; do + test_file sine${bps}-$b 1 $bps "-0 -l 8 -m -e" + done + for b in 10 11 12 13 14 15 16 17 18 19 ; do + test_file sine${bps}-$b 2 $bps "-0 -l 8 -m -e" + done done echo "Testing some frame header variations..." -test_file sine-01 1 16 "-0 -l 8 -m -e --lax -b 16" -test_file sine-01 1 16 "-0 -l 8 -m -e --lax -b 65535" -test_file sine-01 1 16 "-0 -l 8 -m -e -b 16" -test_file sine-01 1 16 "-0 -l 8 -m -e -b 65535" -test_file sine-01 1 16 "-0 -l 8 -m -e --lax -fs 9" -test_file sine-01 1 16 "-0 -l 8 -m -e --lax -fs 90" -test_file sine-01 1 16 "-0 -l 8 -m -e --lax -fs 90000" -test_file sine-01 1 16 "-0 -l 8 -m -e -fs 9" -test_file sine-01 1 16 "-0 -l 8 -m -e -fs 90" -test_file sine-01 1 16 "-0 -l 8 -m -e -fs 90000" +test_file sine16-01 1 16 "-0 -l 8 -m -e --lax -b 16" +test_file sine16-01 1 16 "-0 -l 8 -m -e --lax -b 65535" +test_file sine16-01 1 16 "-0 -l 8 -m -e -b 16" +test_file sine16-01 1 16 "-0 -l 8 -m -e -b 65535" +test_file sine16-01 1 16 "-0 -l 8 -m -e --lax -fs 9" +test_file sine16-01 1 16 "-0 -l 8 -m -e --lax -fs 90" +test_file sine16-01 1 16 "-0 -l 8 -m -e --lax -fs 90000" +test_file sine16-01 1 16 "-0 -l 8 -m -e -fs 9" +test_file sine16-01 1 16 "-0 -l 8 -m -e -fs 90" +test_file sine16-01 1 16 "-0 -l 8 -m -e -fs 90000" echo "Testing option variations..." for f in 00 01 02 03 04 ; do for opt in 0 1 2 4 5 6 8 ; do for extras in '' '-p' '-e' ; do - test_file sine-$f 1 16 "-$opt $extras" + test_file sine16-$f 1 16 "-$opt $extras" done done done for f in 10 11 12 13 14 15 16 17 18 19 ; do for opt in 0 1 2 4 5 6 8 ; do for extras in '' '-p' '-e' ; do - test_file sine-$f 2 16 "-$opt $extras" + test_file sine16-$f 2 16 "-$opt $extras" done done done @@ -99,8 +107,8 @@ echo "Testing noise..." for opt in 0 1 2 4 5 6 8 ; do for extras in '' '-p' '-e' ; do for blocksize in '' '-b 32' '-b 32768' '-b 65535' ; do - for channels in 1 2 4 ; do - for bps in 8 16 ; do + for channels in 1 2 5 8 ; do + for bps in 8 16 24 ; do test_file noise $channels $bps "-$opt $extras $blocksize" done done -- 2.7.4