annotate testdata/evaluation/run-piano.sh @ 331:e8e37f471650 livemode

Merge
author Chris Cannam
date Wed, 29 Apr 2015 18:58:00 +0100
parents 10d8bd634a77
children bcfdaa708992
rev   line source
Chris@222 1 #!/bin/sh
Chris@222 2
Chris@222 3 # Assumption: instrument parameter value 0 of the Silvet plugin is
Chris@222 4 # always "multiple or unknown instruments" and 1 is always "piano".
Chris@222 5
Chris@222 6 piano_path="/home/cannam/Music/piano_small_dataset"
Chris@222 7 yc="/home/cannam/code/may/bin/yc"
Chris@222 8
Chris@222 9 if [ ! -d "$piano_path" ]; then
Chris@222 10 echo "Piano dataset directory $piano_path not found, giving up"
Chris@222 11 exit 1
Chris@222 12 fi
Chris@222 13
Chris@222 14 if ! "$yc" -v ; then
Chris@222 15 echo "Failed to run Yeti compiler yc at $yc_path, giving up";
Chris@222 16 fi
Chris@222 17
Chris@222 18 if ! sonic-annotator -v ; then
Chris@222 19 echo "Failed to run sonic-annotator (not in PATH?), giving up"
Chris@222 20 exit 1
Chris@222 21 fi
Chris@222 22
Chris@222 23 rdffile="../../silvet.n3"
Chris@222 24 if [ ! -f "$rdffile" ] ; then
Chris@222 25 echo "Failed to find plugin RDF file at $rdffile, giving up"
Chris@222 26 exit 1
Chris@222 27 fi
Chris@222 28
Chris@222 29 case "$piano_path" in
Chris@222 30 *\ *) echo "Piano dataset path $piano_path has a space in it, this script won't handle that"; exit 1;;
Chris@222 31 esac
Chris@222 32
Chris@222 33 ( cd ../.. ; make -f Makefile.linux ) || exit 1
Chris@222 34
Chris@222 35 VAMP_PATH=../..
Chris@222 36 export VAMP_PATH
Chris@222 37
Chris@222 38 outfile="/tmp/$$"
Chris@225 39 reference="/tmp/$$ref"
Chris@222 40
Chris@222 41 tmpwav="/tmp/$$.wav"
Chris@222 42
Chris@222 43 transfile="/tmp/$$transform.ttl"
Chris@222 44
Chris@271 45 trap 'rm -f "$outfile" "$tmpwav" "$transfile" "$reference.lab" "$outfile.lab"' 0
Chris@222 46
Chris@238 47 infiles=$(find "$piano_path" -name \*.wav | sort)
Chris@222 48
Chris@222 49 echo
Chris@222 50 echo "Input files are:"
Chris@222 51 echo $infiles | fmt -1
Chris@222 52
Chris@222 53 time for infile in $infiles; do
Chris@222 54
Chris@222 55 echo
Chris@222 56 echo "Evaluating for file $infile..."
Chris@222 57
Chris@222 58 intended_instrument=1 ## assumption: 1 == piano
Chris@222 59
Chris@222 60 # We run this twice, once using the default instrument
Chris@222 61 # (i.e. "multiple or unknown") and once using the intended
Chris@222 62 # instrument preset (piano).
Chris@222 63
Chris@222 64 filename=$(basename "$infile" .wav)
Chris@222 65
Chris@225 66 duration=30
Chris@225 67
Chris@238 68 for instrument in $intended_instrument ; do
Chris@222 69
Chris@269 70 for mode in 1 0; do
Chris@269 71
Chris@269 72 for norm in no; do
Chris@222 73
Chris@269 74 echo
Chris@269 75 echo "For file $filename, instrument $instrument, norm $norm..."
Chris@222 76
Chris@269 77 if [ "$norm" = "no" ]; then
Chris@269 78 # Don't normalise; plugin is now supposed to do it
Chris@269 79 sox "$infile" "$tmpwav" trim 0 $duration
Chris@269 80 else
Chris@269 81 # Normalise as reference
Chris@269 82 sox "$infile" "$tmpwav" trim 0 $duration gain -n -6.020599913279624
Chris@269 83 fi
Chris@222 84
Chris@269 85 # generate the transform by interpolating the instrument parameter
Chris@269 86 cat transform.ttl | \
Chris@269 87 sed "s/INSTRUMENT_PARAMETER/$instrument/" | \
Chris@269 88 sed "s/MODE_PARAMETER/$mode/" > "$transfile"
Chris@222 89
Chris@269 90 sonic-annotator \
Chris@269 91 --writer csv \
Chris@269 92 --csv-one-file "$outfile" \
Chris@269 93 --csv-force \
Chris@269 94 --transform "$transfile" \
Chris@269 95 "$tmpwav"
Chris@222 96
Chris@269 97 cat "$outfile" | \
Chris@269 98 sed 's/^[^,]*,//' | \
Chris@269 99 while IFS=, read start duration frequency level label; do
Chris@269 100 end=`echo "$start $duration + p" | dc`
Chris@269 101 echo -e "$start\t$end\t$frequency"
Chris@269 102 done > "$outfile.lab"
Chris@223 103
Chris@269 104 for ms in 50 100 150; do
Chris@269 105 mark=""
Chris@269 106 if [ "$ms" = "50" ]; then
Chris@269 107 if [ "$instrument" = "0" ]; then
Chris@269 108 mark=" <-- main generic preset for $filename (norm = $norm)";
Chris@269 109 else
Chris@269 110 mark=" <-- main piano preset for $filename (norm = $norm)";
Chris@269 111 fi
Chris@269 112 fi;
Chris@269 113 echo
Chris@269 114 echo "Validating against ground truth at $ms ms:"
Chris@269 115 egrep '(^[0-9]\.)|(^[012][0-9]\.)' "../piano-groundtruth/$filename.lab" > "$reference.lab"
Chris@269 116 "$yc" ../scripts/evaluate_lab.yeti "$ms" "$reference.lab" "$outfile.lab" | sed 's,$,'"$mark"','
Chris@269 117 done;
Chris@223 118 echo
Chris@269 119 done
Chris@223 120 done
Chris@222 121 done
Chris@222 122 done