Sammy1Am / MoppyClassic

Moppy has been replaced with Moppy 2.0!
569 stars 190 forks source link

Notes shifted down one octave. #76

Closed nimaid closed 10 years ago

nimaid commented 10 years ago

I noticed that, in the array where you define the microsecond delays in the java program, you did so one octave lower than what they really are. For instance, the first entry on the line commented "C3 - B3" is 7645 us. However, that's the period for the note C4, not C3. The rest of the notes are shifted the same way as well.

I'm unsure if this was intentional or not, but I figured I would point it out to you.

EDIT: By logging the serial port output, I have determined that, indeed, the notes played are not shifted down as well. When I played the note C4 on channel 1, I was given 02 00 5F. Of course, 02 is the channel times 2. 00 5F is 95 decimal. Since the resolution I'm using is the default 40, I multiply 95 * 80, and get 7600, which is obviously the period for C4, with some rounding error. It seems to me that you made a commenting error. In fact, your program plays the notes C2 to B5, not C1 to B4.

TL;DR: Commenting was off on the microsecond table, and your program plays C2 to B5, not C1 to B4.

Sammy1Am commented 10 years ago

Hello there. I appreciate the scrutiny of my code; programming in a vacuum is tough because it's easy to miss mistakes that I've made myself.

In this particular case though, I'm confidant that my note labeling is correct (I've checked and re-checked it because you're not the first to say that it's off by an octave). I used the table here when doing the coding, but the frequencies are backed up by the information here.

A C4 is actually 261.63Hz, which works out to a period of 3.822ms (1/261.63). The note you actually played was a C3, which was correctly played at ~131Hz. It's probably not your fault though; I'm guessing you're getting your information about which note you're playing from a MIDI program on your PC. For some reason, there are several programs that mis-label notes by an octave. The only reason I can think of is that they didn't like the idea of a "C0" note, and decided to call it C1. Which... only sort of solves the problem anyway, since MIDI actually goes down to C-1 at 8Hz (I guess they could have decided to make C-1 into C0... that sorta makes sense for arrays).

Point being, I really do appreciate the review of my code, but it's correct in this case.

nimaid commented 10 years ago

Hmmm... it appears that we are getting different information. I am using the formula image, where p is the MIDI note number, and f is it's frequency. It's from the same wikipedia page you linked to for the frequencies. C0 is defined as midi note 0, C1 is 12, and so forth. C4 is MIDI note 48. If you plug that into the formula, you get 130.813.

It seems that there are a various sources saying that C1 is midi 0. My software shows the lowest note at C0, or MIDI note 0. I suppose labling the octaves themselves isn't standardized, so this entire discussion is moot.

Sammy1Am commented 10 years ago

So after doing a little more research, it appears you are correct that there is no universal standard for octave labeling. It would appear that I've been labeling my octaves using American Standard Pitch Notation which has been widely used for quite some time.

Based on that standard A4 = 440 (which is where that 440 in the equation comes from), and based on that the MIDI note number for an A4 is 69. A4 is 9 semi-tones above C4, and therefore C4 is MIDI note 60.

To prevent further confusion I've added a comment in the source code to specify the naming convention being used.