For use with the MIDI (Musical Instrument Digital Interface) standard, a frequency mapping is defined by:
In Processing:
// log2(x) = log(x) / log(2); final static float LOG2 = log(2); int freqToPitch(float freq) { return int(69+12*log(freq/440)/LOG2); } // freqToPitch()
Where p is the MIDI note number. And in the opposite direction, to obtain the frequency from a MIDI note p, the formula is defined as:
In Processing:
float pitch2Freq (int p) { return pow(2,(float)(p-69)/12) * 440; } // pitch2Freq()
For notes in an A440 equal temperament, this formula delivers the standard MIDI note number (p). Any other frequencies fill the space between the whole numbers evenly. This allows MIDI instruments to be tuned very accurately in any microtuning scale, including non-western traditional tunings.
Calculate the note name from a note pitch (in Processing):
final static String[] names = {
"C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"
};
void setup()
{
println(pitch2Name(90));
} // setup()
String pitch2Name (int pitch)
{
return names[pitch%12]+((pitch/12)-1);
} // pitch2Name()
=> "Gb6"
Instrument groups:
- Piano
- Chromatic Percussion
- Organ
- Guitar
- Bass
- String
- Ensemble
- Brass
- Reed
- Pipe
- Synth Lead
- Synth Pad
- Synth Effects
- Ethnic
- Percussive
- Sound Effects
Resources:
http://en.wikipedia.org/wiki/Note
MIDI Note Number to Frequency Conversion Charts:
http://subsynth.sourceforge.net/midinote2freq.html
http://www.phys.unsw.edu.au/jw/notes.html
MIDI Instrument Map:
http://en.wikipedia.org/wiki/General_MIDI
MIDI Android Library:
https://code.google.com/p/android-midi-lib/