1#!/bin/sh -e 2 3# FLAC - Free Lossless Audio Codec 4# Copyright (C) 2002-2009 Josh Coalson 5# Copyright (C) 2011-2016 Xiph.Org Foundation 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 21. ./common.sh 22 23PATH=`pwd`/../src/flac:$PATH 24PATH=`pwd`/../src/metaflac:$PATH 25PATH=`pwd`/../objs/$BUILD/bin:$PATH 26 27if echo a | (grep -E '(a|b)') >/dev/null 2>&1 28 then EGREP='grep -E' 29 else EGREP='egrep' 30fi 31 32testdir="metaflac-test-files" 33flacfile="replaygain.flac" 34 35run_flac () 36{ 37 if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then 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 40 else 41 flac${EXE} --no-error-on-compression-fail $* 42 fi 43} 44 45run_metaflac () 46{ 47 if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then 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 50 else 51 metaflac${EXE} $* 52 fi 53} 54 55run_metaflac_silent () 56{ 57 if [ -z "$SILENT" ] ; then 58 run_metaflac $* 59 else 60 if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then 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 63 else 64 metaflac${EXE} $* 2>/dev/null 65 fi 66 fi 67} 68 69check_flac () 70{ 71 run_flac --silent --test $flacfile || die "ERROR in $flacfile" 1>&2 72} 73 74echo "Generating stream..." 75bytes=80000 76if 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 77 chmod +w $flacfile 78else 79 die "ERROR during generation" 80fi 81 82check_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 87tonegenerator () 88{ 89 flac${EXE} --force --output-name=$2 --silent --no-seektable --no-error-on-compression-fail rpg-tone-$1.wav 90} 91 92REPLAYGAIN_FREQ= 93REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 8000/-12.73" 94REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 11025/-12.91" 95REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 12000/-12.98" 96REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 16000/-13.27" 97REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 18900/-13.41" 98REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 22050/-13.77" 99REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 24000/-13.82" 100REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 28000/-14.06" 101REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 32000/-14.08" 102REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 36000/-14.12" 103REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 37800/-14.18" 104REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 44100/-14.17" 105REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 48000/-14.16:1:2:4" 106 107set -e 108 109for 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 127 echo $ECHO_N "Testing FLAC replaygain $RATE ($FREQ x $MULTIPLE) ... " $ECHO_C 128 tonegenerator $RATE $flacfile 129 run_metaflac --scan-replay-gain $flacfile 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 141done 142 143 144rm -f $testdir/out.flac $testdir/out.meta 145 146exit 0 147