Permalink
Find file Copy path
85e63b5 Feb 7, 2016
1 contributor

Users who have contributed to this file

360 lines (311 sloc) 34.8 KB
//1024 values from A1 (55Hz) to A7 (3520Hz)
int NOTELOOKUP[]={
65536, 65802, 66071, 66340, 66610, 66881, 67154, 67427, 67702, 67978, 68255, 68533, 68812, 69092, 69374, 69656, 69940, 70225, 70511, 70798, 71087, 71376, 71667, 71959, 72252, 72546, 72842, 73139, 73437, 73736, 74036, 74338,
74641, 74945, 75250, 75557, 75864, 76173, 76484, 76795, 77108, 77422, 77738, 78054, 78372, 78692, 79012, 79334, 79657, 79982, 80307, 80635, 80963, 81293, 81624, 81957, 82290, 82626, 82962, 83300, 83640, 83980, 84322, 84666,
85011, 85357, 85705, 86054, 86404, 86756, 87110, 87465, 87821, 88179, 88538, 88899, 89261, 89624, 89990, 90356, 90724, 91094, 91465, 91837, 92212, 92587, 92964, 93343, 93723, 94105, 94489, 94873, 95260, 95648, 96038, 96429,
96822, 97216, 97612, 98010, 98409, 98810, 99212, 99617, 100022, 100430, 100839, 101250, 101662, 102076, 102492, 102910, 103329, 103750, 104172, 104597, 105023, 105451, 105880, 106312, 106745, 107180, 107616, 108055, 108495, 108937, 109381, 109826,
110274, 110723, 111174, 111627, 112081, 112538, 112996, 113457, 113919, 114383, 114849, 115317, 115787, 116258, 116732, 117207, 117685, 118164, 118646, 119129, 119614, 120101, 120591, 121082, 121575, 122070, 122568, 123067, 123568, 124072, 124577, 125085,
125594, 126106, 126620, 127135, 127653, 128173, 128695, 129220, 129746, 130275, 130805, 131338, 131873, 132410, 132950, 133491, 134035, 134581, 135129, 135680, 136233, 136788, 137345, 137904, 138466, 139030, 139597, 140165, 140736, 141310, 141885, 142463,
143044, 143626, 144211, 144799, 145389, 145981, 146576, 147173, 147772, 148374, 148979, 149586, 150195, 150807, 151421, 152038, 152657, 153279, 153904, 154531, 155160, 155792, 156427, 157064, 157704, 158346, 158991, 159639, 160289, 160942, 161598, 162256,
162917, 163581, 164247, 164916, 165588, 166263, 166940, 167620, 168303, 168988, 169677, 170368, 171062, 171759, 172459, 173161, 173867, 174575, 175286, 176000, 176717, 177437, 178160, 178885, 179614, 180346, 181080, 181818, 182559, 183303, 184049, 184799,
185552, 186308, 187067, 187829, 188594, 189362, 190133, 190908, 191686, 192467, 193251, 194038, 194828, 195622, 196419, 197219, 198022, 198829, 199639, 200452, 201269, 202089, 202912, 203739, 204569, 205402, 206239, 207079, 207922, 208769, 209620, 210474,
211331, 212192, 213056, 213924, 214796, 215671, 216549, 217432, 218317, 219207, 220100, 220996, 221897, 222800, 223708, 224619, 225534, 226453, 227376, 228302, 229232, 230166, 231103, 232045, 232990, 233939, 234892, 235849, 236810, 237775, 238743, 239716,
240692, 241673, 242657, 243646, 244638, 245635, 246635, 247640, 248649, 249662, 250679, 251700, 252725, 253755, 254789, 255827, 256869, 257915, 258966, 260021, 261080, 262144, 263211, 264284, 265360, 266441, 267527, 268616, 269711, 270809, 271913, 273020,
274132, 275249, 276370, 277496, 278627, 279762, 280901, 282046, 283195, 284348, 285507, 286670, 287837, 289010, 290187, 291369, 292556, 293748, 294945, 296146, 297353, 298564, 299780, 301002, 302228, 303459, 304695, 305936, 307183, 308434, 309690, 310952,
312219, 313490, 314768, 316050, 317337, 318630, 319928, 321231, 322540, 323854, 325173, 326498, 327828, 329163, 330504, 331850, 333202, 334560, 335923, 337291, 338665, 340045, 341430, 342821, 344217, 345620, 347027, 348441, 349861, 351286, 352717, 354154,
355596, 357045, 358499, 359960, 361426, 362898, 364377, 365861, 367352, 368848, 370351, 371859, 373374, 374895, 376422, 377956, 379495, 381041, 382593, 384152, 385717, 387288, 388866, 390450, 392041, 393638, 395241, 396851, 398468, 400091, 401721, 403357,
405001, 406650, 408307, 409970, 411640, 413317, 415001, 416691, 418389, 420093, 421805, 423523, 425248, 426980, 428720, 430466, 432220, 433981, 435748, 437524, 439306, 441095, 442892, 444697, 446508, 448327, 450153, 451987, 453828, 455677, 457533, 459397,
461269, 463148, 465034, 466929, 468831, 470741, 472658, 474584, 476517, 478458, 480407, 482364, 484329, 486302, 488283, 490272, 492270, 494275, 496288, 498310, 500340, 502379, 504425, 506480, 508543, 510615, 512695, 514783, 516880, 518986, 521100, 523223,
525354, 527495, 529643, 531801, 533967, 536143, 538326, 540520, 542721, 544932, 547152, 549381, 551619, 553866, 556122, 558388, 560662, 562947, 565240, 567542, 569854, 572176, 574506, 576847, 579197, 581556, 583925, 586304, 588692, 591091, 593498, 595916,
598344, 600781, 603228, 605686, 608153, 610631, 613118, 615616, 618124, 620642, 623170, 625708, 628257, 630817, 633386, 635967, 638557, 641159, 643770, 646393, 649026, 651670, 654325, 656990, 659666, 662354, 665052, 667761, 670481, 673213, 675955, 678709,
681474, 684250, 687037, 689836, 692646, 695468, 698301, 701145, 704001, 706869, 709749, 712640, 715543, 718458, 721385, 724323, 727274, 730237, 733212, 736198, 739197, 742209, 745232, 748268, 751316, 754377, 757450, 760535, 763634, 766744, 769868, 773004,
776153, 779315, 782490, 785677, 788878, 792091, 795318, 798558, 801811, 805077, 808357, 811650, 814956, 818276, 821610, 824956, 828317, 831691, 835079, 838481, 841897, 845326, 848770, 852227, 855699, 859185, 862685, 866199, 869728, 873271, 876828, 880400,
883987, 887587, 891203, 894834, 898479, 902139, 905814, 909504, 913209, 916929, 920665, 924415, 928181, 931961, 935758, 939570, 943398, 947240, 951100, 954974, 958864, 962770, 966692, 970630, 974584, 978554, 982541, 986543, 990562, 994597, 998649, 1002717,
1006802, 1010903, 1015021, 1019156, 1023308, 1027476, 1031662, 1035865, 1040084, 1044321, 1048576, 1052847, 1057136, 1061442, 1065766, 1070108, 1074467, 1078844, 1083239, 1087652, 1092082, 1096531, 1100998, 1105483, 1109987, 1114508, 1119048, 1123607, 1128184, 1132780, 1137395, 1142028,
1146680, 1151351, 1156042, 1160751, 1165479, 1170227, 1174994, 1179781, 1184587, 1189412, 1194258, 1199123, 1204007, 1208912, 1213837, 1218781, 1223746, 1228731, 1233737, 1238763, 1243809, 1248876, 1253963, 1259072, 1264201, 1269351, 1274521, 1279713, 1284926, 1290161, 1295416, 1300694,
1305993, 1311313, 1316655, 1322018, 1327404, 1332811, 1338240, 1343692, 1349166, 1354662, 1360180, 1365721, 1371285, 1376871, 1382480, 1388111, 1393766, 1399444, 1405145, 1410869, 1416616, 1422387, 1428181, 1433999, 1439841, 1445706, 1451595, 1457509, 1463446, 1469408, 1475393, 1481404,
1487438, 1493498, 1499582, 1505690, 1511824, 1517983, 1524167, 1530375, 1536610, 1542869, 1549154, 1555465, 1561802, 1568164, 1574552, 1580966, 1587406, 1593873, 1600366, 1606885, 1613431, 1620004, 1626603, 1633229, 1639882, 1646563, 1653270, 1660005, 1666767, 1673557, 1680375, 1687220,
1694094, 1700994, 1707924, 1714881, 1721867, 1728881, 1735925, 1742995, 1750097, 1757225, 1764384, 1771571, 1778789, 1786034, 1793310, 1800615, 1807951, 1815315, 1822711, 1830135, 1837591, 1845076, 1852593, 1860139, 1867717, 1875325, 1882965, 1890635, 1898338, 1906070, 1913835, 1921631,
1929460, 1937319, 1945212, 1953135, 1961092, 1969080, 1977102, 1985155, 1993243, 2001362, 2009516, 2017701, 2025921, 2034173, 2042461, 2050780, 2059135, 2067522, 2075946, 2084401, 2092894, 2101418, 2109980, 2118574, 2127205, 2135870, 2144572, 2153307, 2162080, 2170886, 2179731, 2188609,
2197526, 2206478, 2215466, 2224491, 2233553, 2242652, 2251787, 2260960, 2270171, 2279419, 2288704, 2298028, 2307389, 2316788, 2326226, 2335702, 2345217, 2354771, 2364363, 2373995, 2383666, 2393376, 2403126, 2412915, 2422745, 2432614, 2442524, 2452474, 2462464, 2472495, 2482568, 2492681,
2502835, 2513031, 2523268, 2533547, 2543868, 2554230, 2564635, 2575083, 2585573, 2596106, 2606681, 2617300, 2627962, 2638667, 2649416, 2660209, 2671046, 2681927, 2692852, 2703822, 2714836, 2725895, 2737000, 2748149, 2759344, 2770585, 2781871, 2793204, 2804582, 2816007, 2827479, 2838997,
2850562, 2862174, 2873834, 2885541, 2897295, 2909098, 2920948, 2932847, 2944795, 2956791, 2968836, 2980930, 2993073, 3005266, 3017508, 3029800, 3042143, 3054535, 3066979, 3079472, 3092017, 3104613, 3117260, 3129959, 3142709, 3155511, 3168366, 3181272, 3194232, 3207244, 3220309, 3233428,
3246600, 3259825, 3273104, 3286438, 3299826, 3313268, 3326765, 3340317, 3353925, 3367587, 3381306, 3395080, 3408910, 3422797, 3436740, 3450740, 3464797, 3478912, 3493084, 3507313, 3521601, 3535947, 3550351, 3564814, 3579336, 3593916, 3608557, 3623257, 3638016, 3652837, 3667717, 3682658,
3697662, 3712725, 3727849, 3743035, 3758283, 3773593, 3788965, 3804400, 3819898, 3835459, 3851083, 3866771, 3882523, 3898339, 3914219, 3930165, 3946175, 3962250, 3978391, 3994597, 4010870, 4027209, 4043614, 4060087, 4076626, 4093233, 4109907, 4126650, 4143460, 4160339, 4177287, 4194304
};
//1024 values from A1 (55Hz) to A7 (3520Hz) - midi notes 21 - 105
int NOTELOOKUPSCALE[]={
65536, 65536, 65536, 65536, 65536, 65536, 65536, 65536, 69432, 69432, 69432, 69432, 69432, 69432, 69432, 69432, 69432, 69432, 69432, 69432, 69432, 69432, 73561, 73561, 73561, 73561, 73561, 73561, 73561, 73561, 73561, 73561,
73561, 73561, 73561, 73561, 77935, 77935, 77935, 77935, 77935, 77935, 77935, 77935, 77935, 77935, 77935, 77935, 77935, 77935, 82570, 82570, 82570, 82570, 82570, 82570, 82570, 82570, 82570, 82570, 82570, 82570, 82570, 82570,
87480, 87480, 87480, 87480, 87480, 87480, 87480, 87480, 87480, 87480, 87480, 87480, 87480, 87480, 87480, 92681, 92681, 92681, 92681, 92681, 92681, 92681, 92681, 92681, 92681, 92681, 92681, 92681, 92681, 98193, 98193, 98193,
98193, 98193, 98193, 98193, 98193, 98193, 98193, 98193, 98193, 98193, 98193, 104031, 104031, 104031, 104031, 104031, 104031, 104031, 104031, 104031, 104031, 104031, 104031, 104031, 104031, 110217, 110217, 110217, 110217, 110217, 110217, 110217,
110217, 110217, 110217, 110217, 110217, 110217, 110217, 116771, 116771, 116771, 116771, 116771, 116771, 116771, 116771, 116771, 116771, 116771, 116771, 116771, 116771, 116771, 123715, 123715, 123715, 123715, 123715, 123715, 123715, 123715, 123715, 123715,
123715, 123715, 123715, 123715, 131072, 131072, 131072, 131072, 131072, 131072, 131072, 131072, 131072, 131072, 131072, 131072, 131072, 131072, 138865, 138865, 138865, 138865, 138865, 138865, 138865, 138865, 138865, 138865, 138865, 138865, 138865, 138865,
147123, 147123, 147123, 147123, 147123, 147123, 147123, 147123, 147123, 147123, 147123, 147123, 147123, 147123, 147123, 155871, 155871, 155871, 155871, 155871, 155871, 155871, 155871, 155871, 155871, 155871, 155871, 155871, 155871, 165140, 165140, 165140,
165140, 165140, 165140, 165140, 165140, 165140, 165140, 165140, 165140, 165140, 165140, 174960, 174960, 174960, 174960, 174960, 174960, 174960, 174960, 174960, 174960, 174960, 174960, 174960, 174960, 185363, 185363, 185363, 185363, 185363, 185363, 185363,
185363, 185363, 185363, 185363, 185363, 185363, 185363, 196386, 196386, 196386, 196386, 196386, 196386, 196386, 196386, 196386, 196386, 196386, 196386, 196386, 196386, 196386, 208063, 208063, 208063, 208063, 208063, 208063, 208063, 208063, 208063, 208063,
208063, 208063, 208063, 208063, 220435, 220435, 220435, 220435, 220435, 220435, 220435, 220435, 220435, 220435, 220435, 220435, 220435, 220435, 233543, 233543, 233543, 233543, 233543, 233543, 233543, 233543, 233543, 233543, 233543, 233543, 233543, 233543,
247430, 247430, 247430, 247430, 247430, 247430, 247430, 247430, 247430, 247430, 247430, 247430, 247430, 247430, 262144, 262144, 262144, 262144, 262144, 262144, 262144, 262144, 262144, 262144, 262144, 262144, 262144, 262144, 262144, 277731, 277731, 277731,
277731, 277731, 277731, 277731, 277731, 277731, 277731, 277731, 277731, 277731, 277731, 294246, 294246, 294246, 294246, 294246, 294246, 294246, 294246, 294246, 294246, 294246, 294246, 294246, 294246, 311743, 311743, 311743, 311743, 311743, 311743, 311743,
311743, 311743, 311743, 311743, 311743, 311743, 311743, 330280, 330280, 330280, 330280, 330280, 330280, 330280, 330280, 330280, 330280, 330280, 330280, 330280, 330280, 349920, 349920, 349920, 349920, 349920, 349920, 349920, 349920, 349920, 349920, 349920,
349920, 349920, 349920, 349920, 370727, 370727, 370727, 370727, 370727, 370727, 370727, 370727, 370727, 370727, 370727, 370727, 370727, 370727, 392772, 392772, 392772, 392772, 392772, 392772, 392772, 392772, 392772, 392772, 392772, 392772, 392772, 392772,
416127, 416127, 416127, 416127, 416127, 416127, 416127, 416127, 416127, 416127, 416127, 416127, 416127, 416127, 440871, 440871, 440871, 440871, 440871, 440871, 440871, 440871, 440871, 440871, 440871, 440871, 440871, 440871, 467087, 467087, 467087, 467087,
467087, 467087, 467087, 467087, 467087, 467087, 467087, 467087, 467087, 467087, 467087, 494861, 494861, 494861, 494861, 494861, 494861, 494861, 494861, 494861, 494861, 494861, 494861, 494861, 494861, 524288, 524288, 524288, 524288, 524288, 524288, 524288,
524288, 524288, 524288, 524288, 524288, 524288, 524288, 555463, 555463, 555463, 555463, 555463, 555463, 555463, 555463, 555463, 555463, 555463, 555463, 555463, 555463, 588493, 588493, 588493, 588493, 588493, 588493, 588493, 588493, 588493, 588493, 588493,
588493, 588493, 588493, 588493, 623487, 623487, 623487, 623487, 623487, 623487, 623487, 623487, 623487, 623487, 623487, 623487, 623487, 623487, 660561, 660561, 660561, 660561, 660561, 660561, 660561, 660561, 660561, 660561, 660561, 660561, 660561, 660561,
699840, 699840, 699840, 699840, 699840, 699840, 699840, 699840, 699840, 699840, 699840, 699840, 699840, 699840, 741455, 741455, 741455, 741455, 741455, 741455, 741455, 741455, 741455, 741455, 741455, 741455, 741455, 741455, 785544, 785544, 785544, 785544,
785544, 785544, 785544, 785544, 785544, 785544, 785544, 785544, 785544, 785544, 785544, 832255, 832255, 832255, 832255, 832255, 832255, 832255, 832255, 832255, 832255, 832255, 832255, 832255, 832255, 881743, 881743, 881743, 881743, 881743, 881743, 881743,
881743, 881743, 881743, 881743, 881743, 881743, 881743, 934175, 934175, 934175, 934175, 934175, 934175, 934175, 934175, 934175, 934175, 934175, 934175, 934175, 934175, 989723, 989723, 989723, 989723, 989723, 989723, 989723, 989723, 989723, 989723, 989723,
989723, 989723, 989723, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1048576, 1110927, 1110927, 1110927, 1110927, 1110927, 1110927, 1110927, 1110927, 1110927, 1110927, 1110927, 1110927, 1110927, 1110927,
1176986, 1176986, 1176986, 1176986, 1176986, 1176986, 1176986, 1176986, 1176986, 1176986, 1176986, 1176986, 1176986, 1176986, 1246974, 1246974, 1246974, 1246974, 1246974, 1246974, 1246974, 1246974, 1246974, 1246974, 1246974, 1246974, 1246974, 1246974, 1321123, 1321123, 1321123, 1321123,
1321123, 1321123, 1321123, 1321123, 1321123, 1321123, 1321123, 1321123, 1321123, 1321123, 1399681, 1399681, 1399681, 1399681, 1399681, 1399681, 1399681, 1399681, 1399681, 1399681, 1399681, 1399681, 1399681, 1399681, 1399681, 1482910, 1482910, 1482910, 1482910, 1482910, 1482910, 1482910,
1482910, 1482910, 1482910, 1482910, 1482910, 1482910, 1482910, 1571088, 1571088, 1571088, 1571088, 1571088, 1571088, 1571088, 1571088, 1571088, 1571088, 1571088, 1571088, 1571088, 1571088, 1664510, 1664510, 1664510, 1664510, 1664510, 1664510, 1664510, 1664510, 1664510, 1664510, 1664510,
1664510, 1664510, 1664510, 1763487, 1763487, 1763487, 1763487, 1763487, 1763487, 1763487, 1763487, 1763487, 1763487, 1763487, 1763487, 1763487, 1763487, 1868350, 1868350, 1868350, 1868350, 1868350, 1868350, 1868350, 1868350, 1868350, 1868350, 1868350, 1868350, 1868350, 1868350, 1868350,
1979447, 1979447, 1979447, 1979447, 1979447, 1979447, 1979447, 1979447, 1979447, 1979447, 1979447, 1979447, 1979447, 1979447, 2097152, 2097152, 2097152, 2097152, 2097152, 2097152, 2097152, 2097152, 2097152, 2097152, 2097152, 2097152, 2097152, 2097152, 2221855, 2221855, 2221855, 2221855,
2221855, 2221855, 2221855, 2221855, 2221855, 2221855, 2221855, 2221855, 2221855, 2221855, 2353973, 2353973, 2353973, 2353973, 2353973, 2353973, 2353973, 2353973, 2353973, 2353973, 2353973, 2353973, 2353973, 2353973, 2353973, 2493948, 2493948, 2493948, 2493948, 2493948, 2493948, 2493948,
2493948, 2493948, 2493948, 2493948, 2493948, 2493948, 2493948, 2642245, 2642245, 2642245, 2642245, 2642245, 2642245, 2642245, 2642245, 2642245, 2642245, 2642245, 2642245, 2642245, 2642245, 2799362, 2799362, 2799362, 2799362, 2799362, 2799362, 2799362, 2799362, 2799362, 2799362, 2799362,
2799362, 2799362, 2799362, 2965820, 2965820, 2965820, 2965820, 2965820, 2965820, 2965820, 2965820, 2965820, 2965820, 2965820, 2965820, 2965820, 2965820, 3142177, 3142177, 3142177, 3142177, 3142177, 3142177, 3142177, 3142177, 3142177, 3142177, 3142177, 3142177, 3142177, 3142177, 3142177,
3329021, 3329021, 3329021, 3329021, 3329021, 3329021, 3329021, 3329021, 3329021, 3329021, 3329021, 3329021, 3329021, 3329021, 3526975, 3526975, 3526975, 3526975, 3526975, 3526975, 3526975, 3526975, 3526975, 3526975, 3526975, 3526975, 3526975, 3526975, 3736699, 3736699, 3736699, 3736699,
3736699, 3736699, 3736699, 3736699, 3736699, 3736699, 3736699, 3736699, 3736699, 3736699, 3958896, 3958896, 3958896, 3958896, 3958896, 3958896, 3958896, 3958896, 3958896, 3958896, 3958896, 3958896, 3958896, 3958896, 4194304, 4194304, 4194304, 4194304, 4194304, 4194304, 4194304, 4194304
};
//802 values - 55Hz (at 44.1kHz sample rate)
int SINLOOKUPSIZE=802;
short SINLOOKUP[]={
2047, 2063, 2079, 2095, 2111, 2127, 2143, 2159, 2175, 2191, 2207, 2223, 2239, 2255, 2271, 2287, 2303, 2319, 2335, 2351, 2367, 2382, 2398, 2414, 2430, 2445, 2461, 2477, 2493, 2508, 2524, 2539,
2555, 2570, 2586, 2601, 2617, 2632, 2648, 2663, 2678, 2693, 2709, 2724, 2739, 2754, 2769, 2784, 2799, 2814, 2829, 2843, 2858, 2873, 2888, 2902, 2917, 2931, 2946, 2960, 2974, 2989, 3003, 3017,
3031, 3045, 3059, 3073, 3087, 3101, 3114, 3128, 3142, 3155, 3169, 3182, 3195, 3209, 3222, 3235, 3248, 3261, 3274, 3287, 3299, 3312, 3324, 3337, 3349, 3362, 3374, 3386, 3398, 3410, 3422, 3434,
3446, 3457, 3469, 3481, 3492, 3503, 3515, 3526, 3537, 3548, 3559, 3569, 3580, 3591, 3601, 3611, 3622, 3632, 3642, 3652, 3662, 3672, 3682, 3691, 3701, 3710, 3719, 3729, 3738, 3747, 3756, 3764,
3773, 3782, 3790, 3798, 3807, 3815, 3823, 3831, 3839, 3846, 3854, 3861, 3869, 3876, 3883, 3890, 3897, 3904, 3911, 3917, 3924, 3930, 3936, 3942, 3948, 3954, 3960, 3966, 3971, 3977, 3982, 3987,
3992, 3997, 4002, 4007, 4011, 4016, 4020, 4024, 4028, 4032, 4036, 4040, 4044, 4047, 4051, 4054, 4057, 4060, 4063, 4066, 4068, 4071, 4073, 4075, 4077, 4079, 4081, 4083, 4085, 4086, 4088, 4089,
4090, 4091, 4092, 4093, 4093, 4094, 4094, 4094, 4094, 4094, 4094, 4094, 4094, 4093, 4093, 4092, 4091, 4090, 4089, 4088, 4086, 4085, 4083, 4081, 4079, 4077, 4075, 4073, 4071, 4068, 4066, 4063,
4060, 4057, 4054, 4051, 4047, 4044, 4040, 4036, 4032, 4028, 4024, 4020, 4016, 4011, 4007, 4002, 3997, 3992, 3987, 3982, 3977, 3971, 3966, 3960, 3954, 3948, 3942, 3936, 3930, 3924, 3917, 3911,
3904, 3897, 3890, 3883, 3876, 3869, 3861, 3854, 3846, 3839, 3831, 3823, 3815, 3807, 3798, 3790, 3782, 3773, 3764, 3756, 3747, 3738, 3729, 3719, 3710, 3701, 3691, 3682, 3672, 3662, 3652, 3642,
3632, 3622, 3611, 3601, 3591, 3580, 3569, 3559, 3548, 3537, 3526, 3515, 3503, 3492, 3481, 3469, 3457, 3446, 3434, 3422, 3410, 3398, 3386, 3374, 3362, 3349, 3337, 3324, 3312, 3299, 3287, 3274,
3261, 3248, 3235, 3222, 3209, 3195, 3182, 3169, 3155, 3142, 3128, 3114, 3101, 3087, 3073, 3059, 3045, 3031, 3017, 3003, 2989, 2974, 2960, 2946, 2931, 2917, 2902, 2888, 2873, 2858, 2843, 2829,
2814, 2799, 2784, 2769, 2754, 2739, 2724, 2709, 2693, 2678, 2663, 2648, 2632, 2617, 2601, 2586, 2570, 2555, 2539, 2524, 2508, 2493, 2477, 2461, 2445, 2430, 2414, 2398, 2382, 2367, 2351, 2335,
2319, 2303, 2287, 2271, 2255, 2239, 2223, 2207, 2191, 2175, 2159, 2143, 2127, 2111, 2095, 2079, 2063, 2047, 2031, 2015, 1999, 1983, 1967, 1951, 1935, 1919, 1903, 1887, 1871, 1855, 1839, 1823,
1807, 1791, 1775, 1759, 1743, 1727, 1712, 1696, 1680, 1664, 1649, 1633, 1617, 1601, 1586, 1570, 1555, 1539, 1524, 1508, 1493, 1477, 1462, 1446, 1431, 1416, 1401, 1385, 1370, 1355, 1340, 1325,
1310, 1295, 1280, 1265, 1251, 1236, 1221, 1206, 1192, 1177, 1163, 1148, 1134, 1120, 1105, 1091, 1077, 1063, 1049, 1035, 1021, 1007, 993, 980, 966, 952, 939, 925, 912, 899, 885, 872,
859, 846, 833, 820, 807, 795, 782, 770, 757, 745, 732, 720, 708, 696, 684, 672, 660, 648, 637, 625, 613, 602, 591, 579, 568, 557, 546, 535, 525, 514, 503, 493,
483, 472, 462, 452, 442, 432, 422, 412, 403, 393, 384, 375, 365, 356, 347, 338, 330, 321, 312, 304, 296, 287, 279, 271, 263, 255, 248, 240, 233, 225, 218, 211,
204, 197, 190, 183, 177, 170, 164, 158, 152, 146, 140, 134, 128, 123, 117, 112, 107, 102, 97, 92, 87, 83, 78, 74, 70, 66, 62, 58, 54, 50, 47, 43,
40, 37, 34, 31, 28, 26, 23, 21, 19, 17, 15, 13, 11, 9, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
2, 3, 4, 5, 6, 8, 9, 11, 13, 15, 17, 19, 21, 23, 26, 28, 31, 34, 37, 40, 43, 47, 50, 54, 58, 62, 66, 70, 74, 78, 83, 87,
92, 97, 102, 107, 112, 117, 123, 128, 134, 140, 146, 152, 158, 164, 170, 177, 183, 190, 197, 204, 211, 218, 225, 233, 240, 248, 255, 263, 271, 279, 287, 296,
304, 312, 321, 330, 338, 347, 356, 365, 375, 384, 393, 403, 412, 422, 432, 442, 452, 462, 472, 483, 493, 503, 514, 525, 535, 546, 557, 568, 579, 591, 602, 613,
625, 637, 648, 660, 672, 684, 696, 708, 720, 732, 745, 757, 770, 782, 795, 807, 820, 833, 846, 859, 872, 885, 899, 912, 925, 939, 952, 966, 980, 993, 1007, 1021,
1035, 1049, 1063, 1077, 1091, 1105, 1120, 1134, 1148, 1163, 1177, 1192, 1206, 1221, 1236, 1251, 1265, 1280, 1295, 1310, 1325, 1340, 1355, 1370, 1385, 1401, 1416, 1431, 1446, 1462, 1477, 1493,
1508, 1524, 1539, 1555, 1570, 1586, 1601, 1617, 1633, 1649, 1664, 1680, 1696, 1712, 1727, 1743, 1759, 1775, 1791, 1807, 1823, 1839, 1855, 1871, 1887, 1903, 1919, 1935, 1951, 1967, 1983, 1999,
2015, 2031
};
short SAWLOOKUP[]={
2049, 2043, 2038, 2033, 2028, 2023, 2018, 2013, 2008, 2003, 1997, 1992, 1987, 1982, 1977, 1972, 1967, 1962, 1957, 1951, 1946, 1941, 1936, 1931, 1926, 1921, 1916, 1911, 1905, 1900, 1895, 1890,
1885, 1880, 1875, 1870, 1865, 1860, 1854, 1849, 1844, 1839, 1834, 1829, 1824, 1819, 1814, 1808, 1803, 1798, 1793, 1788, 1783, 1778, 1773, 1768, 1762, 1757, 1752, 1747, 1742, 1737, 1732, 1727,
1722, 1717, 1711, 1706, 1701, 1696, 1691, 1686, 1681, 1676, 1671, 1665, 1660, 1655, 1650, 1645, 1640, 1635, 1630, 1625, 1619, 1614, 1609, 1604, 1599, 1594, 1589, 1584, 1579, 1574, 1568, 1563,
1558, 1553, 1548, 1543, 1538, 1533, 1528, 1522, 1517, 1512, 1507, 1502, 1497, 1492, 1487, 1482, 1476, 1471, 1466, 1461, 1456, 1451, 1446, 1441, 1436, 1431, 1425, 1420, 1415, 1410, 1405, 1400,
1395, 1390, 1385, 1379, 1374, 1369, 1364, 1359, 1354, 1349, 1344, 1339, 1333, 1328, 1323, 1318, 1313, 1308, 1303, 1298, 1293, 1288, 1282, 1277, 1272, 1267, 1262, 1257, 1252, 1247, 1242, 1236,
1231, 1226, 1221, 1216, 1211, 1206, 1201, 1196, 1190, 1185, 1180, 1175, 1170, 1165, 1160, 1155, 1150, 1145, 1139, 1134, 1129, 1124, 1119, 1114, 1109, 1104, 1099, 1093, 1088, 1083, 1078, 1073,
1068, 1063, 1058, 1053, 1047, 1042, 1037, 1032, 1027, 1022, 1017, 1012, 1007, 1002, 996, 991, 986, 981, 976, 971, 966, 961, 956, 950, 945, 940, 935, 930, 925, 920, 915, 910,
904, 899, 894, 889, 884, 879, 874, 869, 864, 859, 853, 848, 843, 838, 833, 828, 823, 818, 813, 807, 802, 797, 792, 787, 782, 777, 772, 767, 761, 756, 751, 746,
741, 736, 731, 726, 721, 716, 710, 705, 700, 695, 690, 685, 680, 675, 670, 664, 659, 654, 649, 644, 639, 634, 629, 624, 618, 613, 608, 603, 598, 593, 588, 583,
578, 573, 567, 562, 557, 552, 547, 542, 537, 532, 527, 521, 516, 511, 506, 501, 496, 491, 486, 481, 475, 470, 465, 460, 455, 450, 445, 440, 435, 430, 424, 419,
414, 409, 404, 399, 394, 389, 384, 378, 373, 368, 363, 358, 353, 348, 343, 338, 332, 327, 322, 317, 312, 307, 302, 297, 292, 287, 281, 276, 271, 266, 261, 256,
251, 246, 241, 235, 230, 225, 220, 215, 210, 205, 200, 195, 189, 184, 179, 174, 169, 164, 159, 154, 149, 144, 138, 133, 128, 123, 118, 113, 108, 103, 98, 92,
87, 82, 77, 72, 67, 62, 57, 52, 46, 41, 36, 31, 26, 21, 16, 11, 6, 1, 4090, 4085, 4080, 4075, 4070, 4065, 4060, 4055, 4050, 4044, 4039, 4034, 4029, 4024,
4019, 4014, 4009, 4004, 3998, 3993, 3988, 3983, 3978, 3973, 3968, 3963, 3958, 3952, 3947, 3942, 3937, 3932, 3927, 3922, 3917, 3912, 3907, 3901, 3896, 3891, 3886, 3881, 3876, 3871, 3866, 3861,
3855, 3850, 3845, 3840, 3835, 3830, 3825, 3820, 3815, 3809, 3804, 3799, 3794, 3789, 3784, 3779, 3774, 3769, 3764, 3758, 3753, 3748, 3743, 3738, 3733, 3728, 3723, 3718, 3712, 3707, 3702, 3697,
3692, 3687, 3682, 3677, 3672, 3666, 3661, 3656, 3651, 3646, 3641, 3636, 3631, 3626, 3621, 3615, 3610, 3605, 3600, 3595, 3590, 3585, 3580, 3575, 3569, 3564, 3559, 3554, 3549, 3544, 3539, 3534,
3529, 3523, 3518, 3513, 3508, 3503, 3498, 3493, 3488, 3483, 3478, 3472, 3467, 3462, 3457, 3452, 3447, 3442, 3437, 3432, 3426, 3421, 3416, 3411, 3406, 3401, 3396, 3391, 3386, 3380, 3375, 3370,
3365, 3360, 3355, 3350, 3345, 3340, 3335, 3329, 3324, 3319, 3314, 3309, 3304, 3299, 3294, 3289, 3283, 3278, 3273, 3268, 3263, 3258, 3253, 3248, 3243, 3237, 3232, 3227, 3222, 3217, 3212, 3207,
3202, 3197, 3192, 3186, 3181, 3176, 3171, 3166, 3161, 3156, 3151, 3146, 3140, 3135, 3130, 3125, 3120, 3115, 3110, 3105, 3100, 3094, 3089, 3084, 3079, 3074, 3069, 3064, 3059, 3054, 3049, 3043,
3038, 3033, 3028, 3023, 3018, 3013, 3008, 3003, 2997, 2992, 2987, 2982, 2977, 2972, 2967, 2962, 2957, 2951, 2946, 2941, 2936, 2931, 2926, 2921, 2916, 2911, 2906, 2900, 2895, 2890, 2885, 2880,
2875, 2870, 2865, 2860, 2854, 2849, 2844, 2839, 2834, 2829, 2824, 2819, 2814, 2808, 2803, 2798, 2793, 2788, 2783, 2778, 2773, 2768, 2763, 2757, 2752, 2747, 2742, 2737, 2732, 2727, 2722, 2717,
2711, 2706, 2701, 2696, 2691, 2686, 2681, 2676, 2671, 2665, 2660, 2655, 2650, 2645, 2640, 2635, 2630, 2625, 2620, 2614, 2609, 2604, 2599, 2594, 2589, 2584, 2579, 2574, 2568, 2563, 2558, 2553,
2548, 2543, 2538, 2533, 2528, 2522, 2517, 2512, 2507, 2502, 2497, 2492, 2487, 2482, 2477, 2471, 2466, 2461, 2456, 2451, 2446, 2441, 2436, 2431, 2425, 2420, 2415, 2410, 2405, 2400, 2395, 2390,
2385, 2379, 2374, 2369, 2364, 2359, 2354, 2349, 2344, 2339, 2334, 2328, 2323, 2318, 2313, 2308, 2303, 2298, 2293, 2288, 2282, 2277, 2272, 2267, 2262, 2257, 2252, 2247, 2242, 2236, 2231, 2226,
2221, 2216, 2211, 2206, 2201, 2196, 2191, 2185, 2180, 2175, 2170, 2165, 2160, 2155, 2150, 2145, 2139, 2134, 2129, 2124, 2119, 2114, 2109, 2104, 2099, 2093, 2088, 2083, 2078, 2073, 2068, 2063,
2058, 2053
};
#define SAMPLE_RATE 44100.0
#define TICKS_PER_CYCLE (4294967296.0/SAMPLE_RATE)
#define BIAS 2048
#define LEDPIN 53
int POT0=0,POT1=0,POT2=0,POT3=0;
int64_t iter=0;
int64_t modIter=0;
int out_DAC0;
const byte BUTTONS[]={8,9,10,11,12,13}; //main trigger, scale trigger; mod sine on, mod saw on (else square); main sine on, main saw on (else square)
byte BUTTONSTATES[]={0,0,0,0,0,0};
#define FADEMAX 512 //512 samples attack and release (sustain always 1)
unsigned int FADE=0; //used in ASR
#define MAXDELAYBUFFERSIZE 40000 //nearly 1 second of delay
short DELAYBUFFER[MAXDELAYBUFFERSIZE];
unsigned int delayWriteIndex=0;
unsigned int pDelayWriteIndex=0;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
void setup()
{
//Serial.begin(115200);
/* turn on the timer clock in the power management controller */
pmc_set_writeprotect(false);
pmc_enable_periph_clk(ID_TC4);
/* we want wavesel 01 with RC */
TC_Configure(/* clock */TC1,/* channel */1, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK2);
TC_SetRC(TC1, 1, 238); // sets <> 44.1 Khz interrupt rate
TC_Start(TC1, 1);
TC1->TC_CHANNEL[1].TC_IER=TC_IER_CPCS;
TC1->TC_CHANNEL[1].TC_IDR=~TC_IER_CPCS;
NVIC_EnableIRQ(TC4_IRQn);
analogWrite(DAC0,0);
pinMode(LEDPIN,OUTPUT);
for(int i=0;i<6;i++){
pinMode(BUTTONS[i],INPUT_PULLUP); //begin button pins
}
for(int i=0;i<MAXDELAYBUFFERSIZE;i++){
DELAYBUFFER[i]=BIAS; //initialise delay buffer to 'zero'
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
void loop()
{
POT0 = analogRead(A0); //frequency
POT1 = analogRead(A1); //mod frequency
POT2 = analogRead(A2); //delay
POT3 = analogRead(A3); //feedback
// Serial.print(POT0); Serial.print("\t");
// Serial.print(POT1); Serial.print("\t");
// Serial.print(POT2); Serial.print("\t");
// Serial.print(POT3); Serial.print("\t");
// Serial.print(BUTTONSTATES[0]); Serial.println("\t");
if((delayWriteIndex<(20500<<16))||(POT2==0)){
digitalWrite(LEDPIN,HIGH);
}else{
digitalWrite(LEDPIN,LOW);
}
//get button states
buttonUpdate();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
void TC4_Handler()
{
// We need to get the status to clear it and allow the interrupt to fire again
TC_GetStatus(TC1, 1);
//reset mod index upon 'scale' push
if(BUTTONSTATES[1]==3){
modIter=0;
}
if((BUTTONSTATES[0]==2)||(BUTTONSTATES[1]==2)||(FADE>0)){
//MOD OSC--------------------------------------------------------------------------------
int modval=0;
modIter+=(NOTELOOKUP[POT1]-65536)>>4; //mod rate: tweak as necessary
modIter%=SINLOOKUPSIZE<<16;
if(BUTTONSTATES[2]==2){ //MOD SINE
modval=getBufInterp(SINLOOKUP,SINLOOKUPSIZE,modIter); //interpolation may not be necessary?
}else if(BUTTONSTATES[3]==2){ //MOD SAW
modval=getBufInterp(SAWLOOKUP,SINLOOKUPSIZE,modIter);
}else{ //MOD SQUARE
modval=getBufInterp(SINLOOKUP,SINLOOKUPSIZE,modIter);
if(modval>2047){
modval=4095;
}else if(modval<2047){
modval=0;
}else{
modval=2047;
}
}
modval=(modval<<5)-65536; //mod amount
//MAIN OSC--------------------------------------------------------------------------------
if(BUTTONSTATES[1]==2){ //scale function
iter+=NOTELOOKUPSCALE[POT0];
}else{
iter+=NOTELOOKUP[POT0];
}
iter+=modval;
iter%=SINLOOKUPSIZE<<16;
if(BUTTONSTATES[4]==2){
out_DAC0=getBufInterp(SINLOOKUP,SINLOOKUPSIZE,iter);
}else if(BUTTONSTATES[5]==2){
out_DAC0=getBufInterp(SAWLOOKUP,SINLOOKUPSIZE,iter);
}else{
out_DAC0=getBufInterp(SINLOOKUP,SINLOOKUPSIZE,iter);
if(out_DAC0>2047){
out_DAC0=4095;
}else{
out_DAC0=0;
}
}
//ASR--------------------------------------------------------------------------------------
if((FADE<FADEMAX)&&((BUTTONSTATES[0]==2)||(BUTTONSTATES[1]==2))){ //remove &&((BUTTONSTATES[0]==2)||(BUTTONSTATES[1]==2)) for weird noises
FADE++;
}else{
FADE--;
}
out_DAC0=volumeMult4096(out_DAC0,FADE<<7); //output volume set at 100% (FADE<<6 instead of FADE<<7 would be 50%)
}else{
out_DAC0=BIAS;
}
//delay,feedback,filtering-----------
pDelayWriteIndex=delayWriteIndex; //store the previous index (for filling in the gaps later)
delayWriteIndex+=POT2<<9; //increase the index by the specified amount, to the 'oldest' sample
//crappy filtering - take a equal mix of current and last sample (2 tap rectangular moving average filter - good for high frequency clicks but not very noticeable otherwise)
int oldsample=volumeMix4096(getBufInterp(DELAYBUFFER,MAXDELAYBUFFERSIZE,delayWriteIndex),getBufInterp(DELAYBUFFER,MAXDELAYBUFFERSIZE,pDelayWriteIndex),32768); //read oldest sample
oldsample=volumeMult4096(oldsample,((POT3*3)>>1)<<6); //multiply feedback amount (to 150%)
out_DAC0=volumeAdd4096(oldsample,out_DAC0); //add the oldest sample to the output
for(unsigned int i=(pDelayWriteIndex>>16);i<(delayWriteIndex>>16);i++){
int index=i%MAXDELAYBUFFERSIZE;
DELAYBUFFER[index]=out_DAC0; //write all samples the same! this loop could get messy in short delay times (bigger jumps, longer runs to fill);
}
delayWriteIndex%=MAXDELAYBUFFERSIZE<<16; //limit the index so it's always within the array
dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
int getBufInterp(short int* ARRAYINPUT, int BUFFSIZE, unsigned int INDEX){
//INDEX should be float bufferPosition * 2^16
//linear interpolation - allows you to ask for an array entry between indexes e.g. getValInterp(listOfValues, 1024, 34.7*(2^16)); will return a proportional mix of the values at indexes 34 and 35
//will loop back at the end of the array, e.g. it's possible to request indexes longer than the input
int LOWER = INDEX>>16;
if((INDEX%65536)==0){
return (ARRAYINPUT[LOWER%BUFFSIZE]);
}else{
return linInterp(ARRAYINPUT[LOWER%BUFFSIZE], ARRAYINPUT[(LOWER+1)%BUFFSIZE], INDEX%65536);
}
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
int linInterp(int IN1, int IN2, int WEIGHT){
return (IN1*(65536-WEIGHT) + IN2*WEIGHT)>>16;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
int volumeMult4096(int INPUTSAMPLE,int VOLFACTOR){
//simple linear volume change (clips over 1)
//INPUTSAMPLE is between 0 and 4095
//VOLFACTOR is equal to 2^16F, e.g. a doubling of volume would be 2^16*2 = 131072, assumes bias of 2048
return constrain((((INPUTSAMPLE-BIAS)*VOLFACTOR)>>16)+BIAS,0,4095);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
int volumeMix4096(int INPUTSAMPLE1,int INPUTSAMPLE2,int MIX){
//simple volume mixer for two samples, contrains to 4095, variable mix of two samples, MIX should be expressed x*(2^16) where x is between 0 and 1.
return constrain((INPUTSAMPLE1*(65536-MIX)+INPUTSAMPLE2*MIX)>>16,0,4095);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
int volumeAdd4096(int INPUTSAMPLE1,int INPUTSAMPLE2){ //beware unsigned
//simple volume adder for two samples, contrains to 4095, assumes bias of 2048
return constrain(INPUTSAMPLE1+INPUTSAMPLE2-BIAS,0,4095);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
void buttonUpdate(){
for(int i=0;i<6;i++){
boolean buttonState=digitalRead(BUTTONS[i]);
if(BUTTONSTATES[i]==3){
BUTTONSTATES[i]=2;
}
if((buttonState==LOW)&&(BUTTONSTATES[i]==0)){
BUTTONSTATES[i]=3;
}
if(BUTTONSTATES[i]==1){
BUTTONSTATES[i]=0;
}
if((buttonState==HIGH)&&(BUTTONSTATES[i]==2)){
BUTTONSTATES[i]=1;
}
}
}