Created
March 3, 2011 15:15
-
-
Save gmuller/852903 to your computer and use it in GitHub Desktop.
Revisions
-
gmuller created this gist
Mar 3, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ #include <stdio.h> #include <math.h> int main(){ double semitone_ratio, c0, c5, frequency, fracmidi; int midinote = 73; semitone_ratio = pow(2, 1/12.0); c5 = 220.0 * pow(semitone_ratio, 3); c0 = c5 * pow(0.5, 5); frequency = c0 * pow(semitone_ratio, midinote); //and in reverse fracmidi = log(frequency / c0) / log(semitone_ratio); midinote = ( int)(fracmidi + 0.5); }