#!/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";