Does MIDI Octaves Start at 0 or 1?

Post Reply
User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Does MIDI Octaves Start at 0 or 1?

Post by GeorgeMcGinn »

I'm working on expanding Syntil8 to create sheet music so you can write and save songs.

However, C4 is supposed to be the middle C, which resides below the staff (on the 6th line or the first below the staff lines).

However, it sounds an octave too high when I compare C4 on my real guitars or keyboard.

Then I found this while researching:
The MIDI specification only defines note number 60 as "Middle C", and all other notes are relative. The absolute octave number designations shown here are based on Middle C = C5, which is an arbitrary assignment.
And this:
There is a discrepancy that occurs between various models of MIDI devices and software programs, and that concerns the octave numbers for note names. If your MIDI software/device considers octave 0 as being the lowest octave of the MIDI note range, then middle C's note name is C5. The lowest note name is then C0 (note number 0), and the highest possible note name is G10 (note number 127).

Some software/devices instead consider the third octave of the MIDI note range (2 octaves below middle C) as octave 0.  In that case, the first 2 octaves  are referred to as -2 and -1. So, middle C's note name is C3, the lowest note name is C-2, and the highest note name is G8. 
So my question is what range does SmartBASIC allow for octaves.
IMG_0014.JPG
IMG_0014.JPG (108.17 KiB) Viewed 1975 times
The first bar shows the notation of C4, middle C, and the second bar shows what the SmartBASIC documentation C4 sounds like. It is an octave too high.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
Mr. Kibernetik
Site Admin
Posts: 4782
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Does MIDI Octaves Start at 0 or 1?

Post by Mr. Kibernetik »

Smart BASIC uses following notation system. So, C4 note is the 60th note.
Image
Reference: https://en.wikipedia.org/wiki/Octave

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Does MIDI Octaves Start at 0 or 1?

Post by GeorgeMcGinn »

I agree with you as we both show the middle C on the treble clef stave, and yes, even on my guitar charts showing the notes on a music stave, C4 is 1 line below the treble clef. However, the note that plays at note #60 is actually C5, or in the 3rd space on the treble clef.

I guess I need to modify my question. I have a musically trained ear, and when I play songs, I play them mostly by ear, and sometimes from a music sheet or score. My issue is note #60 plays an octave higher than it supposed to be.

On a guitar, the C4, middle C, note #60, is played on the 5th string, 3rd fret. The sound coming from the program using note #60 sounds like the C5 note that is played on the 2nd string, 2nd fret on a standard tuned guitar.

