mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
Add patch from Earl Chew <earl_chew@yahoo.com> that adds testing for
the replay gain calculations.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user