Mercurial > hg > mirex2013
annotate audio_key_detection/qm-keydetector-v5/qm-keydetector.sh @ 86:01f69f1d5d3c tip
Add further archive versions
author | Chris Cannam |
---|---|
date | Thu, 01 Aug 2019 17:54:05 +0100 |
parents | f14a44513481 |
children |
rev | line source |
---|---|
Chris@11 | 1 |
Chris@11 | 2 mydir=`dirname "$0"` |
Chris@11 | 3 infile="$1" |
Chris@11 | 4 outfile="$2" |
Chris@11 | 5 |
Chris@11 | 6 if [ t"$infile" = "t" ] || [ t"$outfile" = "t" ]; then |
Chris@11 | 7 echo "Usage: $0 infile.wav outfile.txt" |
Chris@11 | 8 exit 2 |
Chris@11 | 9 fi |
Chris@11 | 10 |
Chris@11 | 11 mkdir -p "$mydir"/out || exit 1 |
Chris@11 | 12 |
Chris@11 | 13 echo "Processing input WAV file $infile, writing results to $outfile..." 1>&2 |
Chris@11 | 14 |
Chris@11 | 15 # We want output like |
Chris@11 | 16 # |
Chris@11 | 17 # Bb<TAB>minor |
Chris@11 | 18 # |
Chris@11 | 19 # Our Sonic Annotator output gives us something like that for each |
Chris@11 | 20 # detected key change (the feature label, in column 4), but we want |
Chris@11 | 21 # the modal key (modal in the statistical rather than the musical |
Chris@11 | 22 # sense!) and Sonic Annotator doesn't retain labels for summaries. So |
Chris@11 | 23 # let's write to a temporary file, retrieve the modal value, then pick |
Chris@11 | 24 # the label (from earlier in the file) whose value corresponds to it. |
Chris@11 | 25 |
Chris@11 | 26 VAMP_PATH="$mydir" sonic-annotator \ |
Chris@11 | 27 -t "$mydir"/qm-keydetector.ttl \ |
Chris@11 | 28 -w csv --csv-separator ";" \ |
Chris@11 | 29 --csv-basedir "$mydir/out" \ |
Chris@11 | 30 --csv-force \ |
Chris@11 | 31 -S mode \ |
Chris@11 | 32 "$infile" || exit 1 |
Chris@11 | 33 |
Chris@11 | 34 inbase=`basename "$infile"` |
Chris@11 | 35 inbase=${inbase%.*} |
Chris@11 | 36 tempfile="out/${inbase}_vamp_qm-vamp-plugins_qm-keydetector_key.csv" |
Chris@11 | 37 if [ ! -f "$tempfile" ]; then |
Chris@11 | 38 echo "Key output file $tempfile not found! bailing out"; exit 1 |
Chris@11 | 39 fi |
Chris@11 | 40 |
Chris@11 | 41 mode=`grep ';mode;' "$tempfile" | awk -F';' '{ print $4; }'` |
Chris@11 | 42 |
Chris@11 | 43 cat "$tempfile" | \ |
Chris@11 | 44 awk -F';' '{ print $2, $3 }' | \ |
Chris@11 | 45 grep "^$mode \"" | \ |
Chris@11 | 46 head -n 1 | \ |
Chris@11 | 47 sed -e 's/^[^"]*"//' -e 's/"[^"]*$//' -e 's,/ [^ ]* ,,' -e 's/ /\t/' \ |
Chris@11 | 48 > "$outfile" |
Chris@11 | 49 |
Chris@11 | 50 |
Chris@11 | 51 |
Chris@11 | 52 |