diff --git a/.gitignore b/.gitignore index e28cb79aa0..bc910038b3 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ src/test_seeking/test_seeking src/test_streams/test_streams stamp-h1 test/*.aiff +test/*.aifc test/*.cmp test/*.cue test/*.flac diff --git a/src/flac/decode.c b/src/flac/decode.c index a384b8c030..6aca01d29f 100644 --- a/src/flac/decode.c +++ b/src/flac/decode.c @@ -776,7 +776,7 @@ FLAC__bool write_iff_headers(FILE *f, DecoderSession *decoder_session, FLAC__uin else if(format == FORMAT_AIFF) iff_size = 46 + foreign_metadata_size + aligned_data_size; else /* AIFF-C */ - iff_size = 16 + foreign_metadata_size + aligned_data_size + (fm?fm->aifc_comm_length:0); + iff_size = 16 + foreign_metadata_size + aligned_data_size + (fm?fm->aifc_comm_length:36); if(format != FORMAT_WAVE64 && format != FORMAT_RF64 && iff_size >= 0xFFFFFFF4) { flac__utils_printf(stderr, 1, "%s: ERROR: stream is too big to fit in a single %s file\n", decoder_session->inbasefilename, fmt_desc); diff --git a/src/test_streams/main.c b/src/test_streams/main.c index 90a8971f6f..6052500a0c 100644 --- a/src/test_streams/main.c +++ b/src/test_streams/main.c @@ -747,7 +747,8 @@ static FLAC__bool generate_unsigned_raw(const char *filename, unsigned channels, return false; } -static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsigned channels, unsigned bps, unsigned samples) +/* flavor is: 0:AIFF, 1:AIFF-C NONE, 2:AIFF-C sowt */ +static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsigned channels, unsigned bps, unsigned samples, int flavor) { const unsigned bytes_per_sample = (bps+7)/8; const unsigned true_size = channels * bytes_per_sample * samples; @@ -765,10 +766,18 @@ static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsi return false; if(fwrite("FORM", 1, 4, f) < 4) goto foo; - if(!write_big_endian_uint32(f, padded_size + 46)) - goto foo; - if(fwrite("AIFFCOMM\000\000\000\022", 1, 12, f) < 12) - goto foo; + if(flavor == 0) { + if(!write_big_endian_uint32(f, padded_size + 46)) + goto foo; + if(fwrite("AIFFCOMM\000\000\000\022", 1, 12, f) < 12) + goto foo; + } + else { + if(!write_big_endian_uint32(f, padded_size + 52)) + goto foo; + if(fwrite("AIFCCOMM\000\000\000\030", 1, 12, f) < 12) + goto foo; + } if(!write_big_endian_uint16(f, (FLAC__uint16)channels)) goto foo; if(!write_big_endian_uint32(f, samples)) @@ -777,6 +786,14 @@ static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsi goto foo; if(!write_sane_extended(f, sample_rate)) goto foo; + if(flavor == 1) { + if(fwrite("NONE\000\000", 1, 6, f) < 6) + goto foo; + } + else if(flavor == 2) { + if(fwrite("sowt\000\000", 1, 6, f) < 6) + goto foo; + } if(fwrite("SSND", 1, 4, f) < 4) goto foo; if(!write_big_endian_uint32(f, true_size + 8)) @@ -788,8 +805,14 @@ static FLAC__bool generate_aiff(const char *filename, unsigned sample_rate, unsi for(j = 0; j < channels; j++) { double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale; FLAC__int32 v = ((FLAC__int32)(val + 0.5) + ((GET_RANDOM_BYTE>>4)-8)) << shift; - if(!write_big_endian(f, v, bytes_per_sample)) - goto foo; + if(flavor == 0 || flavor == 1) { + if(!write_big_endian(f, v, bytes_per_sample)) + goto foo; + } + else { + if(!write_little_endian_signed(f, v, bytes_per_sample)) + goto foo; + } } } for(i = true_size; i < padded_size; i++) @@ -1367,7 +1390,15 @@ int main(int argc, char *argv[]) char fn[64]; flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.aiff", channels, bits_per_sample, nsamples[samples]); - if(!generate_aiff(fn, 44100, channels, bits_per_sample, nsamples[samples])) + if(!generate_aiff(fn, 44100, channels, bits_per_sample, nsamples[samples], 0)) + return 1; + + flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.aifc", channels, bits_per_sample, nsamples[samples]); + if(!generate_aiff(fn, 44100, channels, bits_per_sample, nsamples[samples], 1)) + return 1; + + flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u-le.aifc", channels, bits_per_sample, nsamples[samples]); + if(!generate_aiff(fn, 44100, channels, bits_per_sample, nsamples[samples], 2)) return 1; flac_snprintf(fn, sizeof (fn), "rt-%u-%u-%u.wav", channels, bits_per_sample, nsamples[samples]); diff --git a/test/Makefile.am b/test/Makefile.am index b4b76b038f..cd28707d58 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -59,4 +59,4 @@ EXTRA_DIST = \ write_iff.pl clean-local: - -rm -f *.raw *.flac *.oga *.ogg *.cmp *.aiff *.wav *.w64 *.rf64 *.diff *.log *.cue core + -rm -f *.raw *.flac *.oga *.ogg *.cmp *.aifc *.aiff *.wav *.w64 *.rf64 *.diff *.log *.cue core diff --git a/test/test_flac.sh b/test/test_flac.sh index 36e5b059be..c4f067abac 100755 --- a/test/test_flac.sh +++ b/test/test_flac.sh @@ -266,6 +266,34 @@ rt_test_aiff () rm -f rt.flac rt.aiff } +rt_test_aifc () +{ + f="$1" + extra="$2" + echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C + run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR" + echo $ECHO_N "decode... " $ECHO_C + run_flac --force --decode --channel-map=none -o rt.aifc --force-aiff-c-none-format $extra rt.flac || die "ERROR" + echo $ECHO_N "compare... " $ECHO_C + cmp $f rt.aifc || die "ERROR: file mismatch" + echo "OK" + rm -f rt.flac rt.aifc +} + +rt_test_aifc_le () +{ + f="$1" + extra="$2" + echo $ECHO_N "round-trip test ($f) encode... " $ECHO_C + run_flac --force --verify --channel-map=none --no-padding --lax -o rt.flac $extra $f || die "ERROR" + echo $ECHO_N "decode... " $ECHO_C + run_flac --force --decode --channel-map=none -o rt.aifc --force-aiff-c-sowt-format $extra rt.flac || die "ERROR" + echo $ECHO_N "compare... " $ECHO_C + cmp $f rt.aifc || die "ERROR: file mismatch" + echo "OK" + rm -f rt.flac rt.aifc +} + rt_test_autokf () { f="$1" @@ -329,6 +357,12 @@ done for f in rt-*.aiff ; do rt_test_aiff $f done +for f in rt-*[0-9].aifc ; do + rt_test_aifc $f +done +for f in rt-*le.aifc ; do + rt_test_aifc_le $f +done for f in rt-*.wav ; do rt_test_flac $f done