#!/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! system("rm -f /tmp/find_tuning_*"); 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: $infile\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; }