FortySevenEffects / arduino_midi_library

MIDI for Arduino
MIT License
1.56k stars 252 forks source link

Simple Synth pitches are incorrect #204

Open franky47 opened 3 years ago

franky47 commented 3 years ago

See #203.

Correct values of pitches: https://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies

Values must be rounded to the nearest integer, as the tone function does not accept floating point values.

akshay4n commented 3 years ago

@franky47 i would like to work on this

franky47 commented 3 years ago

@akshay4n, awesome, go ahead !

Ping me here if there's anything you need help with.

akshay4n commented 3 years ago

@franky47 I took a look at #203 and went through https://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies and https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/ The problem isn't quite clear to me

franky47 commented 3 years ago

I initially thought that the frequency values were off in the pitch list, but the problem is in reading the table.

It starts at B0, which should map to MIDI note number 23. So the index at which we read the pitch should be noteNumber - 23 to map to the correct note (while taking care not to output negative indices): https://github.com/FortySevenEffects/arduino_midi_library/blob/master/examples/SimpleSynth/SimpleSynth.ino#L54