I also ran the program "Notion" and the C5 key sounds like the SmartBASIC Synthesizer code's C4 key. When I compare the SmartBASIC program with real intruments, the program plays C4 an octave higher than every mucical instrument I have. Try it yourself. Since the example program does not work for me, I am using Rbytes's Synnthesizer v2,2 (code and files can be downloaded at: https://www.dropbox.com/sh/c095ysw168s2 ... nJVLa?dl=0.)

I am thinking that the error is in the program, as it starts off with C as C1 and not C0, and ends with C7, and not C8. That would cause C4, note 60, to play an octave higher. I'm looking over this code, but since coding MIDI is very new to me, I have a learning code that's getting in the way (Ricardo, maybe you can look at the code and see if it is a coding error.

Mr K – does C start at note number zero? It may be a bug in SmartBASIC, for when I look at the NOTES table in the documentation, you do start C at C0, but instead of it being note #0, it is note #12, and that would push it an octave higher. What is Note 0 in SmartBASIC? (Below is documentation from SmartBASIC's Help Menu). For if you are using the MIDI standards from MIDI.ORG, C0 should have a 0 in front of it, not a 12.

Could this be a bug in SmartBASIC?

If so, for now, (I would need to test this) if I subtract 12 from the Note number provided, then I would get the right note, as, according to your chart, when I use 48, it plays the correct sound for C4, or the middle C. However, if I subtract 12 from 12 (C0) I will be using Note 0 for the first C note. Will this cause an error?

This is right out of the SB documentation. I have not the foggiest idea why C0 starts at note 12 (unless 0-11 are reserved for the drums).
NOTE NUMBERS
12-C0 24-C1 36-C2 48-C3 60-C4 72-C5 84-C6 96-C7 108-C8
13-C#0 25-C#1 37-C#2 49-C#3 61-C#4 73-C#5 85-C#6 97-C#7 109-C#8
14-D0 26-D1 38-D2 50-D3 62-D4 74-D5 86-D6 98-D7 110-D8
15-D#0 27-D#1 39-D#2 51-D#3 63-D#4 75-D#5 87-D#6 99-D#7 111-D#8
16-E0 28-E1 40-E2 52-E3 64-E4 76-E5 88-E6 100-E7 112-E8
17-F0 29-F1 41-F2 53-F3 65-F4 77-F5 89-F6 101-F7 113-F8
18-F#0 30-F#1 42-F#2 54-F#3 66-F#4 78-F#5 90-F#6 102-F#7 114-F#8
19-G0 31-G1 43-G2 55-G3 67-G4 79-G5 91-G6 103-G7 115-G8
20-G#0 32-G#1 44-G#2 56-G#3 68-G#4 80-G#5 92-G#6 104-G#7 116-G#8
21-A0 33-A1 45-A2 57-A3 69-A4 81-A5 93-A6 105-A7 117-A8
22-A#0 34-A#1 46-A#2 58-A#3 70-A#4 82-A#5 94-A#6 106-A#7 118-A#8
23-B0 35-B1 47-B2 59-B3 71-B4 83-B5 95-B6 107-B7 119-B8
Simply, the sound is too high in the octave range. Try and compare the middle C with a properly tuned guitar or fullsized keyboard (pianos and keyboards, the first note is a C (as well as the last note)) and you'll hear what I am talking about.

So now my question is: is the iPad's synthesizer not being used correctly by SmartBASIC or has a different starting point? Is the code that you use to create the internal synthesizer not starting at note #0 (the first note is called note 0)? Is it a bug in SB? Or in iOS?

For reference, here is the main screen for the App. Notice that the Octave starts with 1 and ends at 7, instead of starting at 0 and ending at 8.

Help understanding this would be greatly appreciated.
Attachments
IMG_0019.JPG
IMG_0019.JPG (118.87 KiB) Viewed 1966 times
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
Mr. Kibernetik
Site Admin
Posts: 4782
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Does MIDI Octaves Start at 0 or 1?

Post by Mr. Kibernetik »

This is C4 sound example from Wikipedia: https://en.wikipedia.org/wiki/C_(musical_note)
Smart BASIC plays exactly the same note as C4.

This is another C4 sample: https://freesound.org/people/Goup_1/sounds/176449/
This is a more detailed example: https://www.youtube.com/watch?v=yoeJk-1UVn0
GeorgeMcGinn wrote:
Wed Jan 24, 2018 6:57 am
Mr K – does C start at note number zero? It may be a bug in SmartBASIC, for when I look at the NOTES table in the documentation, you do start C at C0, but instead of it being note #0, it is note #12, and that would push it an octave higher. What is Note 0 in SmartBASIC? (Below is documentation from SmartBASIC's Help Menu). For if you are using the MIDI standards from MIDI.ORG, C0 should have a 0 in front of it, not a 12.
Could this be a bug in SmartBASIC?
You can see an answer in the picture I gave in the previous post why C0 is not note #0 but is note #12.
Notation of Smart BASIC starts with C0, and this is the 12th note. Of course you can get 0-11th notes using MIDI commands, but it is -1 octave.

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Does MIDI Octaves Start at 0 or 1?

Post by GeorgeMcGinn »

Yes, that example is a middle C. On my electronic keyboard it sounds the same, on my guitar it sounds the same, but not on the program Synthesizer v2.2 that I provided the link to.

The corresponding sound is the very first key on the keyboard of the SB App, and not the C that the arrow points to. The only way to get the same exact sound is to set the octave slider to 3. Then the C with the arrow sounds exactly like a middle C.

When I run the Synthesizer from the Examples folder, the very first key is a C note, and yes, it is the middle C and sounds exact;y like the sample you provided.

I even conducted an experiment by setting up an oscilliscope to get to the bottom of this.

With Synthesizer 2.2 App, set the octave slider to 4, and playing the C note with the arrow, it gives me a reading of about 523.25 to 561.3 Hertz, or a C5 note. A true middle C (C4) which is the first C note on Ricardo's keyboard comes in with 261.62 - 261.63 Hertz. And I verified it with my Casio keyboard and my Stratocaster guitar.

Thank your Mr. K. for helping me out on this and giving me a good basis on how SmartBASIC uses MIDI. Your help was invaluable. With SB producing the correct sound for the note, I will write to Ricardo as it is a coding issue in his program. Yes, the arrow points to a C note, but it is not necessary the Middle C when the octave is set to 4 (that is what is confusing me) and I have been playing around with the NOTES statements today, as until today I have never used them, so I also created a program that keeps repeating the C4 note that plays correctly.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

Post Reply