diff options
author | B. Watson <yalhcru@gmail.com> | 2015-04-08 03:18:53 -0400 |
---|---|---|
committer | B. Watson <yalhcru@gmail.com> | 2015-04-08 03:18:53 -0400 |
commit | 122f3c401f23f84799802c7b9667bda222646487 (patch) | |
tree | bc77cc44c516eac71b2d6490574fd32a5b5efd65 /find_tuning | |
download | misc-scripts-122f3c401f23f84799802c7b9667bda222646487.tar.gz |
initial commit
Diffstat (limited to 'find_tuning')
-rwxr-xr-x | find_tuning | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/find_tuning b/find_tuning new file mode 100755 index 0000000..cbb4d73 --- /dev/null +++ b/find_tuning @@ -0,0 +1,56 @@ +#!/usr/bin/perl -w + +# 20110531 bkw: dirt-stupid wrapper for nnls-chroma's tuning estimator. +# Depends on vamp-plugin-sdk and nnls-chroma. Will choke on some filenames +# (e.g. ones with double-quotes, backticks, dollar signs...) + +# 20121106 bkw: Adding support for other formats besides wav/ogg/flac. + +# Although vamp-simple-host uses libsndfile, which supports ogg/vorbis, +# in practice it doesn't work real well: takes 120x (!) as long to analyze +# an ogg file as it does to extract with oggdec and analyze that. + +# Basically, anything that isn't named .wav or .flac will get decoded to wav +# with mplayer. This means we can actually use find_tuning on video files. +# It also means we're trusting the input filename extension to be correct! + +if($ARGV[0] && $ARGV[0] eq '-q') { + $quiet++; + shift; +} + +for(@ARGV) { + my $infile; + my $rm_infile = 0; + my $vamperrfile = "/tmp/find_tuning_$$.vamperrs"; + + if(/\.(?:wav|flac)$/i) { + $infile = $_; + } else { + $infile = "/tmp/find_tuning_$$.wav"; + $rm_infile = 1; + warn "Decoding $_ with mplayer\n" unless $quiet; + system("mplayer -really-quiet -benchmark -vo null -ao pcm:fast:file=\"$infile\" \"$_\""); + } + + warn "Analyzing with nnls-chroma\n" unless $quiet; + $freq = `vamp-simple-host nnls-chroma.so:tuning "$infile" 2>$vamperrfile`; + chomp $freq; + + $freq =~ s/.*: //s || do { + $errs = `cat $vamperrfile`; + die "Analysis failed: $errs\n"; + }; + + $freq =~ s/\s.*//; + $cents = 1200 * (log($freq/440)/log(2)); + + if($quiet) { + printf "%+2.2f\n", $cents; + } else { + printf "\n$_: A = $freq Hz, %+2.2f cents\n", $cents; + } + + unlink $infile if $rm_infile; + unlink $vamperrfile; +} |