* Use `mktemp` instead of playing with date(1). * Use -f instead of removing the file every time. * "echo ERROR; exit 1" is what die() is for. * Some cosmetic renamings ('k' to 'comp' for compression etc). * Remove the MacOSX comment. It's not MacOSX specific, and it's not a problem anyway. The number behaves just right. * Remove the $((${size}+10)). It's not needed, and it's a lie. In fact, the actual test FAILs (369513 with -5 vs 369516 with -6), but this +10 hides it! Two more things not addressed in this diff: 1. The input test file (noisy-sine.wav) needs to be present already, probably as an artifact of some previous test. So ./test_compression does not work standalone. I am leaving this till I figure out the right uniform way for all the test* to have their test files generated. 2. The 'wc -c' needs to actually read the whole file. Not much work with noisy-sine.wav, but when we test with big files? Why not "ls -l | awk '{print$5}'" ? Put it in a function in common.sh, probably. Jan --- test_compression.sh.orig Wed Dec 3 22:53:11 2014 +++ test_compression.sh Wed Dec 3 23:01:16 2014 @@ -23,24 +23,22 @@ PATH=`pwd`/../src/flac:$PATH echo "Using FLAC binary :" $(which flac) -date=`date "+%Y%m%dT%H%M%S"` -fname="comp${date}.flac" +ofile=`mktemp`.$$ +ifile="noisy-sine.wav" -last_k=0 -last_size=$(wc -c < noisy-sine.wav) +prevcomp=0 +prevsize=`wc -c < $ifile` +echo "Original file size $prevsize bytes." -echo "Original file size ${last_size} bytes." +for comp in 0 1 2 3 4 5 6 7 8 ; do + flac${EXE} -f -$comp --silent $ifile -o $ofile + size=`wc -c < $ofile` + echo Compression level $comp, file size $size bytes. + if test $prevsize -lt $size ; then + die "Error: level $prevcomp produces smaller file than $comp" + fi + prevsize=$size + prevcomp=$comp +done -for k in 0 1 2 3 4 5 6 7 8 ; do - flac${EXE} -${k} --silent noisy-sine.wav -o ${fname} - size=$(wc -c < ${fname}) - echo "Compression level ${k}, file size ${size} bytes." - if test ${last_size} -lt ${size} ; then - echo "Error : Compression ${last_k} size ${last_size} >= compression ${k} size ${size}." - exit 1 - fi - # Need this because OSX's 'wc -c' returns a number with leading whitespace. - last_size=$((${size}+10)) - last_k=${k} - rm -f ${fname} - done +rm -f $ofile
Op 03-12-14 om 23:27 schreef Jan Stary:> * Remove the $((${size}+10)). It's not needed, and it's a lie. > In fact, the actual test FAILs (369513 with -5 vs 369516 with -6), > but this +10 hides it!No, it is not. This is necessary due to the way FLAC works. There is some uncertainty between the prediction stage and the actual LPC stage due to quantization, and there is no way to change this. It is only 10 bytes anyway.
On Dec 04 00:37:25, mvanb1 at gmail.com wrote:> Op 03-12-14 om 23:27 schreef Jan Stary: > > * Remove the $((${size}+10)). It's not needed, and it's a lie. > > In fact, the actual test FAILs (369513 with -5 vs 369516 with -6), > > but this +10 hides it! > > No, it is not. This is necessary due to the way FLAC works. > There is some uncertainty between the prediction stage and the > actual LPC stage due to quantization, and there is no way to > change this. It is only 10 bytes anyway.My bad, I thought it was a typo in what meant to be "+0", due to the misleadimg MacOSX comment. Another diff below. Jan --- test_compression.sh.orig Wed Dec 3 22:53:11 2014 +++ test_compression.sh Thu Dec 4 08:47:27 2014 @@ -23,24 +23,25 @@ PATH=`pwd`/../src/flac:$PATH echo "Using FLAC binary :" $(which flac) -date=`date "+%Y%m%dT%H%M%S"` -fname="comp${date}.flac" +ofile=`mktemp`.$$ +ifile="noisy-sine.wav" -last_k=0 -last_size=$(wc -c < noisy-sine.wav) +prevcomp=0 +prevsize=`wc -c < $ifile` +echo "Original file size $prevsize bytes." -echo "Original file size ${last_size} bytes." +for comp in 0 1 2 3 4 5 6 7 8 ; do + flac${EXE} -f -$comp --silent $ifile -o $ofile + size=`wc -c < $ofile` + echo Compression level $comp, file size $size bytes. + if test $prevsize -lt $size ; then + die "Error: level $prevcomp produces smaller file than $comp" + fi + # This is necessary due to the way FLAC works. + # There is some uncertainty between the prediction stage + # and the actual LPC stage due to quantization + prevsize=$(($size+10)) + prevcomp=$comp +done -for k in 0 1 2 3 4 5 6 7 8 ; do - flac${EXE} -${k} --silent noisy-sine.wav -o ${fname} - size=$(wc -c < ${fname}) - echo "Compression level ${k}, file size ${size} bytes." - if test ${last_size} -lt ${size} ; then - echo "Error : Compression ${last_k} size ${last_size} >= compression ${k} size ${size}." - exit 1 - fi - # Need this because OSX's 'wc -c' returns a number with leading whitespace. - last_size=$((${size}+10)) - last_k=${k} - rm -f ${fname} - done +rm -f $ofile