Erik de Castro Lopo | 1a7c3fa | 2014-11-27 13:03:13 +1100 | [diff] [blame] | 1 | #!/bin/sh -e |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 2 | |
| 3 | # FLAC - Free Lossless Audio Codec |
| 4 | # Copyright (C) 2002-2009 Josh Coalson |
Erik de Castro Lopo | 6a5fe43 | 2016-12-05 06:35:39 +1100 | [diff] [blame] | 5 | # Copyright (C) 2011-2016 Xiph.Org Foundation |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 6 | # |
| 7 | # This file is part the FLAC project. FLAC is comprised of several |
| 8 | # components distributed under different licenses. The codec libraries |
| 9 | # are distributed under Xiph.Org's BSD-like license (see the file |
| 10 | # COPYING.Xiph in this distribution). All other programs, libraries, and |
| 11 | # plugins are distributed under the GPL (see COPYING.GPL). The documentation |
| 12 | # is distributed under the Gnu FDL (see COPYING.FDL). Each file in the |
| 13 | # FLAC distribution contains at the top the terms under which it may be |
| 14 | # distributed. |
| 15 | # |
| 16 | # Since this particular file is relevant to all components of FLAC, |
| 17 | # it may be distributed under the Xiph.Org license, which is the least |
| 18 | # restrictive of those mentioned above. See the file COPYING.Xiph in this |
| 19 | # distribution. |
| 20 | |
Erik de Castro Lopo | 1a7c3fa | 2014-11-27 13:03:13 +1100 | [diff] [blame] | 21 | . ./common.sh |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 22 | |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 23 | PATH=`pwd`/../src/flac:$PATH |
| 24 | PATH=`pwd`/../src/metaflac:$PATH |
| 25 | PATH=`pwd`/../objs/$BUILD/bin:$PATH |
| 26 | |
| 27 | if echo a | (grep -E '(a|b)') >/dev/null 2>&1 |
| 28 | then EGREP='grep -E' |
| 29 | else EGREP='egrep' |
| 30 | fi |
| 31 | |
| 32 | testdir="metaflac-test-files" |
| 33 | flacfile="replaygain.flac" |
| 34 | |
| 35 | run_flac () |
| 36 | { |
| 37 | if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then |
Erik de Castro Lopo | 1d3d50a | 2013-09-16 19:34:59 +1000 | [diff] [blame] | 38 | echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_replaygain.valgrind.log |
| 39 | valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac --no-error-on-compression-fail $* 4>>test_replaygain.valgrind.log |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 40 | else |
Erik de Castro Lopo | a9712a2 | 2013-09-16 19:55:11 +1000 | [diff] [blame] | 41 | flac${EXE} --no-error-on-compression-fail $* |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 42 | fi |
| 43 | } |
| 44 | |
| 45 | run_metaflac () |
| 46 | { |
| 47 | if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then |
Erik de Castro Lopo | 1d3d50a | 2013-09-16 19:34:59 +1000 | [diff] [blame] | 48 | echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_replaygain.valgrind.log |
| 49 | valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac $* 4>>test_replaygain.valgrind.log |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 50 | else |
Erik de Castro Lopo | a9712a2 | 2013-09-16 19:55:11 +1000 | [diff] [blame] | 51 | metaflac${EXE} $* |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 52 | fi |
| 53 | } |
| 54 | |
| 55 | run_metaflac_silent () |
| 56 | { |
| 57 | if [ -z "$SILENT" ] ; then |
| 58 | run_metaflac $* |
| 59 | else |
| 60 | if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then |
Erik de Castro Lopo | 1d3d50a | 2013-09-16 19:34:59 +1000 | [diff] [blame] | 61 | echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_replaygain.valgrind.log |
| 62 | valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac $* 2>/dev/null 4>>test_replaygain.valgrind.log |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 63 | else |
Erik de Castro Lopo | a9712a2 | 2013-09-16 19:55:11 +1000 | [diff] [blame] | 64 | metaflac${EXE} $* 2>/dev/null |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 65 | fi |
| 66 | fi |
| 67 | } |
| 68 | |
| 69 | check_flac () |
| 70 | { |
| 71 | run_flac --silent --test $flacfile || die "ERROR in $flacfile" 1>&2 |
| 72 | } |
| 73 | |
| 74 | echo "Generating stream..." |
| 75 | bytes=80000 |
Erik de Castro Lopo | 7ef7b58 | 2014-12-20 11:40:41 +1100 | [diff] [blame] | 76 | if dd if=/dev/zero ibs=1 count=$bytes 2>/dev/null | flac${EXE} --silent --force --verify -0 --input-size=$bytes --output-name=$flacfile --force-raw-format --endian=big --sign=signed --channels=1 --bps=8 --sample-rate=8000 - ; then |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 77 | chmod +w $flacfile |
| 78 | else |
| 79 | die "ERROR during generation" |
| 80 | fi |
| 81 | |
| 82 | check_flac |
| 83 | |
| 84 | # Replay gain tests - Test the rates which have specific filter table entries |
| 85 | # and verify that harmonics can be processed correctly. |
| 86 | |
| 87 | tonegenerator () |
| 88 | { |
Erik de Castro Lopo | b903670 | 2014-12-20 14:24:41 +1100 | [diff] [blame] | 89 | flac${EXE} --force --output-name=$2 --silent --no-seektable --no-error-on-compression-fail rpg-tone-$1.wav |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | REPLAYGAIN_FREQ= |
Erik de Castro Lopo | b903670 | 2014-12-20 14:24:41 +1100 | [diff] [blame] | 93 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 8000/-12.73" |
| 94 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 11025/-12.91" |
| 95 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 12000/-12.98" |
| 96 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 16000/-13.27" |
| 97 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 18900/-13.41" |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 98 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 22050/-13.77" |
Erik de Castro Lopo | b903670 | 2014-12-20 14:24:41 +1100 | [diff] [blame] | 99 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 24000/-13.82" |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 100 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 28000/-14.06" |
| 101 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 32000/-14.08" |
| 102 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 36000/-14.12" |
| 103 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 37800/-14.18" |
| 104 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 44100/-14.17" |
| 105 | REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 48000/-14.16:1:2:4" |
| 106 | |
| 107 | set -e |
| 108 | |
| 109 | for ACTION in $REPLAYGAIN_FREQ ; do |
| 110 | if [ -n "${ACTION##*:*}" ] ; then |
| 111 | HARMONICS=1 |
| 112 | else |
| 113 | HARMONICS="${ACTION#*:}" |
| 114 | fi |
| 115 | FREQ="${ACTION%%/*}" |
| 116 | GAIN="${ACTION#*/}" |
| 117 | GAIN="${GAIN%%:*}" |
| 118 | while [ -n "$HARMONICS" ] ; do |
| 119 | MULTIPLE="${HARMONICS%%:*}" |
| 120 | if [ x"$MULTIPLE" = x"$HARMONICS" ] ; then |
| 121 | HARMONICS= |
| 122 | else |
| 123 | HARMONICS="${HARMONICS#*:}" |
| 124 | fi |
| 125 | RATE=$(($MULTIPLE * FREQ)) |
| 126 | [ $MULTIPLE -eq 1 -o -n "${REPLAYGAIN_FREQ##* $RATE/*}" ] || break |
Erik de Castro Lopo | efaab3c | 2015-10-04 09:43:33 +1100 | [diff] [blame] | 127 | echo $ECHO_N "Testing FLAC replaygain $RATE ($FREQ x $MULTIPLE) ... " $ECHO_C |
Erik de Castro Lopo | 7ef7b58 | 2014-12-20 11:40:41 +1100 | [diff] [blame] | 128 | tonegenerator $RATE $flacfile |
Ben Boeckel | f7c52c8 | 2015-08-12 21:45:04 -0400 | [diff] [blame] | 129 | run_metaflac --scan-replay-gain $flacfile |
Erik de Castro Lopo | b01e568 | 2013-08-02 06:19:56 +1000 | [diff] [blame] | 130 | run_metaflac --add-replay-gain $flacfile |
| 131 | run_metaflac --list $flacfile | grep REPLAYGAIN.*GAIN= | |
| 132 | while read -r REPLAYGAIN ; do |
| 133 | MEASUREDGAIN="${REPLAYGAIN##*=}" |
| 134 | MEASUREDGAIN="${MEASUREDGAIN%% *}" |
| 135 | if [ x"$MEASUREDGAIN" != x"$GAIN" ] ; then |
| 136 | die "ERROR, Expected $GAIN db instead of $REPLAYGAIN" |
| 137 | fi |
| 138 | done |
| 139 | echo OK |
| 140 | done |
| 141 | done |
| 142 | |
| 143 | |
| 144 | rm -f $testdir/out.flac $testdir/out.meta |
| 145 | |
| 146 | exit 0 |