#!/bin/sh
# FLAC - Free Lossless Audio Codec
-# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
+# Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Josh Coalson
#
# This file is part the FLAC project. FLAC is comprised of several
# components distributed under difference licenses. The codec libraries
fi
LD_LIBRARY_PATH=`pwd`/../src/libFLAC/.libs:$LD_LIBRARY_PATH
-LD_LIBRARY_PATH=`pwd`/../src/libOggFLAC/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/../src/share/grabbag/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/../src/share/getopt/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_synthesis/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/../src/share/utf8/.libs:$LD_LIBRARY_PATH
-LD_LIBRARY_PATH=`pwd`/../obj/$BUILD/lib:$LD_LIBRARY_PATH
+LD_LIBRARY_PATH=`pwd`/../objs/$BUILD/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
+export MALLOC_CHECK_=3
+export MALLOC_PERTURB_=$((1$(date +%N) % 255 + 1))
PATH=`pwd`/../src/flac:$PATH
PATH=`pwd`/../src/metaflac:$PATH
-PATH=`pwd`/../obj/$BUILD/bin:$PATH
+PATH=`pwd`/../objs/$BUILD/bin:$PATH
+
+if echo a | (grep -E '(a|b)') >/dev/null 2>&1
+ then EGREP='grep -E'
+ else EGREP='egrep'
+fi
testdir="metaflac-test-files"
flacfile="metaflac.flac"
run_flac ()
{
if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
- valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 flac $* 4>>test_metaflac.valgrind.log
+ echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_metaflac.valgrind.log
+ valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac $* 4>>test_metaflac.valgrind.log
else
flac $*
fi
run_metaflac ()
{
if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
- valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 metaflac $* 4>>test_metaflac.valgrind.log
+ echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_metaflac.valgrind.log
+ valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac $* 4>>test_metaflac.valgrind.log
else
metaflac $*
fi
run_metaflac $*
else
if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
- valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 metaflac $* 2>/dev/null 4>>test_metaflac.valgrind.log
+ echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_metaflac.valgrind.log
+ valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac $* 2>/dev/null 4>>test_metaflac.valgrind.log
else
metaflac $* 2>/dev/null
fi
# minor danger, changing vendor strings will change the length of the
# VORBIS_COMMENT block, but if we add "^ length: " to the patterns,
# we lose info about PADDING size that we need
- grep -Ev '^ vendor string: |^ m..imum .....size: ' | sed -e 's/, stream_offset.*//'
+ # grep pattern 1: remove vendor string
+ # grep pattern 2: remove minimum/maximum frame and block size from STREAMINFO
+ # grep pattern 3: remove hexdump data from PICTURE metadata blocks
+ # sed pattern 1: remove stream offset values from SEEKTABLE points
+ $EGREP -v '^ vendor string: |^ m..imum .....size: |^ 0000[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]: ' | sed -e 's/, stream_offset.*//'
}
metaflac_test ()
{
expect="$testdir/$case-expect.meta"
echo -n "test $case: $desc... "
run_metaflac $args $flacfile | filter > $testdir/out.meta || die "ERROR running metaflac"
- diff -q -w $expect $testdir/out.meta 2>/dev/null || die "ERROR: metadata does not match expected $expect"
+ diff -w $expect $testdir/out.meta > /dev/null 2>&1 || die "ERROR: metadata does not match expected $expect"
echo OK
}
check_flac
metaflac_test case42 "--remove-replay-gain" "--list"
+# CUESHEET blocks
cs_in=cuesheets/good.000.cue
cs_out=metaflac.cue
cs_out2=metaflac2.cue
rm -f $cs_out $cs_out2
+# PICTURE blocks
+ncase=46
+for f in \
+ 0.gif \
+ 1.gif \
+ 2.gif \
+; do
+ run_metaflac --import-picture-from="|image/gif|$f||pictures/$f" $flacfile
+ check_flac
+ metaflac_test "case$ncase" "--import-picture-from" "--list"
+ ncase=`expr $ncase + 1`
+done
+for f in \
+ 0.jpg \
+ 4.jpg \
+; do
+ run_metaflac --import-picture-from="4|image/jpeg|$f||pictures/$f" $flacfile
+ check_flac
+ metaflac_test "case$ncase" "--import-picture-from" "--list"
+ ncase=`expr $ncase + 1`
+done
+for f in \
+ 0.png \
+ 1.png \
+ 2.png \
+ 3.png \
+ 4.png \
+ 5.png \
+ 6.png \
+ 7.png \
+ 8.png \
+; do
+ run_metaflac --import-picture-from="5|image/png|$f||pictures/$f" $flacfile
+ check_flac
+ metaflac_test "case$ncase" "--import-picture-from" "--list"
+ ncase=`expr $ncase + 1`
+done
+[ $ncase = 60 ] || die "expected case# to be 60"
+
+fn=export-picture-check
+echo -n "Testing --export-picture-to... "
+run_metaflac --export-picture-to=$fn $flacfile
+check_flac
+cmp $fn pictures/0.gif || die "ERROR, exported picture file and original differ"
+echo OK
+rm -f $fn
+echo -n "Testing --block-number --export-picture-to... "
+run_metaflac --block-number=9 --export-picture-to=$fn $flacfile
+check_flac
+cmp $fn pictures/0.png || die "ERROR, exported picture file and original differ"
+echo OK
+rm -f $fn
+
+run_metaflac --remove --block-type=PICTURE $flacfile
+check_flac
+metaflac_test case60 "--remove --block-type=PICTURE" "--list"
+run_metaflac --import-picture-from="1|image/png|standard_icon|32x32x24|pictures/0.png" $flacfile
+check_flac
+metaflac_test case61 "--import-picture-from" "--list"
+run_metaflac --import-picture-from="2|image/png|icon|64x64x24|pictures/1.png" $flacfile
+check_flac
+metaflac_test case62 "--import-picture-from" "--list"
+
+# UNKNOWN blocks
echo -n "Testing FLAC file with unknown metadata... "
cp -p metaflac.flac.in $flacfile
# remove the VORBIS_COMMENT block so vendor string changes don't interfere with the comparison:
cmp $flacfile metaflac.flac.ok || die "ERROR, $flacfile and metaflac.flac.ok differ"
echo OK
-rm -f out.flac out.meta
+# Replay gain tests - Test the rates which have specific filter table entries
+# and verify that harmonics can be processed correctly.
+
+tonegenerator ()
+{
+ # When using GAWK, use --lint=posix to identify non-POSIX awk usages.
+ awk -- '
+ BEGIN {
+ samplerate = '$1';
+
+ tone = 1000;
+ duration = 1;
+ bitspersample = 24;
+
+ samplemidpoint = 1;
+ for (sps = 0 ; sps < bitspersample - 1 ; sps++) {
+ samplemidpoint *= 2;
+ }
+
+ 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"
+
+set -e
+
+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