blob: 2e7ab53ae3734879f6069b4c90606010f68c696a [file] [log] [blame]
Erik de Castro Lopo1a7c3fa2014-11-27 13:03:13 +11001#!/bin/sh -e
Erik de Castro Lopob01e5682013-08-02 06:19:56 +10002
3# FLAC - Free Lossless Audio Codec
4# Copyright (C) 2002-2009 Josh Coalson
Erik de Castro Lopo6a5fe432016-12-05 06:35:39 +11005# Copyright (C) 2011-2016 Xiph.Org Foundation
Erik de Castro Lopob01e5682013-08-02 06:19:56 +10006#
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 Lopo1a7c3fa2014-11-27 13:03:13 +110021. ./common.sh
Erik de Castro Lopob01e5682013-08-02 06:19:56 +100022
Erik de Castro Lopob01e5682013-08-02 06:19:56 +100023PATH=`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
Erik de Castro Lopo1d3d50a2013-09-16 19:34:59 +100038 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 Lopob01e5682013-08-02 06:19:56 +100040 else
Erik de Castro Lopoa9712a22013-09-16 19:55:11 +100041 flac${EXE} --no-error-on-compression-fail $*
Erik de Castro Lopob01e5682013-08-02 06:19:56 +100042 fi
43}
44
45run_metaflac ()
46{
47 if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
Erik de Castro Lopo1d3d50a2013-09-16 19:34:59 +100048 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 Lopob01e5682013-08-02 06:19:56 +100050 else
Erik de Castro Lopoa9712a22013-09-16 19:55:11 +100051 metaflac${EXE} $*
Erik de Castro Lopob01e5682013-08-02 06:19:56 +100052 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
Erik de Castro Lopo1d3d50a2013-09-16 19:34:59 +100061 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 Lopob01e5682013-08-02 06:19:56 +100063 else
Erik de Castro Lopoa9712a22013-09-16 19:55:11 +100064 metaflac${EXE} $* 2>/dev/null
Erik de Castro Lopob01e5682013-08-02 06:19:56 +100065 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
Erik de Castro Lopo7ef7b582014-12-20 11:40:41 +110076if 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 Lopob01e5682013-08-02 06:19:56 +100077 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{
Erik de Castro Lopob9036702014-12-20 14:24:41 +110089 flac${EXE} --force --output-name=$2 --silent --no-seektable --no-error-on-compression-fail rpg-tone-$1.wav
Erik de Castro Lopob01e5682013-08-02 06:19:56 +100090}
91
92REPLAYGAIN_FREQ=
Erik de Castro Lopob9036702014-12-20 14:24:41 +110093REPLAYGAIN_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"
Erik de Castro Lopob01e5682013-08-02 06:19:56 +100098REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 22050/-13.77"
Erik de Castro Lopob9036702014-12-20 14:24:41 +110099REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 24000/-13.82"
Erik de Castro Lopob01e5682013-08-02 06:19:56 +1000100REPLAYGAIN_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
Erik de Castro Lopoefaab3c2015-10-04 09:43:33 +1100127 echo $ECHO_N "Testing FLAC replaygain $RATE ($FREQ x $MULTIPLE) ... " $ECHO_C
Erik de Castro Lopo7ef7b582014-12-20 11:40:41 +1100128 tonegenerator $RATE $flacfile
Ben Boeckelf7c52c82015-08-12 21:45:04 -0400129 run_metaflac --scan-replay-gain $flacfile
Erik de Castro Lopob01e5682013-08-02 06:19:56 +1000130 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