From 6b5d815f74ac5ad4dfdead51a1ee33a86c48014f Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Sun, 15 Mar 2020 13:33:19 +0100 Subject: [PATCH] Replace weird nonworking wavefolder with sustain/silence length adjustment --- pure_adsr/resources.cc | 232 ++++----------------------- pure_adsr/resources.h | 6 - pure_adsr/resources/lookup_tables.py | 15 +- pure_adsr/tides.cc | 9 -- pure_adsr/tides.h | 51 +++++- 5 files changed, 77 insertions(+), 236 deletions(-) diff --git a/pure_adsr/resources.cc b/pure_adsr/resources.cc index 8cda0b7..f2224e9 100644 --- a/pure_adsr/resources.cc +++ b/pure_adsr/resources.cc @@ -136,180 +136,12 @@ const prog_uint16_t lut_res_env_quartic[] PROGMEM = { 59750, 60553, 61364, 62183, 63010, 63843, 64685, 65535, 65535, }; -const prog_uint16_t lut_res_raised_cosine[] PROGMEM = { - 0, 2, 9, 22, 39, 61, 88, 120, - 157, 199, 246, 298, 354, 416, 482, 553, - 629, 710, 796, 886, 982, 1082, 1186, 1296, - 1410, 1530, 1653, 1782, 1915, 2053, 2195, 2342, - 2494, 2650, 2811, 2976, 3146, 3320, 3498, 3681, - 3869, 4060, 4256, 4457, 4661, 4870, 5083, 5300, - 5522, 5747, 5977, 6210, 6448, 6689, 6935, 7184, - 7437, 7694, 7955, 8220, 8488, 8760, 9035, 9314, - 9597, 9883, 10172, 10465, 10762, 11061, 11364, 11670, - 11980, 12292, 12607, 12926, 13247, 13572, 13899, 14229, - 14562, 14898, 15236, 15578, 15921, 16267, 16616, 16967, - 17321, 17676, 18034, 18395, 18757, 19122, 19488, 19857, - 20227, 20600, 20974, 21350, 21728, 22107, 22488, 22871, - 23255, 23641, 24027, 24416, 24805, 25196, 25588, 25980, - 26374, 26769, 27165, 27562, 27959, 28357, 28756, 29155, - 29555, 29956, 30356, 30758, 31159, 31561, 31963, 32365, - 32767, 33169, 33571, 33973, 34375, 34776, 35178, 35578, - 35979, 36379, 36778, 37177, 37575, 37972, 38369, 38765, - 39160, 39554, 39946, 40338, 40729, 41118, 41507, 41893, - 42279, 42663, 43046, 43427, 43806, 44184, 44560, 44934, - 45307, 45677, 46046, 46412, 46777, 47139, 47500, 47858, - 48213, 48567, 48918, 49267, 49613, 49956, 50298, 50636, - 50972, 51305, 51635, 51962, 52287, 52608, 52927, 53242, - 53554, 53864, 54170, 54473, 54772, 55069, 55362, 55651, - 55937, 56220, 56499, 56774, 57046, 57314, 57579, 57840, - 58097, 58350, 58599, 58845, 59086, 59324, 59557, 59787, - 60012, 60234, 60451, 60664, 60873, 61077, 61278, 61474, - 61665, 61853, 62036, 62214, 62388, 62558, 62723, 62884, - 63040, 63192, 63339, 63481, 63619, 63752, 63881, 64004, - 64124, 64238, 64348, 64452, 64552, 64648, 64738, 64824, - 64905, 64981, 65052, 65118, 65180, 65236, 65288, 65335, - 65377, 65414, 65446, 65473, 65495, 65512, 65525, 65532, - 65532, -}; -const prog_uint16_t lut_res_unipolar_fold[] PROGMEM = { - 0, 352, 703, 1054, 1404, 1754, 2102, 2450, - 2796, 3141, 3483, 3824, 4163, 4500, 4834, 5165, - 5494, 5819, 6141, 6460, 6776, 7088, 7395, 7699, - 7999, 8294, 8585, 8871, 9152, 9429, 9700, 9966, - 10227, 10482, 10731, 10975, 11213, 11445, 11671, 11891, - 12104, 12311, 12512, 12706, 12893, 13073, 13247, 13414, - 13574, 13727, 13873, 14012, 14144, 14268, 14386, 14496, - 14598, 14694, 14782, 14863, 14937, 15003, 15062, 15113, - 15158, 15195, 15225, 15247, 15263, 15271, 15272, 15266, - 15253, 15234, 15207, 15174, 15133, 15087, 15033, 14973, - 14907, 14834, 14756, 14671, 14580, 14483, 14381, 14273, - 14159, 14040, 13915, 13786, 13651, 13512, 13368, 13219, - 13066, 12909, 12747, 12582, 12412, 12239, 12063, 11883, - 11700, 11513, 11324, 11133, 10939, 10742, 10544, 10343, - 10141, 9936, 9731, 9524, 9316, 9107, 8898, 8688, - 8477, 8266, 8055, 7845, 7634, 7424, 7215, 7007, - 6799, 6593, 6388, 6184, 5983, 5783, 5585, 5389, - 5196, 5005, 4816, 4631, 4448, 4269, 4092, 3919, - 3750, 3584, 3422, 3264, 3110, 2960, 2814, 2673, - 2536, 2403, 2276, 2153, 2035, 1922, 1815, 1712, - 1615, 1523, 1436, 1355, 1280, 1210, 1146, 1087, - 1035, 988, 947, 912, 883, 860, 843, 832, - 827, 828, 835, 848, 867, 893, 924, 962, - 1005, 1055, 1110, 1172, 1239, 1312, 1391, 1476, - 1567, 1663, 1766, 1873, 1987, 2105, 2229, 2359, - 2494, 2634, 2779, 2929, 3084, 3244, 3408, 3578, - 3751, 3930, 4112, 4299, 4490, 4686, 4885, 5087, - 5294, 5504, 5718, 5935, 6155, 6378, 6604, 6834, - 7065, 7300, 7537, 7776, 8017, 8261, 8506, 8753, - 9002, 9253, 9504, 9757, 10012, 10267, 10523, 10780, - 11037, 11295, 11553, 11812, 12070, 12329, 12587, 12845, - 13103, 13360, 13616, 13871, 14126, 14380, 14632, 14883, - 15133, 15381, 15627, 15872, 16115, 16356, 16595, 16832, - 17067, 17299, 17529, 17756, 17980, 18202, 18422, 18638, - 18851, 19061, 19268, 19472, 19673, 19871, 20065, 20255, - 20442, 20626, 20806, 20982, 21154, 21323, 21488, 21649, - 21807, 21960, 22110, 22255, 22397, 22534, 22668, 22797, - 22923, 23044, 23162, 23275, 23384, 23489, 23590, 23687, - 23780, 23869, 23954, 24035, 24112, 24185, 24254, 24320, - 24381, 24438, 24492, 24542, 24588, 24631, 24669, 24705, - 24736, 24764, 24789, 24810, 24828, 24843, 24854, 24862, - 24867, 24869, 24868, 24865, 24858, 24848, 24836, 24821, - 24803, 24783, 24761, 24736, 24709, 24680, 24648, 24614, - 24579, 24541, 24502, 24461, 24418, 24374, 24328, 24281, - 24232, 24183, 24131, 24079, 24026, 23972, 23917, 23861, - 23804, 23747, 23689, 23631, 23572, 23513, 23454, 23394, - 23335, 23275, 23216, 23156, 23097, 23038, 22979, 22920, - 22862, 22805, 22748, 22692, 22636, 22581, 22527, 22474, - 22422, 22370, 22320, 22271, 22223, 22176, 22130, 22086, - 22043, 22001, 21961, 21922, 21884, 21849, 21814, 21782, - 21750, 21721, 21693, 21667, 21642, 21620, 21599, 21580, - 21562, 21547, 21533, 21521, 21511, 21503, 21497, 21493, - 21490, 21490, 21491, 21495, 21500, 21507, 21516, 21527, - 21539, 21554, 21571, 21589, 21609, 21631, 21655, 21681, - 21708, 21738, 21769, 21801, 21836, 21872, 21910, 21949, - 21990, 22033, 22077, 22123, 22171, 22219, 22270, 22321, - 22375, 22429, 22485, 22542, 22600, 22660, 22721, 22782, - 22845, 22910, 22975, 23041, 23108, 23176, 23245, 23315, - 23386, 23457, 23529, 23602, 23676, 23750, 23824, 23900, - 23975, 24052, 24128, 24205, 24283, 24361, 24438, 24517, - 24595, 24674, 24752, 24831, 24910, 24989, 25068, 25146, - 25225, 25304, 25382, 25460, 25538, 25616, 25693, 25770, - 25847, 25923, 25999, 26075, 26150, 26224, 26298, 26372, - 26445, 26517, 26589, 26660, 26730, 26800, 26869, 26937, - 27004, 27071, 27137, 27202, 27266, 27330, 27392, 27454, - 27515, 27575, 27634, 27692, 27749, 27805, 27861, 27915, - 27968, 28021, 28072, 28123, 28172, 28221, 28268, 28315, - 28360, 28404, 28448, 28490, 28532, 28572, 28612, 28650, - 28688, 28725, 28760, 28795, 28828, 28861, 28893, 28923, - 28953, 28982, 29010, 29037, 29063, 29089, 29113, 29136, - 29159, 29181, 29202, 29222, 29241, 29260, 29277, 29294, - 29310, 29326, 29341, 29355, 29368, 29380, 29392, 29404, - 29414, 29424, 29434, 29443, 29451, 29459, 29466, 29472, - 29478, 29484, 29489, 29494, 29498, 29502, 29505, 29508, - 29511, 29513, 29515, 29517, 29518, 29519, 29520, 29521, - 29521, 29521, 29520, 29520, 29519, 29519, 29518, 29517, - 29515, 29514, 29513, 29511, 29510, 29508, 29506, 29505, - 29503, 29501, 29499, 29498, 29496, 29494, 29493, 29491, - 29490, 29488, 29487, 29486, 29484, 29483, 29483, 29482, - 29481, 29481, 29481, 29480, 29480, 29481, 29481, 29482, - 29482, 29483, 29485, 29486, 29488, 29490, 29492, 29494, - 29496, 29499, 29502, 29505, 29509, 29513, 29517, 29521, - 29525, 29530, 29535, 29540, 29546, 29551, 29557, 29564, - 29570, 29577, 29584, 29591, 29598, 29606, 29614, 29622, - 29631, 29639, 29648, 29657, 29667, 29676, 29686, 29696, - 29706, 29717, 29728, 29738, 29749, 29761, 29772, 29784, - 29796, 29808, 29820, 29832, 29845, 29857, 29870, 29883, - 29896, 29910, 29923, 29937, 29950, 29964, 29978, 29992, - 30006, 30021, 30035, 30050, 30064, 30079, 30093, 30108, - 30123, 30138, 30153, 30168, 30183, 30198, 30213, 30229, - 30244, 30259, 30274, 30290, 30305, 30320, 30336, 30351, - 30366, 30382, 30397, 30412, 30428, 30443, 30458, 30473, - 30488, 30504, 30519, 30534, 30549, 30564, 30579, 30593, - 30608, 30623, 30637, 30652, 30667, 30681, 30695, 30710, - 30724, 30738, 30752, 30766, 30780, 30794, 30807, 30821, - 30834, 30848, 30861, 30874, 30887, 30900, 30913, 30926, - 30939, 30951, 30964, 30976, 30988, 31001, 31013, 31025, - 31036, 31048, 31060, 31071, 31083, 31094, 31105, 31117, - 31128, 31138, 31149, 31160, 31171, 31181, 31191, 31202, - 31212, 31222, 31232, 31242, 31252, 31262, 31271, 31281, - 31290, 31299, 31309, 31318, 31327, 31336, 31345, 31354, - 31362, 31371, 31380, 31388, 31397, 31405, 31413, 31422, - 31430, 31438, 31446, 31454, 31462, 31469, 31477, 31485, - 31492, 31500, 31508, 31515, 31522, 31530, 31537, 31544, - 31552, 31559, 31566, 31573, 31580, 31587, 31594, 31601, - 31608, 31615, 31621, 31628, 31635, 31642, 31648, 31655, - 31662, 31668, 31675, 31682, 31688, 31695, 31701, 31708, - 31714, 31721, 31727, 31733, 31740, 31746, 31753, 31759, - 31765, 31772, 31778, 31785, 31791, 31797, 31804, 31810, - 31816, 31823, 31829, 31835, 31842, 31848, 31854, 31861, - 31867, 31873, 31880, 31886, 31892, 31898, 31905, 31911, - 31917, 31924, 31930, 31937, 31943, 31949, 31956, 31962, - 31968, 31975, 31981, 31987, 31994, 32000, 32007, 32013, - 32019, 32026, 32032, 32039, 32045, 32052, 32058, 32065, - 32071, 32077, 32084, 32090, 32097, 32103, 32110, 32116, - 32123, 32129, 32136, 32142, 32149, 32155, 32162, 32168, - 32175, 32181, 32188, 32194, 32201, 32207, 32214, 32220, - 32227, 32233, 32240, 32246, 32253, 32259, 32266, 32272, - 32279, 32285, 32292, 32298, 32305, 32311, 32318, 32324, - 32331, 32337, 32344, 32350, 32357, 32363, 32370, 32376, - 32382, 32389, 32395, 32402, 32408, 32414, 32421, 32427, - 32434, 32440, 32446, 32453, 32459, 32465, 32472, 32478, - 32484, 32490, 32497, 32503, 32509, 32516, 32522, 32528, - 32534, 32540, 32547, 32553, 32559, 32565, 32571, 32577, - 32583, 32590, 32596, 32602, 32608, 32614, 32620, 32626, - 32632, 32638, 32644, 32650, 32656, 32662, 32668, 32674, - 32680, 32686, 32692, 32697, 32703, 32709, 32715, 32721, - 32727, 32732, 32738, 32744, 32750, 32756, 32761, 32767, - 32767, -}; const prog_uint16_t* const lookup_table_table[] = { lut_res_env_linear, lut_res_env_expo, lut_res_env_quartic, - lut_res_raised_cosine, - lut_res_unipolar_fold, }; const prog_uint32_t lut_res_env_increments[] PROGMEM = { @@ -348,38 +180,38 @@ const prog_uint32_t lut_res_env_increments[] PROGMEM = { 219043, }; const prog_uint32_t lut_res_env_increments_slow[] PROGMEM = { - 876173, 855969, 836311, 817181, 798563, 780441, 762801, 745627, - 728906, 712624, 696767, 681324, 666281, 651626, 637349, 623439, - 609883, 596673, 583797, 571247, 559013, 547085, 535455, 524115, - 513056, 502270, 491749, 481487, 471475, 461707, 452176, 442875, - 433798, 424939, 416292, 407850, 399610, 391564, 383708, 376036, - 368544, 361227, 354080, 347098, 340278, 333615, 327104, 320742, - 314525, 308449, 302511, 296706, 291032, 285485, 280062, 274760, - 269575, 264504, 259546, 254696, 249952, 245312, 240773, 236332, - 231987, 227735, 223575, 219504, 215519, 211620, 207803, 204066, - 200409, 196828, 193322, 189889, 186528, 183236, 180012, 176855, - 173763, 170734, 167767, 164860, 162012, 159222, 156488, 153809, - 151184, 148612, 146090, 143619, 141197, 138822, 136495, 134213, - 131976, 129782, 127631, 125522, 123454, 121426, 119437, 117486, - 115572, 113695, 111853, 110047, 108274, 106535, 104829, 103155, - 101512, 99900, 98318, 96765, 95241, 93745, 92277, 90835, - 89420, 88031, 86667, 85328, 84013, 82722, 81454, 80209, - 78986, 77785, 76605, 75446, 74308, 73190, 72092, 71013, - 69953, 68911, 67888, 66883, 65895, 64924, 63969, 63032, - 62110, 61204, 60314, 59439, 58578, 57733, 56901, 56084, - 55280, 54490, 53713, 52949, 52198, 51460, 50733, 50019, - 49316, 48625, 47945, 47277, 46619, 45972, 45336, 44710, - 44094, 43488, 42892, 42305, 41728, 41160, 40601, 40051, - 39510, 38977, 38453, 37937, 37429, 36929, 36437, 35952, - 35475, 35006, 34544, 34089, 33641, 33200, 32765, 32338, - 31916, 31502, 31093, 30691, 30295, 29905, 29521, 29143, - 28770, 28403, 28041, 27685, 27334, 26988, 26648, 26312, - 25981, 25656, 25335, 25019, 24707, 24400, 24097, 23799, - 23505, 23216, 22930, 22649, 22372, 22098, 21829, 21564, - 21302, 21044, 20789, 20539, 20292, 20048, 19808, 19571, - 19337, 19107, 18880, 18656, 18435, 18217, 18003, 17791, - 17582, 17376, 17173, 16972, 16775, 16580, 16388, 16198, - 16011, 15826, 15644, 15465, 15288, 15113, 14940, 14770, + 3504693, 3381406, 3263185, 3149790, 3040997, 2936593, 2836375, 2740152, + 2647742, 2558972, 2473679, 2391707, 2312908, 2237142, 2164276, 2094182, + 2026741, 1961838, 1899363, 1839212, 1781288, 1725495, 1671745, 1619951, + 1570032, 1521911, 1475514, 1430770, 1387612, 1345976, 1305799, 1267025, + 1229596, 1193460, 1158565, 1124863, 1092307, 1060853, 1030457, 1001080, + 972682, 945226, 918676, 892998, 868159, 844128, 820875, 798370, + 776588, 755500, 735082, 715309, 696158, 677607, 659634, 642219, + 625341, 608982, 593124, 577749, 562840, 548381, 534356, 520751, + 507551, 494743, 482312, 470248, 458536, 447165, 436124, 425402, + 414989, 404874, 395047, 385499, 376222, 367205, 358442, 349923, + 341641, 333588, 325758, 318142, 310735, 303530, 296520, 289700, + 283063, 276605, 270318, 264199, 258242, 252442, 246795, 241296, + 235939, 230723, 225641, 220690, 215866, 211166, 206585, 202121, + 197770, 193528, 189393, 185361, 181430, 177597, 173858, 170211, + 166654, 163184, 159798, 156495, 153272, 150126, 147056, 144060, + 141135, 138279, 135491, 132769, 130111, 127516, 124981, 122504, + 120086, 117723, 115415, 113160, 110956, 108803, 106698, 104641, + 102631, 100666, 98745, 96867, 95030, 93235, 91479, 89762, + 88082, 86440, 84833, 83262, 81724, 80220, 78748, 77307, + 75898, 74519, 73169, 71847, 70554, 69288, 68048, 66835, + 65647, 64483, 63344, 62228, 61136, 60065, 59017, 57990, + 56984, 55999, 55034, 54088, 53161, 52252, 51362, 50490, + 49635, 48797, 47975, 47170, 46380, 45606, 44848, 44104, + 43374, 42658, 41957, 41269, 40594, 39932, 39283, 38646, + 38021, 37408, 36806, 36216, 35637, 35069, 34512, 33965, + 33428, 32900, 32383, 31875, 31377, 30888, 30407, 29936, + 29473, 29018, 28572, 28133, 27703, 27280, 26865, 26457, + 26056, 25663, 25276, 24897, 24524, 24157, 23797, 23443, + 23096, 22754, 22419, 22089, 21765, 21446, 21133, 20825, + 20523, 20226, 19933, 19646, 19364, 19086, 18813, 18544, + 18280, 18021, 17765, 17514, 17268, 17025, 16786, 16551, + 16320, 16093, 15869, 15650, 15433, 15220, 15011, 14805, 14602, }; diff --git a/pure_adsr/resources.h b/pure_adsr/resources.h index 23194f5..91b1d62 100644 --- a/pure_adsr/resources.h +++ b/pure_adsr/resources.h @@ -42,8 +42,6 @@ extern const prog_uint32_t* const lookup_table_32_table[]; extern const prog_uint16_t lut_res_env_linear[] PROGMEM; extern const prog_uint16_t lut_res_env_expo[] PROGMEM; extern const prog_uint16_t lut_res_env_quartic[] PROGMEM; -extern const prog_uint16_t lut_res_raised_cosine[] PROGMEM; -extern const prog_uint16_t lut_res_unipolar_fold[] PROGMEM; extern const prog_uint32_t lut_res_env_increments[] PROGMEM; extern const prog_uint32_t lut_res_env_increments_slow[] PROGMEM; #define STR_RES_DUMMY 0 // dummy @@ -53,10 +51,6 @@ extern const prog_uint32_t lut_res_env_increments_slow[] PROGMEM; #define LUT_RES_ENV_EXPO_SIZE 257 #define LUT_RES_ENV_QUARTIC 2 #define LUT_RES_ENV_QUARTIC_SIZE 257 -#define LUT_RES_RAISED_COSINE 3 -#define LUT_RES_RAISED_COSINE_SIZE 257 -#define LUT_RES_UNIPOLAR_FOLD 4 -#define LUT_RES_UNIPOLAR_FOLD_SIZE 1025 #define LUT_RES_ENV_INCREMENTS 0 #define LUT_RES_ENV_INCREMENTS_SIZE 257 #define LUT_RES_ENV_INCREMENTS_SLOW 1 diff --git a/pure_adsr/resources/lookup_tables.py b/pure_adsr/resources/lookup_tables.py index 9bb7bae..b4dbffb 100644 --- a/pure_adsr/resources/lookup_tables.py +++ b/pure_adsr/resources/lookup_tables.py @@ -32,8 +32,7 @@ import numpy SAMPLE_RATE = 20000000.0 / 510 / 16#/ 4 # hz -WAVESHAPER_SIZE = 1024 - +WAVETABLE_SIZE = 1024 """---------------------------------------------------------------------------- LFO and envelope increments. ----------------------------------------------------------------------------""" @@ -65,7 +64,7 @@ lookup_tables_32.append( # Tides envelopes max_time = 60.0 * 2 # seconds -min_time = 2 +min_time = .5 gamma = 0.175 min_increment = excursion / (max_time * sample_rate) max_increment = excursion / (min_time * sample_rate) @@ -90,13 +89,3 @@ lookup_tables.append(('env_expo', env_expo / env_expo.max() * 65535.0)) lookup_tables.append( ('env_quartic', env_quartic / env_quartic.max() * 65535.0)) -raised_cosine = 0.5 - numpy.cos(env_linear * numpy.pi) / 2 -lookup_tables.append(('raised_cosine', raised_cosine * 65535.0)) - -x = numpy.arange(0, WAVESHAPER_SIZE + 1) / float(WAVESHAPER_SIZE) -x[-1] = x[-2] -sine = numpy.sin(8 * numpy.pi * x) -window = numpy.exp(-x * x * 4) ** 2 -unipolar_fold = (0.5 * sine + 2 * x) * window + numpy.arctan(4 * x) * (1 - window) -unipolar_fold /= numpy.abs(unipolar_fold).max() -lookup_tables.append(('unipolar_fold', numpy.round(32767 * unipolar_fold))) diff --git a/pure_adsr/tides.cc b/pure_adsr/tides.cc index 2ab302b..f099f51 100644 --- a/pure_adsr/tides.cc +++ b/pure_adsr/tides.cc @@ -82,15 +82,6 @@ void Tides::Process( value_ = a + ((b - a) * (t >> 1) >> 15); - int32_t wf_balance = smoothness_ >> 1; - int32_t wf_gain = 2048 + \ - (static_cast(smoothness_ >> 1) * (65535 - 2048) >> 15); - int32_t original = value_; - int32_t m = pgm_read_word(lut_res_unipolar_fold + ((original * wf_gain + (1U << 31)) >> 22)); - int32_t n = pgm_read_word(lut_res_unipolar_fold + ((original * wf_gain + (1U << 31)) >> 22) + 1); - int32_t folded = m + ((n - m) * static_cast(((original * wf_gain) >> 6) & 0xffff) >> 16); - value_ = original + ((folded - original) * wf_balance >> 15); - value_ = value_ << 1; phase_ += phase_increment_; *out++ = value_; } diff --git a/pure_adsr/tides.h b/pure_adsr/tides.h index a586173..df0bd66 100644 --- a/pure_adsr/tides.h +++ b/pure_adsr/tides.h @@ -35,6 +35,8 @@ #include #include +#define max(x, y) (((x) > (y)) ? (x) : (y)) + namespace pure_adsr { class Tides { @@ -47,30 +49,38 @@ class Tides { void Configure(uint16_t* parameter, ControlMode control_mode) { - set_ad_loop(parameter[0], parameter[1]); - smoothness_ = parameter[3]; - uint8_t waveform_mode = quant.Process(parameter[2] / 65536.0f, 5); + uint16_t param = parameter[2]; + uint16_t hold_high_length = 0; + uint16_t hold_low_length = 0; + if(param > 32768) { + hold_high_length = (param - 32768) >> 0; + } else { + hold_low_length = (32768 - param) >> 0; + } + + set_ad_f_loop(parameter[0], parameter[1], hold_high_length, hold_low_length); + uint8_t waveform_mode = quant.Process(parameter[3] / 65536.0f, 5); switch (waveform_mode) { case 0: shape_[0] = ENV_SHAPE_QUARTIC; - shape_[1] = ENV_SHAPE_EXPONENTIAL; + shape_[2] = ENV_SHAPE_EXPONENTIAL; break; case 1: shape_[0] = ENV_SHAPE_QUARTIC; - shape_[1] = ENV_SHAPE_QUARTIC; + shape_[2] = ENV_SHAPE_QUARTIC; break; case 2: shape_[0] = ENV_SHAPE_LINEAR; - shape_[1] = ENV_SHAPE_LINEAR; + shape_[2] = ENV_SHAPE_LINEAR; break; case 3: shape_[0] = ENV_SHAPE_EXPONENTIAL; - shape_[1] = ENV_SHAPE_EXPONENTIAL; + shape_[2] = ENV_SHAPE_EXPONENTIAL; break; case 4: shape_[0] = ENV_SHAPE_EXPONENTIAL; - shape_[1] = ENV_SHAPE_QUARTIC; + shape_[2] = ENV_SHAPE_QUARTIC; break; } @@ -262,6 +272,31 @@ class Tides { loop_end_ = 2; } + inline void set_ad_f_loop(uint16_t attack, uint16_t decay, uint16_t sustain, uint16_t silence) + { + num_segments_ = 4; + sustain_point_ = 0; + + level_[0] = 0; + level_[1] = 32767; + level_[2] = 32767; + level_[3] = 0; + level_[4] = 0; + + time_[0] = attack; + time_[1] = sustain; + time_[2] = decay; + time_[3] = silence; + + shape_[0] = ENV_SHAPE_LINEAR; + shape_[1] = ENV_SHAPE_LINEAR; + shape_[2] = ENV_SHAPE_LINEAR; + shape_[3] = ENV_SHAPE_LINEAR; + + loop_start_ = 0; + loop_end_ = 4; + } + inline void set_adr_loop( uint16_t attack, uint16_t decay,