1
0

notes.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #define MIDI_START 36 // here starts our table, lowest is C2
  2. #define MIDI_NOTES 73
  3. #if defined(__AVR_ATmega328P__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny861__) || defined(__AVR_ATtiny4313__)
  4. #include "avr/pgmspace.h"
  5. // converting midi notes into the desired frequwnz for the tone function
  6. // the frequenz was calculated with libreoffice calc with this fm = (440 Hz)* 2^((m−69)/12) and than rounded.
  7. const PROGMEM unsigned int midiNoteToFreq[MIDI_NOTES] =
  8. {
  9. 65, // C2
  10. 69, 73, 78, 82, 87, 92, 98, 104, 110, 117, 123,
  11. 131, // C3
  12. 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247,
  13. 262, //C4
  14. 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494,
  15. 523, //C5
  16. 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988,
  17. 1047, //C6
  18. 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976,
  19. 2093, //C7
  20. 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951,
  21. 4186 //C8
  22. };
  23. #define getFrequency(n) (pgm_read_word(n - MIDI_START + midiNoteToFreq))
  24. #endif
  25. #ifdef ESP32
  26. const unsigned int midiNoteToFreq[MIDI_NOTES] =
  27. {
  28. 65, // C2
  29. 69, 73, 78, 82, 87, 92, 98, 104, 110, 117, 123,
  30. 131, // C3
  31. 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247,
  32. 262, //C4
  33. 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494,
  34. 523, //C5
  35. 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988,
  36. 1047, //C6
  37. 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976,
  38. 2093, //C7
  39. 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951,
  40. 4186 //C8
  41. };
  42. #define getFrequency(n) (midiNoteToFreq[n-MIDI_START])
  43. #endif