You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
3.7KB

  1. // Table of midi note frequencies * 2
  2. // They are times 2 for greater accuracy, yet still fits in a word.
  3. // Generated from Excel by =ROUND(2*440/32*(2^((x-9)/12)),0) for 0<x<128
  4. // The lowest notes might not work, depending on the Arduino clock frequency
  5. // This is for the Teensy Audio library which specifies
  6. // frequencies as floating point. See make_notetab.xlsx
  7. const float tune_frequencies2_PGM[128] =
  8. {
  9. 8.1758, 8.6620, 9.1770, 9.7227, 10.3009, 10.9134, 11.5623, 12.2499,
  10. 12.9783, 13.7500, 14.5676, 15.4339, 16.3516, 17.3239, 18.3540, 19.4454,
  11. 20.6017, 21.8268, 23.1247, 24.4997, 25.9565, 27.5000, 29.1352, 30.8677,
  12. 32.7032, 34.6478, 36.7081, 38.8909, 41.2034, 43.6535, 46.2493, 48.9994,
  13. 51.9131, 55.0000, 58.2705, 61.7354, 65.4064, 69.2957, 73.4162, 77.7817,
  14. 82.4069, 87.3071, 92.4986, 97.9989, 103.8262, 110.0000, 116.5409, 123.4708,
  15. 130.8128, 138.5913, 146.8324, 155.5635, 164.8138, 174.6141, 184.9972, 195.9977,
  16. 207.6523, 220.0000, 233.0819, 246.9417, 261.6256, 277.1826, 293.6648, 311.1270,
  17. 329.6276, 349.2282, 369.9944, 391.9954, 415.3047, 440.0000, 466.1638, 493.8833,
  18. 523.2511, 554.3653, 587.3295, 622.2540, 659.2551, 698.4565, 739.9888, 783.9909,
  19. 830.6094, 880.0000, 932.3275, 987.7666, 1046.5023, 1108.7305, 1174.6591, 1244.5079,
  20. 1318.5102, 1396.9129, 1479.9777, 1567.9817, 1661.2188, 1760.0000, 1864.6550, 1975.5332,
  21. 2093.0045, 2217.4610, 2349.3181, 2489.0159, 2637.0205, 2793.8259, 2959.9554, 3135.9635,
  22. 3322.4376, 3520.0000, 3729.3101, 3951.0664, 4186.0090, 4434.9221, 4698.6363, 4978.0317,
  23. 5274.0409, 5587.6517, 5919.9108, 6271.9270, 6644.8752, 7040.0000, 7458.6202, 7902.1328,
  24. 8372.0181, 8869.8442, 9397.2726, 9956.0635, 10548.0818, 11175.3034, 11839.8215, 12543.8540
  25. };
  26. #define CMD_PLAYNOTE 0x90 /* play a note: low nibble is generator #, note is next byte */
  27. #define CMD_STOPNOTE 0x80 /* stop a note: low nibble is generator # */
  28. #define CMD_CHANGEINST 0xc0
  29. #define CMD_RESTART 0xe0 /* restart the score from the beginning */
  30. #define CMD_STOP 0xf0 /* stop playing */
  31. const float velocity2amplitude[127] = {
  32. 0.01778,0.01966,0.02164,0.02371,0.02588,0.02814,0.03049,0.03294,0.03549,0.03812,
  33. 0.04086,0.04369,0.04661,0.04963,0.05274,0.05594,0.05924,0.06264,0.06613,0.06972,
  34. 0.07340,0.07717,0.08104,0.08500,0.08906,0.09321,0.09746,0.10180,0.10624,0.11077,
  35. 0.11539,0.12011,0.12493,0.12984,0.13484,0.13994,0.14513,0.15042,0.15581,0.16128,
  36. 0.16685,0.17252,0.17828,0.18414,0.19009,0.19613,0.20227,0.20851,0.21484,0.22126,
  37. 0.22778,0.23439,0.24110,0.24790,0.25480,0.26179,0.26887,0.27605,0.28333,0.29070,
  38. 0.29816,0.30572,0.31337,0.32112,0.32896,0.33690,0.34493,0.35306,0.36128,0.36960,
  39. 0.37801,0.38651,0.39511,0.40381,0.41260,0.42148,0.43046,0.43953,0.44870,0.45796,
  40. 0.46732,0.47677,0.48631,0.49595,0.50569,0.51552,0.52544,0.53546,0.54557,0.55578,
  41. 0.56609,0.57648,0.58697,0.59756,0.60824,0.61902,0.62989,0.64085,0.65191,0.66307,
  42. 0.67432,0.68566,0.69710,0.70863,0.72026,0.73198,0.74380,0.75571,0.76771,0.77981,
  43. 0.79201,0.80430,0.81668,0.82916,0.84174,0.85440,0.86717,0.88003,0.89298,0.90602,
  44. 0.91917,0.93240,0.94573,0.95916,0.97268,0.98629,1.00000
  45. };
  46. /*
  47. #! /usr/bin/perl
  48. # The Interpretation of MIDI Velocity
  49. # Roger B. Dannenberg
  50. # School of Computer Science, Carnegie Mellon University
  51. $dynamic_range = 35;
  52. $r = 10 ** ($dynamic_range / 20);
  53. $b = 127 / (126 * sqrt($r)) - 1/126;
  54. $m = (1 - $b) / 127;
  55. print "const float velocity2amplitude[127] = {\n";
  56. for ($v=1; $v <= 127; $v++) {
  57. $a = ($m * $v + $b) ** 2;
  58. printf "%.5f", $a;
  59. print "," if $v < 127;
  60. print "\n" if ($v % 10) == 0;
  61. }
  62. print "\n};\n";
  63. */
  64. // User must supply this score array
  65. extern unsigned char score[];