Finding a MIDI Note From the Period of a Waveform or Finding it from a String/Fret Grid, That Is the Question!
Sometimes the internet is wonderful and the search engines just provide what is asked for, a veritable (if not always verifiable) cargo cult of bounty. Then it sometimes isn't. Take this formula, for instance, it calculates the note number for a Musical Instrument Digital Interface (MIDI) Note On or Note Off command from the pitch of a note. Deriving the nearest MIDI note number from a tone of a given pitch. (Source: Google Search.) This is all well and good if you're talking about theoretical pitches, or working with a high end, high speed microcontroller that can measure a frequency quickly and spit out a MIDI command, but I like my microcontrollers low cost, like the venerable Atmel 328p. You can measure pitch with one of these, but you have to convert the wave's period to pitch, because the processor isn't really up to having a built in frequency counter. The way to do this is to measure the wave's period directly with the pulseIn() command, like so... voi...