[flac-dev] PATCH: Add test for metaflac --add-replay-gain

Earl Chew earl_chew at yahoo.com
Sun Feb 26 08:33:54 PST 2012


The test is rather simple, and only compares the computed output values for a 1kHz signal
at the known filter table sampling frequencies with previously obained golden values.

As such, the test only verifies that the performance of the replay
gain analyser has not changed.

A better test would be to compare the computed value with an independently
obtain theorectical value. This is possible by more judicious use of
the loudness.sci script, combined with more modelling of filter
operation in scilab. Such a test would verify that the performance
of the replay gain analyser is actually correct.

There is only one test to verify handling of harmonics of the filter table
sampling frequencies.

Signed-off-by: Earl Chew <earl_chew at yahoo.com>
---
 test/test_metaflac.sh |   86 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/test/test_metaflac.sh b/test/test_metaflac.sh
index 19f5a00..5b82f11 100755
--- a/test/test_metaflac.sh
+++ b/test/test_metaflac.sh
@@ -392,6 +392,92 @@ 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
-- 
1.6.5.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/flac-dev/attachments/20120226/c0cfb76d/attachment.htm 


More information about the flac-dev mailing list