Skip to content

Commit

Permalink
Add roundtrip tests for AIFF-C handling in command line tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmf01 committed Dec 3, 2024
1 parent ffc5bf5 commit 669eae9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 39 additions & 8 deletions src/test_streams/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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++)
Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 34 additions & 0 deletions test/test_flac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 669eae9

Please sign in to comment.