Skip to content

Instantly share code, notes, and snippets.

@dropmeaword
Created April 11, 2013 21:51
Show Gist options
  • Save dropmeaword/5367512 to your computer and use it in GitHub Desktop.
Save dropmeaword/5367512 to your computer and use it in GitHub Desktop.
MIDI to frequency conversions
double midi2freq(int midi)
{
double f;
f = exp (log (440.0) + (double)(midi - 69) * log (2.0) / 12.0);
return (f);
}
int freq2midi(double f)
{
int midi;
midi = (int)(0.5 + 69.0 + 12.0 / log (2.0) * log (f / 440.0));
return (midi);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment