PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Fork of PokittoLib by
Synth_helpers.cpp
00001 /**************************************************************************/ 00002 /*! 00003 @file Synth_envfuncs.cpp 00004 @author Jonne Valola 00005 00006 @section LICENSE 00007 00008 Pokitto development stage library 00009 Software License Agreement 00010 00011 Copyright (c) 2015, Jonne Valola ("Author") 00012 All rights reserved. 00013 00014 This library is intended solely for the purpose of Pokitto development. 00015 00016 Redistribution and use in source and binary forms, with or without 00017 modification requires written permission from Author. 00018 */ 00019 /**************************************************************************/ 00020 00021 #include "Pokitto.h " 00022 #include "Synth.h " 00023 00024 #define PROGMEM 00025 #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 00026 #ifndef WIN32 00027 #ifndef pgm_read_word 00028 #define pgm_read_word(addr) (*(const unsigned short *)(addr)) 00029 #endif 00030 #else 00031 #define pgm_read_word(addr) (*(const unsigned int *)(addr)) 00032 #endif // WIN32 00033 00034 // http://www.arklyffe.com/main/2010/08/29/xorshift-pseudorandom-number-generator/ 00035 static uint8_t y8 = 1; 00036 static uint16_t y16 = 1; 00037 00038 // returns values from 1 to 255 inclusive, period is 255 00039 uint8_t xorshift8(void) { 00040 //y8 ^= (y8 << 7); 00041 y8 ^= (y8 * 128); 00042 y8 ^= (y8 >> 5); 00043 //return y8 ^= (y8 << 3); 00044 return y8 ^= (y8 * 8); 00045 } 00046 00047 // returns values from 1 to 65535 inclusive, period is 65535 00048 uint16_t xorshift16(void) { 00049 //y16 ^= (y16 << 13); 00050 y16 ^= (y16 * 8192); 00051 y16 ^= (y16 >> 9); 00052 //return y16 ^= (y16 << 7); 00053 return y16 ^= (y16 * 128); 00054 } 00055 00056 00057 int8_t arptable[MAX_ARPMODE][5] = { 00058 {0,0,0,0,0}, // Off 00059 {0,4,7,4,0}, // Major tonic, 3rd, 5th 00060 {0,3,7,3,0}, // Minor tonic, 3rd, 5th 00061 {0,1,0,-1,0}, // vibrato test 00062 {0,12,0,12,0}, // octave test 00063 {0,11,14,17,21}, // funky test 00064 }; 00065 00066 /** VITAL TABLES **/ 00067 00068 uint16_t cincs[] ={ 00069 36, // 0 - NOTE_B0 00070 38, // 1 - NOTE_C1 00071 40, // 2 - NOTE_CS1 00072 43, // 3 - NOTE_D1 00073 45, // 4 - NOTE_DS1 00074 47, // 5 - NOTE_E1 00075 51, // 6 - NOTE_F1 00076 53, // 7 - NOTE_FS1 00077 56, // 8 - NOTE_G1 00078 60, // 9 - NOTE_GS1 00079 63, // 10 - NOTE_A1 00080 67, // 11 - NOTE_AS1 00081 71, // 12 - NOTE_B1 00082 75, // 13 - NOTE_C2 00083 79, // 14 - NOTE_CS2 00084 84, // 15 - NOTE_D2 00085 90, // 16 - NOTE_DS2 00086 94, // 17 - NOTE_E2 00087 100, // 18 - NOTE_F2 00088 107, // 19 - NOTE_FS2 00089 113, // 20 - NOTE_G2 00090 120, // 21 - NOTE_GS2 00091 127, // 22 - NOTE_A2 00092 135, // 23 - NOTE_AS2 00093 142, // 24 - NOTE_B2 00094 151, // 25 - NOTE_C3 00095 160, // 26 - NOTE_CS3 00096 169, // 27 - NOTE_D3 00097 180, // 28 - NOTE_DS3 00098 190, // 29 - NOTE_E3 00099 201, // 30 - NOTE_F3 00100 213, // 31 - NOTE_FS3 00101 225, // 32 - NOTE_G3 00102 239, //239, // 33 - NOTE_GS3 00103 253, // 34 - NOTE_A3 00104 267, // 35 - NOTE_AS3 00105 284, // 36 - NOTE_B3 00106 301, // 37 - NOTE_C4 00107 318, // 38 - NOTE_CS4 00108 338, // 39 - NOTE_D4 00109 358, // 40 - NOTE_DS4 00110 379, // 41 - NOTE_E4 00111 402, // 42 - NOTE_F4 00112 426, // 43 - NOTE_FS4 00113 452, // 44 - NOTE_G4 00114 478, // 45 - NOTE_GS4 00115 504, // 46 - NOTE_A4 // 440Hz 00116 537, // 47 - NOTE_AS4 00117 570, // 48 - NOTE_B4 00118 601, // 49 - NOTE_C5 00119 636, // 50 - NOTE_CS5 00120 676, // 51 - NOTE_D5 00121 712, // 52 - NOTE_DS5 00122 762, // 53 - NOTE_E5 00123 799, // 54 - NOTE_F5 00124 851, // 55 - NOTE_FS5 00125 898, // 56 - NOTE_G5 00126 950, // 57 - NOTE_GS5 00127 1008, // 58 - NOTE_A5 00128 1074, // 59 - NOTE_AS5 00129 1130, // 60 - NOTE_B5 00130 1214, // 61 - NOTE_C6 00131 1285, // 62 - NOTE_CS6 00132 1337, // 63 - NOTE_D6 00133 1425, // 64 - NOTE_DS6 00134 1524, // 65 - NOTE_E6 00135 1598, // 66 - NOTE_F6 00136 1680, // 67 - NOTE_FS6 00137 1820, // 68 - NOTE_G6 00138 1928, // 69 - NOTE_GS6 00139 2048, // 70 - NOTE_A6 00140 2114, // 71 - NOTE_AS6 00141 2260, // 72 - NOTE_B6 00142 2427, // 73 - NOTE_C7 00143 2521, // 74 - NOTE_CS7 00144 2731, // 75 - NOTE_D7 00145 2849, // 76 - NOTE_DS7 00146 2979, // 77 - NOTE_E7 00147 3277, // 78 - NOTE_F7 00148 3449, // 79 - NOTE_FS7 00149 3641, // 80 - NOTE_G7 00150 3855, // 81 - NOTE_GS7 00151 4096, // 82 - NOTE_A7 00152 4369, // 83 - NOTE_AS7 00153 4681, // 84 - NOTE_B7 00154 4681, // 85 - NOTE_C8 00155 5041, // 86 - NOTE_CS8 00156 5461, // 87 - NOTE_D8 00157 5958, // 88 - NOTE_DS8 00158 }; 00159 00160 00161 /** NOTE TO TEXT TABLES **/ 00162 00163 const char note_0[] PROGMEM = "B-0"; // 0 - NOTE_B0 00164 const char note_1[] PROGMEM = "C-1"; // 1 - NOTE_C1 00165 const char note_2[] PROGMEM = "C#1"; // 2 - NOTE_CS1 00166 const char note_3[] PROGMEM = "D-1"; // 3 - NOTE_D1 00167 const char note_4[] PROGMEM = "D#1"; // 4 - NOTE_DS1 00168 const char note_5[] PROGMEM = "E-1"; // 5 - NOTE_E1 00169 const char note_6[] PROGMEM = "F-1"; // 6 - NOTE_F1 00170 const char note_7[] PROGMEM = "F#1"; // 7 - NOTE_FS1 00171 const char note_8[] PROGMEM = "G-1"; // 8 - NOTE_G1 00172 const char note_9[] PROGMEM = "G#1"; // 9 - NOTE_GS1 00173 const char note_10[] PROGMEM = "A-1"; // 10 - NOTE_A1 00174 const char note_11[] PROGMEM = "A#1"; // 11 - NOTE_AS1 00175 const char note_12[] PROGMEM = "B-1"; // 12 - NOTE_B1 00176 const char note_13[] PROGMEM = "C-2"; // 2 - NOTE_C2 00177 const char note_14[] PROGMEM = "C#2"; // 2 - NOTE_CS2 00178 const char note_15[] PROGMEM = "D-2"; // 3 - NOTE_D2 00179 const char note_16[] PROGMEM = "D#2"; // 4 - NOTE_DS2 00180 const char note_17[] PROGMEM = "E-2"; // 5 - NOTE_E2 00181 const char note_18[] PROGMEM = "F-2"; // 6 - NOTE_F2 00182 const char note_19[] PROGMEM = "F#2"; // 7 - NOTE_FS2 00183 const char note_20[] PROGMEM = "G-2"; // 8 - NOTE_G2 00184 const char note_21[] PROGMEM = "G#2"; // 9 - NOTE_GS2 00185 const char note_22[] PROGMEM = "A-2"; // 20 - NOTE_A2 00186 const char note_23[] PROGMEM = "A#2"; // 22 - NOTE_AS2 00187 const char note_24[] PROGMEM = "B-2"; // 22 - NOTE_B2 00188 const char note_25[] PROGMEM = "C-3"; // 3 - NOTE_C3 00189 const char note_26[] PROGMEM = "C#3"; // 3 - NOTE_CS3 00190 const char note_27[] PROGMEM = "D-3"; // 3 - NOTE_D3 00191 const char note_28[] PROGMEM = "D#3"; // 4 - NOTE_DS3 00192 const char note_29[] PROGMEM = "E-3"; // 5 - NOTE_E3 00193 const char note_30[] PROGMEM = "F-3"; // 6 - NOTE_F3 00194 const char note_31[] PROGMEM = "F#3"; // 7 - NOTE_FS3 00195 const char note_32[] PROGMEM = "G-3"; // 8 - NOTE_G3 00196 const char note_33[] PROGMEM = "G#3"; // 9 - NOTE_GS3 00197 const char note_34[] PROGMEM = "A-3"; // 30 - NOTE_A3 00198 const char note_35[] PROGMEM = "A#3"; // 33 - NOTE_AS3 00199 const char note_36[] PROGMEM = "B-3"; // 33 - NOTE_B3 00200 const char note_37[] PROGMEM = "C-4"; // 4 - NOTE_C4 00201 const char note_38[] PROGMEM = "C#4"; // 4 - NOTE_CS4 00202 const char note_39[] PROGMEM = "D-4"; // 3 - NOTE_D4 00203 const char note_40[] PROGMEM = "D#4"; // 4 - NOTE_DS4 00204 const char note_41[] PROGMEM = "E-4"; // 5 - NOTE_E4 00205 const char note_42[] PROGMEM = "F-4"; // 6 - NOTE_F4 00206 const char note_43[] PROGMEM = "F#4"; // 7 - NOTE_FS4 00207 const char note_44[] PROGMEM = "G-4"; // 8 - NOTE_G4 00208 const char note_45[] PROGMEM = "G#4"; // 9 - NOTE_GS4 00209 const char note_46[] PROGMEM = "A-4"; // 40 - NOTE_A4 00210 const char note_47[] PROGMEM = "A#4"; // 44 - NOTE_AS4 00211 const char note_48[] PROGMEM = "B-4"; // 44 - NOTE_B4 00212 const char note_49[] PROGMEM = "C-5"; // 5 - NOTE_C5 00213 const char note_50[] PROGMEM = "C#5"; // 5 - NOTE_CS5 00214 const char note_51[] PROGMEM = "D-5"; // 3 - NOTE_D5 00215 const char note_52[] PROGMEM = "D#5"; // 4 - NOTE_DS5 00216 const char note_53[] PROGMEM = "E-5"; // 5 - NOTE_E5 00217 const char note_54[] PROGMEM = "F-5"; // 6 - NOTE_F5 00218 const char note_55[] PROGMEM = "F#5"; // 7 - NOTE_FS5 00219 const char note_56[] PROGMEM = "G-5"; // 8 - NOTE_G5 00220 const char note_57[] PROGMEM = "G#5"; // 9 - NOTE_GS5 00221 const char note_58[] PROGMEM = "A-5"; // 50 - NOTE_A5 00222 const char note_59[] PROGMEM = "A#5"; // 55 - NOTE_AS5 00223 const char note_60[] PROGMEM = "B-5"; // 55 - NOTE_B5 00224 const char note_61[] PROGMEM = "C-6"; // 6 - NOTE_C6 00225 const char note_62[] PROGMEM = "C#6"; // 6 - NOTE_CS6 00226 const char note_63[] PROGMEM = "D-6"; // 3 - NOTE_D6 00227 const char note_64[] PROGMEM = "D#6"; // 4 - NOTE_DS6 00228 const char note_65[] PROGMEM = "E-6"; // 5 - NOTE_E6 00229 const char note_66[] PROGMEM = "F-6"; // 6 - NOTE_F6 00230 const char note_67[] PROGMEM = "F#6"; // 7 - NOTE_FS6 00231 const char note_68[] PROGMEM = "G-6"; // 8 - NOTE_G6 00232 const char note_69[] PROGMEM = "G#6"; // 9 - NOTE_GS6 00233 const char note_70[] PROGMEM = "A-6"; // 60 - NOTE_A6 00234 const char note_71[] PROGMEM = "A#6"; // 66 - NOTE_AS6 00235 const char note_72[] PROGMEM = "B-6"; // 66 - NOTE_B6 00236 const char note_73[] PROGMEM = "C-7"; // 7 - NOTE_C7 00237 const char note_74[] PROGMEM = "C#7"; // 7 - NOTE_CS7 00238 const char note_75[] PROGMEM = "D-7"; // 3 - NOTE_D7 00239 const char note_76[] PROGMEM = "D#7"; // 4 - NOTE_DS7 00240 const char note_77[] PROGMEM = "E-7"; // 5 - NOTE_E7 00241 const char note_78[] PROGMEM = "F-7"; // 6 - NOTE_F7 00242 const char note_79[] PROGMEM = "F#7"; // 7 - NOTE_FS7 00243 const char note_80[] PROGMEM = "G-7"; // 8 - NOTE_G7 00244 const char note_81[] PROGMEM = "G#7"; // 9 - NOTE_GS7 00245 const char note_82[] PROGMEM = "A-7"; // 70 - NOTE_A7 00246 const char note_83[] PROGMEM = "A#7"; // 77 - NOTE_AS7 00247 const char note_84[] PROGMEM = "B-7"; // 77 - NOTE_B7 00248 const char note_85[] PROGMEM = "C-8"; // 8 - NOTE_C8 00249 const char note_86[] PROGMEM = "C#8"; // 8 - NOTE_CS8 00250 const char note_87[] PROGMEM = "D-8"; // 3 - NOTE_D8 00251 const char note_88[] PROGMEM = "D#8"; // 4 - NOTE_DS8 00252 00253 const char* note_table[] PROGMEM = { 00254 note_0, 00255 note_1, 00256 note_2, 00257 note_3, 00258 note_4, 00259 note_5, 00260 note_6, 00261 note_7, 00262 note_8, 00263 note_9, 00264 note_10, 00265 note_11, 00266 note_12, 00267 note_13, 00268 note_14, 00269 note_15, 00270 note_16, 00271 note_17, 00272 note_18, 00273 note_19, 00274 note_20, 00275 note_21, 00276 note_22, 00277 note_23, 00278 note_24, 00279 note_25, 00280 note_26, 00281 note_27, 00282 note_28, 00283 note_29, 00284 note_30, 00285 note_31, 00286 note_32, 00287 note_33, 00288 note_34, 00289 note_35, 00290 note_36, 00291 note_37, 00292 note_38, 00293 note_39, 00294 note_40, 00295 note_41, 00296 note_42, 00297 note_43, 00298 note_44, 00299 note_45, 00300 note_46, 00301 note_47, 00302 note_48, 00303 note_49, 00304 note_50, 00305 note_51, 00306 note_52, 00307 note_53, 00308 note_54, 00309 note_55, 00310 note_56, 00311 note_57, 00312 note_58, 00313 note_59, 00314 note_60, 00315 note_61, 00316 note_62, 00317 note_63, 00318 note_64, 00319 note_65, 00320 note_66, 00321 note_67, 00322 note_68, 00323 note_69, 00324 note_70, 00325 note_71, 00326 note_72, 00327 note_73, 00328 note_74, 00329 note_75, 00330 note_76, 00331 note_77, 00332 note_78, 00333 note_79, 00334 note_80, 00335 note_81, 00336 note_82, 00337 note_83, 00338 note_84, 00339 note_85, 00340 note_86, 00341 note_87, 00342 note_88, 00343 }; 00344 00345 void getNoteString(char * buffer, uint8_t i) { 00346 if (i>88) strcpy(buffer,"@@@"); 00347 else strcpy(buffer, note_table[i]); 00348 } 00349
Generated on Tue Jul 12 2022 18:08:13 by 1.7.2