From 122f3c401f23f84799802c7b9667bda222646487 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 8 Apr 2015 03:18:53 -0400 Subject: initial commit --- notefreq | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 notefreq (limited to 'notefreq') diff --git a/notefreq b/notefreq new file mode 100755 index 0000000..49dbe60 --- /dev/null +++ b/notefreq @@ -0,0 +1,56 @@ +#!/usr/bin/perl -w + +sub usage { + die < 1, + 'C#' => 2, + Db => 2, + D => 3, + 'D#' => 4, + Eb => 4, + E => 5, + F => 6, + 'F#' => 7, + Gb => 7, + G => 8, + 'G#' => 9, + Ab => 9, + A => 10, + 'A#' => 11, + Bb => 11, + B => 12 + ); + +if(@ARGV && ($ARGV[0] =~ /^-a([.\d]+)$/)) { + $ref = $1; + shift; +} else { + $ref = 440; # A440 +} + +$refnum = $notes{A} + 12*4; + +$_ = shift; +($note, $oct) = /^([A-G][#b]?)-?(\d\d?)/i; + +usage unless $note; + +$num = $notes{ucfirst lc $note} + (12*$oct) - $refnum; + +$freq = $ref * (2 ** ($num/12)); + +print "$freq\n"; -- cgit v1.2.3