📄 test_flac.sh
字号:
#!/bin/sh
# FLAC - Free Lossless Audio Codec
# Copyright (C) 2001,2002,2003,2004,2005 Josh Coalson
#
# This file is part the FLAC project. FLAC is comprised of several
# components distributed under difference licenses. The codec libraries
# are distributed under Xiph.Org's BSD-like license (see the file
# COPYING.Xiph in this distribution). All other programs, libraries, and
# plugins are distributed under the GPL (see COPYING.GPL). The documentation
# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the
# FLAC distribution contains at the top the terms under which it may be
# distributed.
#
# Since this particular file is relevant to all components of FLAC,
# it may be distributed under the Xiph.Org license, which is the least
# restrictive of those mentioned above. See the file COPYING.Xiph in this
# distribution.
die ()
{
echo $* 1>&2
exit 1
}
if [ x = x"$1" ] ; then
BUILD=debug
else
BUILD="$1"
fi
LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=../src/libOggFLAC/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=../src/share/grabbag/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=../src/share/getopt/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=../src/share/replaygain_synthesis/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=../src/share/utf8/.libs:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=../obj/$BUILD/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
PATH=../src/flac:$PATH
PATH=../src/metaflac:$PATH
PATH=../src/test_streams:$PATH
PATH=../obj/$BUILD/bin:$PATH
flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
run_flac ()
{
if [ x"$FLAC__VALGRIND" = xyes ] ; then
valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 flac $* 4>>test_flac.valgrind.log
else
flac $*
fi
}
run_metaflac ()
{
if [ x"$FLAC__VALGRIND" = xyes ] ; then
valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 metaflac $* 4>>test_flac.valgrind.log
else
metaflac $*
fi
}
if [ `env | grep -ic '^comspec='` != 0 ] ; then
is_win=yes
else
is_win=no
fi
echo "Checking for --ogg support in flac..."
if flac --ogg --silent --force-raw-format --endian=little --sign=signed --channels=1 --bps=8 --sample-rate=44100 -c $0 1>/dev/null 2>&1 ; then
has_ogg=yes;
echo "flac --ogg works"
else
has_ogg=no;
echo "flac --ogg doesn't work"
fi
echo "Generating streams..."
if [ ! -f wacky1.wav ] ; then
test_streams || die "ERROR during test_streams"
fi
############################################################################
# test that flac doesn't automatically overwrite files unless -f is used
############################################################################
echo "Try encoding to a file that exists; should fail"
cp wacky1.wav exist.wav
touch exist.flac
if run_flac --totally-silent -0 exist.wav ; then
die "ERROR: it should have failed but didn't"
else
echo "OK, it failed as it should"
fi
echo "Try encoding with -f to a file that exists; should succeed"
if run_flac --totally-silent -0 --force exist.wav ; then
echo "OK, it succeeded as it should"
else
die "ERROR: it should have succeeded but didn't"
fi
echo "Try decoding to a file that exists; should fail"
if run_flac --totally-silent -d exist.flac ; then
die "ERROR: it should have failed but didn't"
else
echo "OK, it failed as it should"
fi
echo "Try decoding with -f to a file that exists; should succeed"
if run_flac --totally-silent -d -f exist.flac ; then
echo "OK, it succeeded as it should"
else
die "ERROR: it should have succeeded but didn't"
fi
rm -f exist.wav exist.flac
############################################################################
# basic 'round-trip' tests of various kinds of streams
############################################################################
rt_test_raw ()
{
f="$1"
channels=`echo $f | awk -F- '{print $2}'`
bytes_per_sample=`echo $f | awk -F- '{print $3}'`
bps=`expr $bytes_per_sample '*' 8`
echo -n "round-trip test ($f) encode... "
run_flac --silent --force --verify --force-raw-format --endian=little --sign=signed --sample-rate=44100 --bps=$bps --channels=$channels $f -o rt.flac || die "ERROR"
echo -n "decode... "
run_flac --silent --force --decode --force-raw-format --endian=little --sign=signed -o rt.raw rt.flac || die "ERROR"
echo -n "compare... "
cmp $f rt.raw || die "ERROR: file mismatch"
echo "OK"
rm -f rt.flac rt.raw
}
rt_test_wav ()
{
f="$1"
echo -n "round-trip test ($f) encode... "
run_flac --silent --force --verify $f -o rt.flac || die "ERROR"
echo -n "decode... "
run_flac --silent --force --decode -o rt.wav rt.flac || die "ERROR"
echo -n "compare... "
cmp $f rt.wav || die "ERROR: file mismatch"
echo "OK"
rm -f rt.flac rt.wav
}
rt_test_aiff ()
{
f="$1"
echo -n "round-trip test ($f) encode... "
run_flac --silent --force --verify $f -o rt.flac || die "ERROR"
echo -n "decode... "
run_flac --silent --force --decode -o rt.aiff rt.flac || die "ERROR"
echo -n "compare... "
cmp $f rt.aiff || die "ERROR: file mismatch"
echo "OK"
rm -f rt.flac rt.aiff
}
for f in rt-*.raw ; do
rt_test_raw $f
done
for f in rt-*.wav ; do
rt_test_wav $f
done
for f in rt-*.aiff ; do
rt_test_aiff $f
done
############################################################################
# test --skip and --until
############################################################################
#
# first make some chopped-up raw files
#
echo "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMN" > master.raw
dddie="die ERROR: creating files for --skip/--until tests"
dd if=master.raw ibs=1 count=50 of=50c.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=10 count=40 of=50c.skip10.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=11 count=39 of=50c.skip11.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=20 count=30 of=50c.skip20.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=30 count=20 of=50c.skip30.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=40 count=10 of=50c.skip40.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=10 of=50c.until10.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=20 of=50c.until20.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=30 of=50c.until30.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=39 of=50c.until39.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 count=40 of=50c.until40.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=10 count=20 of=50c.skip10.until30.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=10 count=29 of=50c.skip10.until39.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=10 count=30 of=50c.skip10.until40.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=20 count=10 of=50c.skip20.until30.raw 2>/dev/null || $dddie
dd if=master.raw ibs=1 skip=20 count=20 of=50c.skip20.until40.raw 2>/dev/null || $dddie
wav_eopt="--silent --force --verify --lax"
wav_dopt="--silent --force --decode"
raw_eopt="$wav_eopt --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1"
raw_dopt="$wav_dopt --force-raw-format --endian=big --sign=signed"
#
# convert them to WAVE and AIFF files
#
convert_to_wav ()
{
run_flac $raw_eopt $1.raw || die "ERROR converting $1.raw to WAVE"
run_flac $wav_dopt $1.flac || die "ERROR converting $1.raw to WAVE"
}
convert_to_wav 50c
convert_to_wav 50c.skip10
convert_to_wav 50c.skip11
convert_to_wav 50c.skip20
convert_to_wav 50c.skip30
convert_to_wav 50c.skip40
convert_to_wav 50c.until10
convert_to_wav 50c.until20
convert_to_wav 50c.until30
convert_to_wav 50c.until39
convert_to_wav 50c.until40
convert_to_wav 50c.skip10.until30
convert_to_wav 50c.skip10.until39
convert_to_wav 50c.skip10.until40
convert_to_wav 50c.skip20.until30
convert_to_wav 50c.skip20.until40
convert_to_aiff ()
{
run_flac $raw_eopt $1.raw || die "ERROR converting $1.raw to AIFF"
run_flac $wav_dopt $1.flac -o $1.aiff || die "ERROR converting $1.raw to AIFF"
}
convert_to_aiff 50c
convert_to_aiff 50c.skip10
convert_to_aiff 50c.skip11
convert_to_aiff 50c.skip20
convert_to_aiff 50c.skip30
convert_to_aiff 50c.skip40
convert_to_aiff 50c.until10
convert_to_aiff 50c.until20
convert_to_aiff 50c.until30
convert_to_aiff 50c.until39
convert_to_aiff 50c.until40
convert_to_aiff 50c.skip10.until30
convert_to_aiff 50c.skip10.until39
convert_to_aiff 50c.skip10.until40
convert_to_aiff 50c.skip20.until30
convert_to_aiff 50c.skip20.until40
test_skip_until ()
{
in_fmt=$1
out_fmt=$2
[ "$in_fmt" = wav ] || [ "$in_fmt" = aiff ] || [ "$in_fmt" = raw ] || die "ERROR: internal error, bad 'in' format '$in_fmt'"
[ "$out_fmt" = flac ] || [ "$out_fmt" = ogg ] || die "ERROR: internal error, bad 'out' format '$out_fmt'"
if [ $in_fmt = raw ] ; then
eopt="$raw_eopt"
dopt="$raw_dopt"
else
eopt="$wav_eopt"
dopt="$wav_dopt"
fi
if [ $out_fmt = ogg ] ; then
eopt="--ogg $eopt"
fi
#
# test --skip when encoding
#
desc="($in_fmt<->$out_fmt)"
echo -n "testing --skip=# (encode) $desc... "
run_flac $eopt --skip=10 -o z50c.skip10.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
run_flac $dopt -o z50c.skip10.$in_fmt z50c.skip10.$out_fmt || die "ERROR decoding FLAC file $desc"
cmp 50c.skip10.$in_fmt z50c.skip10.$in_fmt || die "ERROR: file mismatch for --skip=10 (encode) $desc"
rm -f z50c.skip10.$out_fmt z50c.skip10.$in_fmt
echo OK
echo -n "testing --skip=mm:ss (encode) $desc... "
run_flac $eopt --skip=0:01 -o z50c.skip0:01.$out_fmt 50c.$in_fmt || die "ERROR generating FLAC file $desc"
run_flac $dopt -o z50c.skip0:01.$in_fmt z50c.skip0:01.$out_fmt || die "ERROR decoding FLAC file $desc"
cmp 50c.skip10.$in_fmt z50c.skip0:01.$in_fmt || die "ERROR: file mismatch for --skip=0:01 (encode) $desc"
rm -f z50c.skip0:01.$out_fmt z50c.skip0:01.$in_fmt
echo OK
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -