diff options
author | Erik de Castro Lopo <erikd@mega-nerd.com> | 2012-03-19 07:44:11 +1100 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2012-03-19 07:44:11 +1100 |
commit | f20770e5d41f67b44dfaf36c6b3afdaf39fc1b5d (patch) | |
tree | 760049b82833a8393623e039c25371babcc10b70 /test | |
parent | 2f8b6a0349547742ca011a6b786c93839477ae33 (diff) | |
download | flac-f20770e5d41f67b44dfaf36c6b3afdaf39fc1b5d.tar.gz |
Add patch from Earl Chew <earl_chew@yahoo.com> that adds testing for
the replay gain calculations.
Diffstat (limited to 'test')
-rwxr-xr-x | test/test_metaflac.sh | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/test/test_metaflac.sh b/test/test_metaflac.sh index 19f5a002..c823ccf6 100755 --- a/test/test_metaflac.sh +++ b/test/test_metaflac.sh @@ -392,6 +392,93 @@ run_metaflac --remove --block-type=VORBIS_COMMENT --dont-use-padding $flacfile cmp $flacfile metaflac.flac.ok || die "ERROR, $flacfile and metaflac.flac.ok differ" echo OK +# Replay gain tests - Test the rates which have specific filter table entries +# and verify that harmonics can be processed correctly. + +tonegenerator () +{ + awk -- ' + BEGIN { + samplerate = '$1'; + + tone = 1000; + duration = 1; + bitspersample = 24; + + samplemidpoint = lshift(1, (bitspersample-1)); + samplerange = samplemidpoint - 1; + + pi = 4 * atan2(1,1); + + for (ix = 0; ix < duration * samplerate; ++ix) { + sample = sin(2 * pi * tone * ix / samplerate); + sample *= samplerange; + sample += samplemidpoint; + sample = int(sample); + for (bx = 0; bx < bitspersample/8; ++bx) { + byte[bx] = sample % 256; + sample /= 256; + } + while (bx--) { + printf("%c", byte[bx]); + } + } + + }' /dev/null | + flac --silent \ + --endian=big --channels=1 --bps=24 --sample-rate=$1 --sign=unsigned - +} + +REPLAYGAIN_FREQ= +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 8000/-12.73" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 11025/-12.93" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 11025/-12.93" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 12000/-12.98" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 16000/-13.27" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 18900/-13.41" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 22050/-13.77" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 24000/-13.82" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 28000/-14.06" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 32000/-14.08" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 36000/-14.12" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 37800/-14.18" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 44100/-14.17" +REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 48000/-14.16:1:2:4" + +for ACTION in $REPLAYGAIN_FREQ ; do + if [ -n "${ACTION##*:*}" ] ; then + HARMONICS=1 + else + HARMONICS="${ACTION#*:}" + fi + FREQ="${ACTION%%/*}" + GAIN="${ACTION#*/}" + GAIN="${GAIN%%:*}" + while [ -n "$HARMONICS" ] ; do + MULTIPLE="${HARMONICS%%:*}" + if [ x"$MULTIPLE" = x"$HARMONICS" ] ; then + HARMONICS= + else + HARMONICS="${HARMONICS#*:}" + fi + RATE=$(($MULTIPLE * FREQ)) + [ $MULTIPLE -eq 1 -o -n "${REPLAYGAIN_FREQ##* $RATE/*}" ] || break + echo -n "Testing FLAC replaygain $RATE ($FREQ x $MULTIPLE) ... " + tonegenerator $RATE > $flacfile + run_metaflac --add-replay-gain $flacfile + run_metaflac --list $flacfile | grep REPLAYGAIN.*GAIN= | + while read -r REPLAYGAIN ; do + MEASUREDGAIN="${REPLAYGAIN##*=}" + MEASUREDGAIN="${MEASUREDGAIN%% *}" + if [ x"$MEASUREDGAIN" != x"$GAIN" ] ; then + die "ERROR, Expected $GAIN db instead of $REPLAYGAIN" + fi + done + echo OK + done +done + + rm -f $testdir/out.flac $testdir/out.meta exit 0 |