Why are the MIDI Note Numbers off by an octave?


#1

I was working on something today where this was mildly relevant, and I noticed that the MIDI note numbers are an octave off the standard. Shouldn't C4 be MIDI Note# 60? Using MidiMessage::getMidiNoteInHz returns the wrong value, which was causing problems when using some samples that followed the standard. I've seen other apps that do the same thing, I'm just curious as to why it was implemented this way. 


Hello, Juce is excellent so far, wanted to alert you to a dicrepancy in the AudioSynthesiser demo
#2

http://www.juce.com/doc/classMidiKeyboardComponent#a0fa0517007dae385e61b92a938e5a030 

https://github.com/julianstorer/JUCE/blob/5448e88f3974f00af9524a4c80e753a2faadd6c3/modules/juce_audio_basics/midi/juce_MidiMessage.cpp

double MidiMessage::getMidiNoteInHertz (int noteNumber, const double frequencyOfA) noexcept
{
  return frequencyOfA * pow (2.0, (noteNumber - 69) / 12.0);
}

 

feel free to change "noteNumber - 69" to "noteNumber - 69 +/- 12" to fix the octave or just +/-12 the noteNumber before you call that method. 


#3

Thank you! That solved a bunch of issues I was having. 


#4

I'd just thought I should add some thoughts.

Acc to the Midi specification, the middle C (that is the C nearest under tuning A of 4440Hz) is (always) assigned midi note number 60. Which means a midi tune/file will always play in the same octave on every midi player (made acc to the midi spec and under default conditions with no key transpose active of course)

What isn't standardized however is how to name the octave this middle C/#60 is assigned to. Some say it's number 4 and hence call this note C4 because it's the fourth C on a normal 88-keys piano. Some say it's C5 because it's C number 5 starting with C0 as the midi note number 0. There are other standards too.

So the answer to your question is "not neccessarily" and getMidiNoteInHertz() is correct. The places to worry about getting the wrong midi key is where you depend on the octave number. This should only be regarded as a label in the midi world and as such preferably be user assignable in the settings for the midi equipment when applicable.