Unified · Split
| @@ -33,12 +33,12 @@ tButterworth bw; · 32 unmodified lines | ||
| 33 | 33 | |
| 34 | 34 | tWaveTable wt; |
| 35 | 35 | tWaveTableS cwt; |
| 36 | −tWaveSynth ws; | |
| 36 | +tWaveOsc ws; | |
| 37 | 37 | |
| 38 | 38 | tBuffer samp; |
| 39 | 39 | tMBSampler sampler; |
| 40 | 40 | |
| 41 | −const int numWavetables = 1; | |
| 41 | +const int numWavetables = 4; | |
| 42 | 42 | tWaveTable wavetables[numWavetables]; |
| 43 | 43 | tSimpleRetune retune; |
| 44 | 44 | |
| @@ -80,13 +80,12 @@ void LEAFTest_init (float sampleRate, int blockSize) · 35 unmodified lines | ||
| 80 | 80 | tPhasor_init(&phasor, &leaf); |
| 81 | 81 | tPhasor_setFreq(&phasor, 220.f); |
| 82 | 82 | |
| 83 | − float* set[4]; | |
| 84 | − set[0] = (float*)__leaf_table_sinewave; | |
| 85 | − set[1] = (float*)__leaf_table_triangle[0]; | |
| 86 | − set[2] = (float*)__leaf_table_squarewave[0]; | |
| 87 | − set[3] = (float*)__leaf_table_sawtooth[0]; | |
| 83 | + tWaveTable_init(&wavetables[0], (float*)__leaf_table_sinewave, 2048, 20000.f, &leaf); | |
| 84 | + tWaveTable_init(&wavetables[1], (float*)__leaf_table_triangle, 2048, 20000.f, &leaf); | |
| 85 | + tWaveTable_init(&wavetables[2], (float*)__leaf_table_squarewave, 2048, 20000.f, &leaf); | |
| 86 | + tWaveTable_init(&wavetables[3], (float*)__leaf_table_sawtooth, 2048, 20000.f, &leaf); | |
| 88 | 87 | |
| 89 | −// tWaveSynth_init(&ws, set, 2048, 4, 10000.f, &leaf); | |
| 88 | + tWaveOsc_init(&ws, wavetables, numWavetables, &leaf); | |
| 90 | 89 | |
| 91 | 90 | lastLoadedAudioSize = 0; |
| 92 | 91 | loadedAudio.clear(); |
| @@ -103,14 +102,10 @@ inline double getSawFall(double angle) { · 10 unmodified lines | ||
| 103 | 102 | |
| 104 | 103 | float LEAFTest_tick (float input) |
| 105 | 104 | { |
| 106 | − tSimpleRetune_tuneVoice(&retune, 0, mtof(roundf(ftom(tSimpleRetune_getInputFrequency(&retune))))); | |
| 107 | − return tSimpleRetune_tick(&retune, input); | |
| 108 | − | |
| 109 | − | |
| 110 | 105 | float out = 0.0f; |
| 111 | − for (int i = 0; i < fmin(loadedAudio.size(), numWavetables); ++i) | |
| 106 | + for (int i = 0; i < numWavetables; ++i) | |
| 112 | 107 | { |
| 113 | −// out += tWaveTable_tick(&wavetables[i]); | |
| 108 | + out += tWaveOsc_tick(&ws); | |
| 114 | 109 | } |
| 115 | 110 | return out; |
| 116 | 111 | } |
| @@ -125,12 +120,12 @@ void LEAFTest_block (void) · 8 unmodified lines | ||
| 125 | 120 | tMBSaw_setFreq(&bsaw, val * 10000.f); |
| 126 | 121 | // tWaveTable_setFreq(&wt, val * 160000.f - 80000.0f); |
| 127 | 122 | // tWaveTableS_setFreq(&cwt, val * 10000.); |
| 128 | − tWaveSynth_setFreq(&ws, val * 10000.f); | |
| 123 | + tWaveOsc_setFreq(&ws, val * 2000.f); | |
| 129 | 124 | // tRetune_tuneVoice(&retune, 0, val * 3.0f + 0.5f); |
| 130 | 125 | // tSimpleRetune_tuneVoice(&sretune, 0, 300); |
| 131 | 126 | |
| 132 | 127 | val = getSliderValue("slider2"); |
| 133 | − tWaveSynth_setIndex(&ws, val); | |
| 128 | + tWaveOsc_setIndex(&ws, val); | |
| 134 | 129 | // tRetune_setPitchFactor(&retune, val * 3.0f + 0.5f, 1); |
| 135 | 130 | |
| 136 | 131 | val = getSliderValue("slider3"); |
| @@ -1005,72 +1005,24 @@ extern "C" { · 1004 unmodified lines | ||
| 1005 | 1005 | float maxFreq, tMempool* const mempool); |
| 1006 | 1006 | void tWaveTable_free(tWaveTable* const osc); |
| 1007 | 1007 | void tWaveTable_setSampleRate (tWaveTable* const osc, float sr); |
| 1008 | − | |
| 1009 | − //============================================================================== | |
| 1010 | − | |
| 1011 | − /*! | |
| 1012 | − @defgroup twavetableosc tWaveOsc | |
| 1013 | − @ingroup oscillators | |
| 1014 | − @brief Anti-aliased wavetable oscillator. | |
| 1015 | − @{ | |
| 1016 | − | |
| 1017 | − @fn float tWaveTable_tick (tWaveTable* const osc) | |
| 1018 | − @brief Tick a tWaveTable oscillator. | |
| 1019 | − @param osc A pointer to the relevant tWaveTable. | |
| 1020 | − @return The ticked sample as a float from -1 to 1. | |
| 1021 | − | |
| 1022 | − @fn void tWaveTable_setFreq (tWaveTable* const osc, float freq) | |
| 1023 | − @brief Set the frequency of a tWaveTable oscillator. | |
| 1024 | − @param osc A pointer to the relevant tWaveTable. | |
| 1025 | − @param freq The frequency to set the oscillator to. | |
| 1026 | − | |
| 1027 | − @} */ | |
| 1028 | − | |
| 1029 | − typedef struct _tWaveOsc | |
| 1030 | − { | |
| 1031 | − tMempool mempool; | |
| 1032 | − tWaveTable table; | |
| 1033 | − float inc, freq; | |
| 1034 | − float phase; | |
| 1035 | − float phaseOffset; | |
| 1036 | − float invSampleRate; | |
| 1037 | − | |
| 1038 | − int oct; | |
| 1039 | − float w; | |
| 1040 | − float aa; | |
| 1041 | − } _tWaveOsc; | |
| 1042 | − | |
| 1043 | − typedef _tWaveOsc* tWaveOsc; | |
| 1044 | − | |
| 1045 | − void tWaveOsc_init(tWaveOsc* const osc, tWaveTable* const table, LEAF* const leaf); | |
| 1046 | − void tWaveOsc_initToPool(tWaveOsc* const osc, tWaveTable* const table, tMempool* const mempool); | |
| 1047 | − void tWaveOsc_free(tWaveOsc* const osc); | |
| 1048 | − | |
| 1049 | − float tWaveOsc_tick(tWaveOsc* const osc); | |
| 1050 | − void tWaveOsc_setFreq(tWaveOsc* const osc, float freq); | |
| 1051 | − void tWaveOsc_setAntiAliasing(tWaveOsc* const osc, float aa); | |
| 1052 | − void tWaveOsc_setPhaseOffset(tWaveOsc* const osc, float phase); | |
| 1053 | − void tWaveOsc_setSampleRate (tWaveOsc* const osc, float sr); | |
| 1054 | 1008 | |
| 1055 | 1009 | //============================================================================== |
| 1056 | 1010 | |
| 1057 | 1011 | /*! |
| 1058 | − @defgroup twavesynth tWaveSynth | |
| 1012 | + @defgroup twaveosc tWaveOsc | |
| 1059 | 1013 | @ingroup oscillators |
| 1060 | 1014 | @brief Set of anti-aliased wavetable oscillators that can be faded between. |
| 1061 | 1015 | @{ |
| 1062 | 1016 | |
| 1063 | − @fn void tWaveSynth_init(tWaveSynth* const osc, const float** tables, int n, int size, float maxFreq, LEAF* const leaf) | |
| 1064 | − @brief Initialize a tWaveSynth to the default mempool of a LEAF instance. | |
| 1065 | − @param osc A pointer to the tWaveSynth to initialize. | |
| 1017 | + @fn void tWaveOsc_init(tWaveOsc* const osc, const float** tables, int n, int size, float maxFreq, LEAF* const leaf) | |
| 1018 | + @brief Initialize a tWaveOsc to the default mempool of a LEAF instance. | |
| 1019 | + @param osc A pointer to the tWaveOsc to initialize. | |
| 1066 | 1020 | @param tables An array of pointers to wavetable data. |
| 1067 | 1021 | @param n The number of wavetables. |
| 1068 | − @param size The number of samples in each of the wavetables. | |
| 1069 | − @param maxFreq The maximum expected frequency of the oscillator. The higher this is, the more memory will be needed. | |
| 1070 | 1022 | @param leaf A pointer to the leaf instance. |
| 1071 | 1023 | |
| 1072 | − @fn void tWaveSynth_initToPool(tWaveSynth* const osc, const float** tables, int n, int size, float maxFreq, tMempool* const mempool) | |
| 1073 | − @brief Initialize a tWaveSynth to a specified mempool. | |
| 1024 | + @fn void tWaveOsc_initToPool(tWaveOsc* const osc, const float** tables, int n, int size, float maxFreq, tMempool* const mempool) | |
| 1025 | + @brief Initialize a tWaveOsc to a specified mempool. | |
| 1074 | 1026 | @param osc A pointer to the tWaveTable to initialize. |
| 1075 | 1027 | @param tables An array of pointers to wavetable data. |
| 1076 | 1028 | @param n The number of wavetables. |
| @@ -1078,27 +1030,27 @@ extern "C" { · 1 unmodified line | ||
| 1078 | 1030 | @param maxFreq The maximum expected frequency of the oscillator. The higher this is, the more memory will be needed. |
| 1079 | 1031 | @param mempool A pointer to the tMempool to use. |
| 1080 | 1032 | |
| 1081 | − @fn void tWaveSynth_free (tWaveSynth* const osc) | |
| 1082 | − @brief Free a tWaveSynth from its mempool. | |
| 1083 | − @param osc A pointer to the tWaveSynth to free. | |
| 1033 | + @fn void tWaveOsc_free (tWaveOsc* const osc) | |
| 1034 | + @brief Free a tWaveOsc from its mempool. | |
| 1035 | + @param osc A pointer to the tWaveOsc to free. | |
| 1084 | 1036 | |
| 1085 | − @fn float tWaveSynth_tick (tWaveSynth* const osc) | |
| 1086 | − @brief Tick a tWaveSynth oscillator. | |
| 1087 | − @param osc A pointer to the relevant tWaveSynth. | |
| 1037 | + @fn float tWaveOsc_tick (tWaveOsc* const osc) | |
| 1038 | + @brief Tick a tWaveOsc oscillator. | |
| 1039 | + @param osc A pointer to the relevant tWaveOsc. | |
| 1088 | 1040 | @return The ticked sample as a float from -1 to 1. |
| 1089 | 1041 | |
| 1090 | − @fn void tWaveSynth_setFreq (tWaveSynth* const osc, float freq) | |
| 1091 | − @brief Set the frequency of a tWaveSynth oscillator. | |
| 1092 | − @param osc A pointer to the relevant tWaveSynth. | |
| 1042 | + @fn void tWaveOsc_setFreq (tWaveOsc* const osc, float freq) | |
| 1043 | + @brief Set the frequency of a tWaveOsc oscillator. | |
| 1044 | + @param osc A pointer to the relevant tWaveOsc. | |
| 1093 | 1045 | @param freq The frequency to set the oscillator to. |
| 1094 | 1046 | |
| 1095 | − @fn void tWaveSynth_setIndex(tWaveSynth* const osc, float index) | |
| 1047 | + @fn void tWaveOsc_setIndex(tWaveOsc* const osc, float index) | |
| 1096 | 1048 | @brief Set the output index of the wavetable set. |
| 1097 | 1049 | @param index The new index from 0.0 to 1.0 as a smooth fade from the first wavetable in the set to the last. |
| 1098 | 1050 | |
| 1099 | 1051 | @} */ |
| 1100 | 1052 | |
| 1101 | − typedef struct _tWaveSynth | |
| 1053 | + typedef struct _tWaveOsc | |
| 1102 | 1054 | { |
| 1103 | 1055 | tMempool mempool; |
| 1104 | 1056 | tWaveTable* tables; |
| @@ -1123,24 +1075,20 @@ extern "C" { · 18 unmodified lines | ||
| 1123 | 1075 | float aa; |
| 1124 | 1076 | int numSubTables; |
| 1125 | 1077 | |
| 1126 | − } _tWaveSynth; | |
| 1078 | + } _tWaveOsc; | |
| 1127 | 1079 | |
| 1128 | − typedef _tWaveSynth* tWaveSynth; | |
| 1080 | + typedef _tWaveOsc* tWaveOsc; | |
| 1129 | 1081 | |
| 1130 | − void tWaveSynth_init(tWaveSynth* const cy, tWaveTable* tables, int size, | |
| 1131 | − int numTables, float maxFreq, LEAF* const leaf); | |
| 1132 | − | |
| 1133 | − void tWaveSynth_initToPool(tWaveSynth* const cy, tWaveTable* tables, int size, | |
| 1134 | − int numTables, float maxFreq, tMempool* const mp); | |
| 1135 | − void tWaveSynth_free(tWaveSynth* const osc); | |
| 1082 | + void tWaveOsc_init(tWaveOsc* const cy, tWaveTable* tables, int numTables, LEAF* const leaf); | |
| 1083 | + void tWaveOsc_initToPool(tWaveOsc* const cy, tWaveTable* tables, int numTables, tMempool* const mp); | |
| 1084 | + void tWaveOsc_free(tWaveOsc* const osc); | |
| 1136 | 1085 | |
| 1137 | − float tWaveSynth_tick(tWaveSynth* const osc); | |
| 1138 | − | |
| 1139 | − void tWaveSynth_setFreq(tWaveSynth* const cy, float freq); | |
| 1140 | − void tWaveSynth_setAntiAliasing(tWaveSynth* const osc, float aa); | |
| 1141 | − void tWaveSynth_setIndex(tWaveSynth* const osc, float index); | |
| 1142 | − void tWaveSynth_setTables(tWaveSynth* const cy, tWaveTable* tables, int numTables, int size); | |
| 1143 | − void tWaveSynth_setSampleRate (tWaveSynth* const osc, float sr); | |
| 1086 | + float tWaveOsc_tick(tWaveOsc* const osc); | |
| 1087 | + void tWaveOsc_setFreq(tWaveOsc* const cy, float freq); | |
| 1088 | + void tWaveOsc_setAntiAliasing(tWaveOsc* const osc, float aa); | |
| 1089 | + void tWaveOsc_setIndex(tWaveOsc* const osc, float index); | |
| 1090 | + void tWaveOsc_setTables(tWaveOsc* const cy, tWaveTable* tables, int numTables); | |
| 1091 | + void tWaveOsc_setSampleRate (tWaveOsc* const osc, float sr); | |
| 1144 | 1092 | |
| 1145 | 1093 | //============================================================================== |
| 1146 | 1094 | |
| @@ -1196,168 +1144,51 @@ extern "C" { · 49 unmodified lines | ||
| 1196 | 1144 | void tWaveTableS_free(tWaveTableS* const osc); |
| 1197 | 1145 | void tWaveTableS_setSampleRate (tWaveTableS* const osc, float sr); |
| 1198 | 1146 | |
| 1147 | + | |
| 1148 | + //============================================================================== | |
| 1199 | 1149 | /*! |
| 1200 | 1150 | @defgroup twaveoscs tWaveOscS |
| 1201 | 1151 | @ingroup oscillators |
| 1202 | − @brief A more space-efficient anti-aliased wavetable oscillator than tWaveOsc but with slightly worse fidelity. | |
| 1152 | + @brief Set of anti-aliased wavetable oscillators that can be faded between. | |
| 1203 | 1153 | @{ |
| 1204 | 1154 | |
| 1205 | − @fn void tWaveOscS_init (tWaveOscS* const osc, float* table, int size, float maxFreq, LEAF* const leaf) | |
| 1155 | + @fn void tWaveOscS_init(tWaveOsc* const osc, const float** tables, int n, int size, float maxFreq, LEAF* const leaf) | |
| 1206 | 1156 | @brief Initialize a tWaveOscS to the default mempool of a LEAF instance. |
| 1207 | 1157 | @param osc A pointer to the tWaveOscS to initialize. |
| 1208 | − @param table A pointer to the wavetable data. | |
| 1209 | − @param size The number of samples in the wavetable. | |
| 1210 | − @param maxFreq The maximum expected frequency of the oscillator. The higher this is, the more memory will be needed. | |
| 1158 | + @param tables An array of pointers to wavetable data. | |
| 1159 | + @param n The number of wavetables. | |
| 1211 | 1160 | @param leaf A pointer to the leaf instance. |
| 1212 | 1161 | |
| 1213 | − @fn void tWaveOscS_initToPool (tWaveOscS* const osc, float* table, int size, float maxFreq, tMempool* const mempool) | |
| 1162 | + @fn void tWaveOscS_initToPool(tWaveOsc* const osc, const float** tables, int n, int size, float maxFreq, tMempool* const mempool) | |
| 1214 | 1163 | @brief Initialize a tWaveOscS to a specified mempool. |
| 1215 | − @param osc A pointer to the tWaveOscS to initialize. | |
| 1216 | − @param table A pointer to the wavetable data. | |
| 1217 | − @param size The number of samples in the wave table. | |
| 1164 | + @param osc A pointer to the tWaveTableS to initialize. | |
| 1165 | + @param tables An array of pointers to wavetable data. | |
| 1166 | + @param n The number of wavetables. | |
| 1167 | + @param size The number of samples in each of the wavetables. | |
| 1218 | 1168 | @param maxFreq The maximum expected frequency of the oscillator. The higher this is, the more memory will be needed. |
| 1219 | 1169 | @param mempool A pointer to the tMempool to use. |
| 1220 | 1170 | |
| 1221 | − @fn void tWaveOscS_free (tWaveOscS* const osc) | |
| 1171 | + @fn void tWaveOscS_free (tWaveOsc* const osc) | |
| 1222 | 1172 | @brief Free a tWaveOscS from its mempool. |
| 1223 | 1173 | @param osc A pointer to the tWaveOscS to free. |
| 1224 | 1174 | |
| 1225 | − @fn float tWaveOscS_tick (tWaveOscS* const osc) | |
| 1175 | + @fn float tWaveOscS_tick (tWaveOsc* const osc) | |
| 1226 | 1176 | @brief Tick a tWaveOscS oscillator. |
| 1227 | 1177 | @param osc A pointer to the relevant tWaveOscS. |
| 1228 | 1178 | @return The ticked sample as a float from -1 to 1. |
| 1229 | 1179 | |
| 1230 | − @fn void tWaveOscS_setFreq (tWaveOscS* const osc, float freq) | |
| 1180 | + @fn void tWaveOscS_setFreq (tWaveOsc* const osc, float freq) | |
| 1231 | 1181 | @brief Set the frequency of a tWaveOscS oscillator. |
| 1232 | 1182 | @param osc A pointer to the relevant tWaveOscS. |
| 1233 | 1183 | @param freq The frequency to set the oscillator to. |
| 1234 | 1184 | |
| 1235 | − @} */ | |
| 1236 | − | |
| 1237 | − typedef struct _tWaveOscS | |
| 1238 | − { | |
| 1239 | − tMempool mempool; | |
| 1240 | − tWaveTableS table; | |
| 1241 | − float inc, freq; | |
| 1242 | − float phase; | |
| 1243 | − float phaseOffset; | |
| 1244 | − float invSampleRate; | |
| 1245 | − int oct; | |
| 1246 | − float w; | |
| 1247 | − float aa; | |
| 1248 | − } _tWaveOscS; | |
| 1249 | − | |
| 1250 | − typedef _tWaveOscS* tWaveOscS; | |
| 1251 | − | |
| 1252 | − void tWaveOscS_init(tWaveOscS* const osc, tWaveTableS* const table, LEAF* const leaf); | |
| 1253 | − void tWaveOscS_initToPool(tWaveOscS* const osc, tWaveTableS* const table, tMempool* const mempool); | |
| 1254 | − void tWaveOscS_free(tWaveOscS* const osc); | |
| 1255 | − | |
| 1256 | − float tWaveOscS_tick(tWaveOscS* const osc); | |
| 1257 | − void tWaveOscS_setFreq(tWaveOscS* const osc, float freq); | |
| 1258 | − void tWaveOscS_setAntiAliasing(tWaveOscS* const osc, float aa); | |
| 1259 | − void tWaveOscS_setPhaseOffset(tWaveOscS* const osc, float phase); | |
| 1260 | − void tWaveOscS_setSampleRate (tWaveOscS* const osc, float sr); | |
| 1261 | − | |
| 1262 | − //============================================================================== | |
| 1263 | − /*! | |
| 1264 | − @defgroup twaveoscs tWaveOscS | |
| 1265 | − @ingroup oscillators | |
| 1266 | − @brief A more space-efficient anti-aliased wavetable oscillator than tWaveOsc but with slightly worse fidelity. | |
| 1267 | − @{ | |
| 1268 | − | |
| 1269 | − @fn void tWaveOscS_init (tWaveOscS* const osc, float* table, int size, float maxFreq, LEAF* const leaf) | |
| 1270 | − @brief Initialize a tWaveOscS to the default mempool of a LEAF instance. | |
| 1271 | − @param osc A pointer to the tWaveOscS to initialize. | |
| 1272 | − @param table A pointer to the wavetable data. | |
| 1273 | − @param size The number of samples in the wavetable. | |
| 1274 | − @param maxFreq The maximum expected frequency of the oscillator. The higher this is, the more memory will be needed. | |
| 1275 | − @param leaf A pointer to the leaf instance. | |
| 1276 | − | |
| 1277 | − @fn void tWaveOscS_initToPool (tWaveOscS* const osc, float* table, int size, float maxFreq, tMempool* const mempool) | |
| 1278 | − @brief Initialize a tWaveOscS to a specified mempool. | |
| 1279 | − @param osc A pointer to the tWaveOscS to initialize. | |
| 1280 | − @param table A pointer to the wavetable data. | |
| 1281 | − @param size The number of samples in the wave table. | |
| 1282 | − @param maxFreq The maximum expected frequency of the oscillator. The higher this is, the more memory will be needed. | |
| 1283 | − @param mempool A pointer to the tMempool to use. | |
| 1284 | − | |
| 1285 | − @fn void tWaveOscS_free (tWaveOscS* const osc) | |
| 1286 | − @brief Free a tWaveOscS from its mempool. | |
| 1287 | − @param osc A pointer to the tWaveOscS to free. | |
| 1288 | − | |
| 1289 | − @fn float tWaveOscS_tick (tWaveOscS* const osc) | |
| 1290 | − @brief Tick a tWaveOscS oscillator. | |
| 1291 | − @param osc A pointer to the relevant tWaveOscS. | |
| 1292 | − @return The ticked sample as a float from -1 to 1. | |
| 1293 | − | |
| 1294 | − @fn void tWaveOscS_setFreq (tWaveOscS* const osc, float freq) | |
| 1295 | − @brief Set the frequency of a tWaveOscS oscillator. | |
| 1296 | − @param osc A pointer to the relevant tWaveOscS. | |
| 1297 | − @param freq The frequency to set the oscillator to. | |
| 1298 | − | |
| 1299 | − @} */ | |
| 1300 | − | |
| 1301 | − typedef struct _tWaveSubOscS | |
| 1302 | − { | |
| 1303 | − tMempool mempool; | |
| 1304 | − tWaveTableS table; | |
| 1305 | − | |
| 1306 | − } _tWaveSubOscS; | |
| 1307 | − | |
| 1308 | − typedef _tWaveSubOscS* tWaveSubOscS; | |
| 1309 | − | |
| 1310 | − void tWaveSubOscS_init(tWaveSubOscS* const osc, tWaveTableS* const table, LEAF* const leaf); | |
| 1311 | − void tWaveSubOscS_initToPool(tWaveSubOscS* const osc, tWaveTableS* const table, tMempool* const mempool); | |
| 1312 | − void tWaveSubOscS_free(tWaveSubOscS* const osc); | |
| 1313 | − float tWaveSubOscS_tick(tWaveSubOscS* const cy, float phase, int oct, float w); | |
| 1314 | − | |
| 1315 | − //============================================================================== | |
| 1316 | − /*! | |
| 1317 | − @defgroup twavesynths tWaveSynthS | |
| 1318 | − @ingroup oscillators | |
| 1319 | − @brief Set of anti-aliased wavetable oscillators that can be faded between. | |
| 1320 | − @{ | |
| 1321 | − | |
| 1322 | − @fn void tWaveSynthS_init(tWaveSynth* const osc, const float** tables, int n, int size, float maxFreq, LEAF* const leaf) | |
| 1323 | − @brief Initialize a tWaveSynthS to the default mempool of a LEAF instance. | |
| 1324 | − @param osc A pointer to the tWaveSynthS to initialize. | |
| 1325 | − @param tables An array of pointers to wavetable data. | |
| 1326 | − @param n The number of wavetables. | |
| 1327 | − @param size The number of samples in each of the wavetables. | |
| 1328 | − @param maxFreq The maximum expected frequency of the oscillator. The higher this is, the more memory will be needed. | |
| 1329 | − @param leaf A pointer to the leaf instance. | |
| 1330 | − | |
| 1331 | − @fn void tWaveSynthS_initToPool(tWaveSynth* const osc, const float** tables, int n, int size, float maxFreq, tMempool* const mempool) | |
| 1332 | − @brief Initialize a tWaveSynthS to a specified mempool. | |
| 1333 | − @param osc A pointer to the tWaveTableS to initialize. | |
| 1334 | − @param tables An array of pointers to wavetable data. | |
| 1335 | − @param n The number of wavetables. | |
| 1336 | − @param size The number of samples in each of the wavetables. | |
| 1337 | − @param maxFreq The maximum expected frequency of the oscillator. The higher this is, the more memory will be needed. | |
| 1338 | − @param mempool A pointer to the tMempool to use. | |
| 1339 | − | |
| 1340 | − @fn void tWaveSynthS_free (tWaveSynth* const osc) | |
| 1341 | − @brief Free a tWaveSynthS from its mempool. | |
| 1342 | − @param osc A pointer to the tWaveSynthS to free. | |
| 1343 | − | |
| 1344 | − @fn float tWaveSynthS_tick (tWaveSynth* const osc) | |
| 1345 | − @brief Tick a tWaveSynthS oscillator. | |
| 1346 | − @param osc A pointer to the relevant tWaveSynthS. | |
| 1347 | − @return The ticked sample as a float from -1 to 1. | |
| 1348 | − | |
| 1349 | − @fn void tWaveSynthS_setFreq (tWaveSynth* const osc, float freq) | |
| 1350 | − @brief Set the frequency of a tWaveSynthS oscillator. | |
| 1351 | − @param osc A pointer to the relevant tWaveSynthS. | |
| 1352 | − @param freq The frequency to set the oscillator to. | |
| 1353 | − | |
| 1354 | − @fn void tWaveSynthS_setIndex(tWaveSynth* const osc, float index) | |
| 1185 | + @fn void tWaveOscS_setIndex(tWaveOsc* const osc, float index) | |
| 1355 | 1186 | @brief Set the output index of the wavetable set. |
| 1356 | 1187 | @param index The new index from 0.0 to 1.0 as a smooth fade from the first wavetable in the set to the last. |
| 1357 | 1188 | |
| 1358 | 1189 | @} */ |
| 1359 | 1190 | |
| 1360 | − typedef struct _tWaveSynthS | |
| 1191 | + typedef struct _tWaveOscS | |
| 1361 | 1192 | { |
| 1362 | 1193 | tMempool mempool; |
| 1363 | 1194 | |
| @@ -1365,7 +1196,6 @@ extern "C" { · 1 unmodified line | ||
| 1365 | 1196 | |
| 1366 | 1197 | tWaveTableS* tables; |
| 1367 | 1198 | |
| 1368 | − tWaveSubOscS* oscs; | |
| 1369 | 1199 | int numTables; |
| 1370 | 1200 | float index; |
| 1371 | 1201 | float maxFreq; |
| @@ -1387,22 +1217,20 @@ extern "C" { · 15 unmodified lines | ||
| 1387 | 1217 | float aa; |
| 1388 | 1218 | int numSubTables; |
| 1389 | 1219 | |
| 1390 | − } _tWaveSynthS; | |
| 1391 | − | |
| 1392 | − typedef _tWaveSynthS* tWaveSynthS; | |
| 1393 | − | |
| 1394 | − void tWaveSynthS_init(tWaveSynthS* const cy, tWaveTableS* tables, int size, | |
| 1395 | − int numTables, float maxFreq, LEAF* const leaf); | |
| 1396 | − void tWaveSynthS_initToPool(tWaveSynthS* const osc, tWaveTableS* tables, int size, | |
| 1397 | − int numTables, float maxFreq, tMempool* const mempool); | |
| 1398 | − void tWaveSynthS_free(tWaveSynthS* const osc); | |
| 1399 | − | |
| 1400 | − float tWaveSynthS_tick(tWaveSynthS* const osc); | |
| 1401 | − void tWaveSynthS_setFreq(tWaveSynthS* const osc, float freq); | |
| 1402 | − void tWaveSynthS_setAntiAliasing(tWaveSynthS* const osc, float aa); | |
| 1403 | − void tWaveSynthS_setIndex(tWaveSynthS* const osc, float index); | |
| 1404 | −// void tWaveSynthS_setIndexTable(tWaveSynthS* const osc, int i, float* table, int size); | |
| 1405 | − void tWaveSynthS_setSampleRate (tWaveSynthS* const osc, float sr); | |
| 1220 | + } _tWaveOscS; | |
| 1221 | + | |
| 1222 | + typedef _tWaveOscS* tWaveOscS; | |
| 1223 | + | |
| 1224 | + void tWaveOscS_init(tWaveOscS* const cy, tWaveTableS* tables, int numTables, LEAF* const leaf); | |
| 1225 | + void tWaveOscS_initToPool(tWaveOscS* const osc, tWaveTableS* tables, int numTables, tMempool* const mempool); | |
| 1226 | + void tWaveOscS_free(tWaveOscS* const osc); | |
| 1227 | + | |
| 1228 | + float tWaveOscS_tick(tWaveOscS* const osc); | |
| 1229 | + void tWaveOscS_setFreq(tWaveOscS* const osc, float freq); | |
| 1230 | + void tWaveOscS_setAntiAliasing(tWaveOscS* const osc, float aa); | |
| 1231 | + void tWaveOscS_setIndex(tWaveOscS* const osc, float index); | |
| 1232 | +// void tWaveOscS_setIndexTable(tWaveOscS* const osc, int i, float* table, int size); | |
| 1233 | + void tWaveOscS_setSampleRate (tWaveOscS* const osc, float sr); | |
| 1406 | 1234 | |
| 1407 | 1235 | #ifdef __cplusplus |
| 1408 | 1236 | } |
| @@ -604,7 +604,7 @@ extern "C" { · 603 unmodified lines | ||
| 604 | 604 | float tLivingString2_tick (tLivingString2* const, float input); |
| 605 | 605 | float tLivingString2_tickEfficient (tLivingString2* const, float input); |
| 606 | 606 | |
| 607 | − float tLivingString2_udpateDelays(tLivingString2* const pl); //necessary if using tickEfficient (so that parameter setting can be put in a slower process). included in standard tick. | |
| 607 | + void tLivingString2_updateDelays(tLivingString2* const pl); //necessary if using tickEfficient (so that parameter setting can be put in a slower process). included in standard tick. | |
| 608 | 608 | float tLivingString2_sample (tLivingString2* const); |
| 609 | 609 | void tLivingString2_setFreq (tLivingString2* const, float freq); |
| 610 | 610 | void tLivingString2_setWaveLength (tLivingString2* const, float waveLength); // in samples |
| @@ -1925,137 +1925,18 @@ void tWaveTable_setSampleRate(tWaveTable* const cy, float sr) · 1924 unmodified lines | ||
| 1925 | 1925 | tButterworth_free(&c->bl); |
| 1926 | 1926 | } |
| 1927 | 1927 | |
| 1928 | −//======================================================================================= | |
| 1929 | −//======================================================================================= | |
| 1930 | − | |
| 1931 | −void tWaveOsc_init(tWaveOsc* const cy, tWaveTable* const table, LEAF* const leaf) | |
| 1932 | −{ | |
| 1933 | − tWaveOsc_initToPool(cy, table, &leaf->mempool); | |
| 1934 | −} | |
| 1935 | − | |
| 1936 | −void tWaveOsc_initToPool(tWaveOsc* const cy, tWaveTable* const table, tMempool* const mp) | |
| 1937 | −{ | |
| 1938 | − _tMempool* m = *mp; | |
| 1939 | − _tWaveOsc* c = *cy = (_tWaveOsc*) mpool_alloc(sizeof(_tWaveOsc), m); | |
| 1940 | − c->mempool = m; | |
| 1941 | − LEAF* leaf = c->mempool->leaf; | |
| 1942 | − | |
| 1943 | − c->table = *table; | |
| 1944 | − | |
| 1945 | − c->inc = 0.0f; | |
| 1946 | − c->phase = 0.0f; | |
| 1947 | − c->phaseOffset = 0.0f; | |
| 1948 | − c->aa = 0.5f; | |
| 1949 | − | |
| 1950 | − c->invSampleRate = leaf->invSampleRate; | |
| 1951 | − | |
| 1952 | − tWaveOsc_setFreq(cy, 220); | |
| 1953 | −} | |
| 1954 | − | |
| 1955 | −void tWaveOsc_free(tWaveOsc* const cy) | |
| 1956 | −{ | |
| 1957 | − _tWaveOsc* c = *cy; | |
| 1958 | − mpool_free((char*)c, c->mempool); | |
| 1959 | −} | |
| 1960 | − | |
| 1961 | −float tWaveOsc_tick(tWaveOsc* const cy) | |
| 1962 | −{ | |
| 1963 | − _tWaveOsc* c = *cy; | |
| 1964 | − | |
| 1965 | − float temp; | |
| 1966 | − int idx; | |
| 1967 | − float frac; | |
| 1968 | − float samp0; | |
| 1969 | − float samp1; | |
| 1970 | − | |
| 1971 | − int size = c->table->size; | |
| 1972 | − int sizeMask = c->table->sizeMask; | |
| 1973 | − float** tables = c->table->tables; | |
| 1974 | − | |
| 1975 | − // Phasor increment | |
| 1976 | − c->phase += c->inc; | |
| 1977 | − if (c->phase + c->phaseOffset >= 1.0f) c->phase -= 1.0f; | |
| 1978 | − if (c->phase + c->phaseOffset < 0.0f) c->phase += 1.0f; | |
| 1979 | − | |
| 1980 | − // Wavetable synthesis | |
| 1981 | − temp = size * (c->phase + c->phaseOffset); | |
| 1982 | − | |
| 1983 | − idx = (int)temp; | |
| 1984 | − frac = temp - (float)idx; | |
| 1985 | − samp0 = tables[c->oct][idx]; | |
| 1986 | − idx = (idx + 1) & sizeMask; | |
| 1987 | − if (++idx >= size) idx = 0; | |
| 1988 | − samp1 = tables[c->oct][idx]; | |
| 1989 | − | |
| 1990 | − float oct0 = (samp0 + (samp1 - samp0) * frac); | |
| 1991 | − | |
| 1992 | − idx = (int)temp; | |
| 1993 | − samp0 = tables[c->oct+1][idx]; | |
| 1994 | − idx = (idx + 1) & sizeMask; | |
| 1995 | − samp1 = tables[c->oct+1][idx]; | |
| 1996 | − | |
| 1997 | − float oct1 = (samp0 + (samp1 - samp0) * frac); | |
| 1998 | − | |
| 1999 | − return oct0 + (oct1 - oct0) * c->w; | |
| 2000 | −} | |
| 2001 | − | |
| 2002 | −void tWaveOsc_setFreq(tWaveOsc* const cy, float freq) | |
| 2003 | −{ | |
| 2004 | − _tWaveOsc* c = *cy; | |
| 2005 | − | |
| 2006 | − c->freq = freq; | |
| 2007 | − | |
| 2008 | − c->inc = c->freq * c->invSampleRate; | |
| 2009 | − c->inc -= (int)c->inc; | |
| 2010 | − | |
| 2011 | − // abs for negative frequencies | |
| 2012 | − c->w = fabsf(c->freq * c->table->invBaseFreq); | |
| 2013 | − | |
| 2014 | − // Probably ok to use a log2 approx here; won't effect tuning at all, just crossfading between octave tables | |
| 2015 | − c->w = log2f_approx(c->w) + c->aa; // adding an offset here will shift our table selection upward, reducing aliasing but lower high freq fidelity. +1.0f should remove all aliasing | |
| 2016 | − if (c->w < 0.0f) c->w = 0.0f; // If c->w is < 0.0f, then freq is less than our base freq | |
| 2017 | − c->oct = (int)c->w; | |
| 2018 | − c->w -= c->oct; | |
| 2019 | − | |
| 2020 | − // When out of range of our tables, this will prevent a crash. | |
| 2021 | − // Also causes a blip but fine since we're above maxFreq at this point. | |
| 2022 | − if (c->oct >= c->table->numTables - 1) c->oct = c->table->numTables - 2; | |
| 2023 | −} | |
| 2024 | − | |
| 2025 | −void tWaveOsc_setAntiAliasing(tWaveOsc* const cy, float aa) | |
| 2026 | −{ | |
| 2027 | − _tWaveOsc* c = *cy; | |
| 2028 | − c->aa = aa; | |
| 2029 | − tWaveOsc_setFreq(cy, c->freq); | |
| 2030 | −} | |
| 2031 | − | |
| 2032 | −void tWaveOsc_setPhaseOffset(tWaveOsc* const cy, float phase) | |
| 2033 | −{ | |
| 2034 | − _tWaveOsc* c = *cy; | |
| 2035 | − c->phaseOffset = phase - (int)phase; | |
| 2036 | −} | |
| 2037 | − | |
| 2038 | −void tWaveOsc_setSampleRate(tWaveOsc* const cy, float sr) | |
| 2039 | −{ | |
| 2040 | − _tWaveOsc* c = *cy; | |
| 2041 | − c->invSampleRate = 1.0f/sr; | |
| 2042 | − tWaveOsc_setFreq(cy, c->freq); | |
| 2043 | −} | |
| 2044 | − | |
| 2045 | 1928 | //================================================================================================ |
| 2046 | 1929 | //================================================================================================ |
| 2047 | 1930 | |
| 2048 | −void tWaveSynth_init(tWaveSynth* const cy, tWaveTable* tables, int size, | |
| 2049 | − int numTables, float maxFreq, LEAF* const leaf) | |
| 1931 | +void tWaveOsc_init(tWaveOsc* const cy, tWaveTable* tables, int numTables, LEAF* const leaf) | |
| 2050 | 1932 | { |
| 2051 | − tWaveSynth_initToPool(cy, tables, size, numTables, maxFreq, &leaf->mempool); | |
| 1933 | + tWaveOsc_initToPool(cy, tables, numTables, &leaf->mempool); | |
| 2052 | 1934 | } |
| 2053 | 1935 | |
| 2054 | −void tWaveSynth_initToPool(tWaveSynth* const cy, tWaveTable* tables, int size, | |
| 2055 | − int numTables, float maxFreq, tMempool* const mp) | |
| 1936 | +void tWaveOsc_initToPool(tWaveOsc* const cy, tWaveTable* tables, int numTables, tMempool* const mp) | |
| 2056 | 1937 | { |
| 2057 | 1938 | _tMempool* m = *mp; |
| 2058 | − _tWaveSynth* c = *cy = (_tWaveSynth*) mpool_alloc(sizeof(_tWaveSynth), m); | |
| 1939 | + _tWaveOsc* c = *cy = (_tWaveOsc*) mpool_alloc(sizeof(_tWaveOsc), m); | |
| 2059 | 1940 | |
| 2060 | 1941 | c->mempool = m; |
| 2061 | 1942 | |
| @@ -2070,29 +1951,28 @@ void tWaveSynth_initToPool(tWaveSynth* const cy, tWaveTable* tables, int size, · 8 unmodified lines | ||
| 2070 | 1951 | c->phase = 0; |
| 2071 | 1952 | c->inc = 0; |
| 2072 | 1953 | c->oct = 0; |
| 2073 | − c->size = size; | |
| 1954 | + c->size = c->tables[0]->size; | |
| 2074 | 1955 | c->w = 0.0f; |
| 2075 | 1956 | c->aa = 0.5f; |
| 2076 | 1957 | c->sampleRate = leaf->sampleRate; |
| 2077 | 1958 | // Determine base frequency |
| 2078 | − c->baseFreq = c->sampleRate / (float) size; | |
| 1959 | + c->baseFreq = c->sampleRate / (float) c->size; | |
| 2079 | 1960 | c->invBaseFreq = 1.0f / c->baseFreq; |
| 2080 | 1961 | c->numSubTables = c->tables[0]->numTables; |
| 2081 | 1962 | |
| 2082 | 1963 | c->invSampleRateTimesTwoTo32 = leaf->invSampleRate * TWO_TO_32; |
| 2083 | − c->maxFreq = maxFreq; | |
| 1964 | + c->maxFreq = c->tables[0]->maxFreq; | |
| 2084 | 1965 | } |
| 2085 | 1966 | |
| 2086 | −void tWaveSynth_free(tWaveSynth* const cy) | |
| 1967 | +void tWaveOsc_free(tWaveOsc* const cy) | |
| 2087 | 1968 | { |
| 2088 | − _tWaveSynth* c = *cy; | |
| 1969 | + _tWaveOsc* c = *cy; | |
| 2089 | 1970 | mpool_free((char*)c, c->mempool); |
| 2090 | 1971 | } |
| 2091 | 1972 | |
| 2092 | − | |
| 2093 | −float tWaveSynth_tick(tWaveSynth* const cy) | |
| 1973 | +float tWaveOsc_tick(tWaveOsc* const cy) | |
| 2094 | 1974 | { |
| 2095 | − _tWaveSynth* c = *cy; | |
| 1975 | + _tWaveOsc* c = *cy; | |
| 2096 | 1976 | |
| 2097 | 1977 | // Phasor increment (unsigned 32bit int wraps automatically with overflow so no need for if branch checks, as you need with float) |
| 2098 | 1978 | c->phase += c->inc; |
| @@ -2159,9 +2039,9 @@ float tWaveSynth_tick(tWaveSynth* const cy) · 60 unmodified lines | ||
| 2159 | 2039 | return s1 + (s2 - s1) * c->mix; |
| 2160 | 2040 | } |
| 2161 | 2041 | |
| 2162 | −void tWaveSynth_setFreq(tWaveSynth* const cy, float freq) | |
| 2042 | +void tWaveOsc_setFreq(tWaveOsc* const cy, float freq) | |
| 2163 | 2043 | { |
| 2164 | − _tWaveSynth* c = *cy; | |
| 2044 | + _tWaveOsc* c = *cy; | |
| 2165 | 2045 | |
| 2166 | 2046 | c->freq = freq; |
| 2167 | 2047 | |
| @@ -2179,15 +2059,15 @@ void tWaveSynth_setFreq(tWaveSynth* const cy, float freq) · 11 unmodified lines | ||
| 2179 | 2059 | if (c->oct >= c->numSubTables - 1) c->oct = c->numSubTables - 2; |
| 2180 | 2060 | } |
| 2181 | 2061 | |
| 2182 | −void tWaveSynth_setAntiAliasing(tWaveSynth* const cy, float aa) | |
| 2062 | +void tWaveOsc_setAntiAliasing(tWaveOsc* const cy, float aa) | |
| 2183 | 2063 | { |
| 2184 | − _tWaveSynth* c = *cy; | |
| 2064 | + _tWaveOsc* c = *cy; | |
| 2185 | 2065 | c->aa = aa; |
| 2186 | 2066 | } |
| 2187 | 2067 | |
| 2188 | −void tWaveSynth_setIndex(tWaveSynth* const cy, float index) | |
| 2068 | +void tWaveOsc_setIndex(tWaveOsc* const cy, float index) | |
| 2189 | 2069 | { |
| 2190 | − _tWaveSynth* c = *cy; | |
| 2070 | + _tWaveOsc* c = *cy; | |
| 2191 | 2071 | c->index = index; |
| 2192 | 2072 | float f = c->index * (c->numTables - 1); |
| 2193 | 2073 | |
| @@ -2197,26 +2077,26 @@ void tWaveSynth_setIndex(tWaveSynth* const cy, float index) · 3 unmodified lines | ||
| 2197 | 2077 | c->mix = f - c->o1; |
| 2198 | 2078 | } |
| 2199 | 2079 | |
| 2200 | −void tWaveSynth_setTables(tWaveSynth* const cy, tWaveTable* tables, int numTables, int size) | |
| 2080 | +void tWaveOsc_setTables(tWaveOsc* const cy, tWaveTable* tables, int numTables) | |
| 2201 | 2081 | { |
| 2202 | − _tWaveSynth* c = *cy; | |
| 2082 | + _tWaveOsc* c = *cy; | |
| 2203 | 2083 | LEAF* leaf = c->mempool->leaf; |
| 2204 | 2084 | c->tables = tables; |
| 2205 | 2085 | c->numTables = numTables; |
| 2206 | − c->size = size; | |
| 2086 | + c->size = c->tables[0]->size; | |
| 2207 | 2087 | |
| 2208 | 2088 | c->sampleRate = leaf->sampleRate; |
| 2209 | 2089 | // Determine base frequency |
| 2210 | − c->baseFreq = c->sampleRate / (float) size; | |
| 2090 | + c->baseFreq = c->sampleRate / (float) c->size; | |
| 2211 | 2091 | c->invBaseFreq = 1.0f / c->baseFreq; |
| 2212 | 2092 | c->numSubTables = c->tables[0]->numTables; |
| 2213 | 2093 | |
| 2214 | 2094 | } |
| 2215 | 2095 | |
| 2216 | 2096 | /*//// eventually gotta finish this so you can X/Y control the indices and fade between non-adjacent tables |
| 2217 | −void tWaveSynthS_setIndexXY(tWaveSynthS* const cy, float indexX, float indexY) | |
| 2097 | +void tWaveOscS_setIndexXY(tWaveOscS* const cy, float indexX, float indexY) | |
| 2218 | 2098 | { |
| 2219 | − _tWaveSynthS* c = *cy; | |
| 2099 | + _tWaveOscS* c = *cy; | |
| 2220 | 2100 | c->index = index; |
| 2221 | 2101 | float f1 = c->index * (c->numTables - 1); |
| 2222 | 2102 | |
| @@ -2229,9 +2109,9 @@ void tWaveSynthS_setIndexXY(tWaveSynthS* const cy, float indexX, float indexY) · 6 unmodified lines | ||
| 2229 | 2109 | } |
| 2230 | 2110 | */ |
| 2231 | 2111 | |
| 2232 | −void tWaveSynth_setSampleRate(tWaveSynth* const cy, float sr) | |
| 2112 | +void tWaveOsc_setSampleRate(tWaveOsc* const cy, float sr) | |
| 2233 | 2113 | { |
| 2234 | − _tWaveSynth* c = *cy; | |
| 2114 | + _tWaveOsc* c = *cy; | |
| 2235 | 2115 | //TODO: need to fix this -JS |
| 2236 | 2116 | for (int i = 0; i < c->numTables; ++i) |
| 2237 | 2117 | { |
| @@ -2407,198 +2287,15 @@ void tWaveTableS_setSampleRate(tWaveTableS* const cy, float sr) · 169 unmodified lines | ||
| 2407 | 2287 | //================================================================================================ |
| 2408 | 2288 | //================================================================================================ |
| 2409 | 2289 | |
| 2410 | −void tWaveOscS_init(tWaveOscS* const cy, tWaveTableS* const table, LEAF* const leaf) | |
| 2290 | +void tWaveOscS_init(tWaveOscS* const cy, tWaveTableS* tables, int numTables, LEAF* const leaf) | |
| 2411 | 2291 | { |
| 2412 | − tWaveOscS_initToPool(cy, table, &leaf->mempool); | |
| 2292 | + tWaveOscS_initToPool(cy, tables, numTables, &leaf->mempool); | |
| 2413 | 2293 | } |
| 2414 | 2294 | |
| 2415 | −void tWaveOscS_initToPool(tWaveOscS* const cy, tWaveTableS* const table, tMempool* const mp) | |
| 2295 | +void tWaveOscS_initToPool(tWaveOscS* const cy, tWaveTableS* tables, int numTables, tMempool* const mp) | |
| 2416 | 2296 | { |
| 2417 | 2297 | _tMempool* m = *mp; |
| 2418 | 2298 | _tWaveOscS* c = *cy = (_tWaveOscS*) mpool_alloc(sizeof(_tWaveOscS), m); |
| 2419 | − c->mempool = m; | |
| 2420 | − LEAF* leaf = c->mempool->leaf; | |
| 2421 | − | |
| 2422 | − c->table = *table; | |
| 2423 | − | |
| 2424 | − c->invSampleRate = leaf->invSampleRate; | |
| 2425 | − c->inc = 0.0f; | |
| 2426 | − c->phase = 0.0f; | |
| 2427 | − c->phaseOffset = 0.0f; | |
| 2428 | − c->aa = 0.5f; | |
| 2429 | − | |
| 2430 | − tWaveOscS_setFreq(cy, 220); | |
| 2431 | −} | |
| 2432 | − | |
| 2433 | −void tWaveOscS_free(tWaveOscS* const cy) | |
| 2434 | −{ | |
| 2435 | − _tWaveOscS* c = *cy; | |
| 2436 | − mpool_free((char*)c, c->mempool); | |
| 2437 | −} | |
| 2438 | − | |
| 2439 | −float tWaveOscS_tick(tWaveOscS* const cy) | |
| 2440 | −{ | |
| 2441 | − _tWaveOscS* c = *cy; | |
| 2442 | − | |
| 2443 | − float temp; | |
| 2444 | − int idx; | |
| 2445 | − float frac; | |
| 2446 | − float samp0; | |
| 2447 | − float samp1; | |
| 2448 | − | |
| 2449 | − // Phasor increment | |
| 2450 | − c->phase += c->inc; | |
| 2451 | − if (c->phase >= 1.0f) c->phase -= 1.0f; | |
| 2452 | − if (c->phase < 0.0f) c->phase += 1.0f; | |
| 2453 | − | |
| 2454 | − int* sizes = c->table->sizes; | |
| 2455 | − int* sizeMasks = c->table->sizeMasks; | |
| 2456 | − float** tables = c->table->tables; | |
| 2457 | − | |
| 2458 | − // Wavetable synthesis | |
| 2459 | − temp = sizes[c->oct] * (c->phase + c->phaseOffset); | |
| 2460 | − idx = (int)temp; | |
| 2461 | − frac = temp - (float)idx; | |
| 2462 | − samp0 = tables[c->oct][idx]; | |
| 2463 | − idx = (idx + 1) & sizeMasks[c->oct]; | |
| 2464 | − samp1 = tables[c->oct][idx]; | |
| 2465 | − | |
| 2466 | − float oct0 = (samp0 + (samp1 - samp0) * frac); | |
| 2467 | − | |
| 2468 | − temp = sizes[c->oct+1] * (c->phase + c->phaseOffset); | |
| 2469 | − idx = (int)temp; | |
| 2470 | − frac = temp - (float)idx; | |
| 2471 | − samp0 = tables[c->oct+1][idx]; | |
| 2472 | − idx = (idx + 1) & sizeMasks[c->oct + 1]; | |
| 2473 | − samp1 = tables[c->oct+1][idx]; | |
| 2474 | − | |
| 2475 | − float oct1 = (samp0 + (samp1 - samp0) * frac); | |
| 2476 | − | |
| 2477 | − return oct0 + (oct1 - oct0) * c->w; | |
| 2478 | −} | |
| 2479 | − | |
| 2480 | −void tWaveOscS_setFreq(tWaveOscS* const cy, float freq) | |
| 2481 | −{ | |
| 2482 | − _tWaveOscS* c = *cy; | |
| 2483 | − | |
| 2484 | − c->freq = freq; | |
| 2485 | − | |
| 2486 | − c->inc = c->freq * c->invSampleRate; | |
| 2487 | − c->inc -= (int)c->inc; | |
| 2488 | − | |
| 2489 | − // abs for negative frequencies | |
| 2490 | − c->w = fabsf(c->freq * c->table->invBaseFreq); | |
| 2491 | − | |
| 2492 | − // Probably ok to use a log2 approx here; won't effect tuning at all, just crossfading between octave tables | |
| 2493 | − // I bet we could turn this into a lookup and save a lot of processing | |
| 2494 | − c->w = log2f_approx(c->w) + c->aa;//+ LEAF_SQRT2 - 1.0f; adding an offset here will shift our table selection upward, reducing aliasing but lower high freq fidelity. +1.0f should remove all aliasing | |
| 2495 | − if (c->w < 0.0f) c->w = 0.0f; // If c->w is < 0.0f, then freq is less than our base freq | |
| 2496 | − c->oct = (int)c->w; | |
| 2497 | − c->w -= c->oct; | |
| 2498 | − if (c->oct >= c->table->numTables - 1) c->oct = c->table->numTables - 2; | |
| 2499 | −} | |
| 2500 | − | |
| 2501 | −void tWaveOscS_setAntiAliasing(tWaveOscS* const cy, float aa) | |
| 2502 | −{ | |
| 2503 | − _tWaveOscS* c = *cy; | |
| 2504 | − c->aa = aa; | |
| 2505 | − tWaveOscS_setFreq(cy, c->freq); | |
| 2506 | −} | |
| 2507 | − | |
| 2508 | −void tWaveOscS_setPhaseOffset(tWaveOscS* const cy, float phase) | |
| 2509 | −{ | |
| 2510 | − _tWaveOscS* c = *cy; | |
| 2511 | − c->phaseOffset = phase - (int)phase; | |
| 2512 | −} | |
| 2513 | − | |
| 2514 | −void tWaveOscS_setSampleRate(tWaveOscS* const cy, float sr) | |
| 2515 | −{ | |
| 2516 | − _tWaveOscS* c = *cy; | |
| 2517 | − c->invSampleRate = 1.0f/sr; | |
| 2518 | − tWaveOscS_setFreq(cy, c->freq); | |
| 2519 | −} | |
| 2520 | − | |
| 2521 | −//================================================================================================ | |
| 2522 | −//================================================================================================ | |
| 2523 | − | |
| 2524 | − | |
| 2525 | − | |
| 2526 | − | |
| 2527 | − | |
| 2528 | −void tWaveSubOscS_init(tWaveSubOscS* const cy, tWaveTableS* const table, LEAF* const leaf) | |
| 2529 | −{ | |
| 2530 | − tWaveSubOscS_initToPool(cy, table, &leaf->mempool); | |
| 2531 | −} | |
| 2532 | − | |
| 2533 | −void tWaveSubOscS_initToPool(tWaveSubOscS* const cy, tWaveTableS* const table, tMempool* const mp) | |
| 2534 | −{ | |
| 2535 | − _tMempool* m = *mp; | |
| 2536 | − _tWaveSubOscS* c = *cy = (_tWaveSubOscS*) mpool_alloc(sizeof(_tWaveSubOscS), m); | |
| 2537 | − c->mempool = m; | |
| 2538 | − | |
| 2539 | − c->table = *table; | |
| 2540 | −} | |
| 2541 | − | |
| 2542 | −void tWaveSubOscS_free(tWaveSubOscS* const cy) | |
| 2543 | −{ | |
| 2544 | − _tWaveSubOscS* c = *cy; | |
| 2545 | − mpool_free((char*)c, c->mempool); | |
| 2546 | −} | |
| 2547 | − | |
| 2548 | −float tWaveSubOscS_tick(tWaveSubOscS* const cy, float phase, int oct, float w) | |
| 2549 | −{ | |
| 2550 | − _tWaveSubOscS* c = *cy; | |
| 2551 | − | |
| 2552 | − float temp; | |
| 2553 | − int idx; | |
| 2554 | − float frac; | |
| 2555 | − float samp0; | |
| 2556 | − float samp1; | |
| 2557 | − | |
| 2558 | − int* sizes = c->table->sizes; | |
| 2559 | − int* sizeMasks = c->table->sizeMasks; | |
| 2560 | − float** tables = c->table->tables; | |
| 2561 | − | |
| 2562 | − // Wavetable synthesis | |
| 2563 | − temp = sizes[oct] * phase; | |
| 2564 | − idx = (int)temp; | |
| 2565 | − frac = temp - (float)idx; | |
| 2566 | − samp0 = tables[oct][idx]; | |
| 2567 | − idx = (idx + 1) & sizeMasks[oct]; | |
| 2568 | − samp1 = tables[oct][idx]; | |
| 2569 | − | |
| 2570 | − float oct0 = (samp0 + (samp1 - samp0) * frac); | |
| 2571 | − | |
| 2572 | − temp = sizes[oct+1] * phase; | |
| 2573 | − idx = (int)temp; | |
| 2574 | − frac = temp - (float)idx; | |
| 2575 | − samp0 = tables[oct+1][idx]; | |
| 2576 | − idx = (idx + 1) & sizeMasks[oct+1]; | |
| 2577 | − samp1 = tables[oct+1][idx]; | |
| 2578 | − | |
| 2579 | − float oct1 = (samp0 + (samp1 - samp0) * frac); | |
| 2580 | − | |
| 2581 | − return oct0 + (oct1 - oct0) * w; | |
| 2582 | −} | |
| 2583 | − | |
| 2584 | − | |
| 2585 | − | |
| 2586 | − | |
| 2587 | − | |
| 2588 | −//================================================================================================ | |
| 2589 | −//================================================================================================ | |
| 2590 | − | |
| 2591 | −void tWaveSynthS_init(tWaveSynthS* const cy, tWaveTableS* tables, int size, | |
| 2592 | − int numTables, float maxFreq, LEAF* const leaf) | |
| 2593 | −{ | |
| 2594 | − tWaveSynthS_initToPool(cy, tables, size, numTables, maxFreq, &leaf->mempool); | |
| 2595 | −} | |
| 2596 | − | |
| 2597 | −void tWaveSynthS_initToPool(tWaveSynthS* const cy, tWaveTableS* tables, int size, | |
| 2598 | − int numTables, float maxFreq, tMempool* const mp) | |
| 2599 | −{ | |
| 2600 | − _tMempool* m = *mp; | |
| 2601 | − _tWaveSynthS* c = *cy = (_tWaveSynthS*) mpool_alloc(sizeof(_tWaveSynthS), m); | |
| 2602 | 2299 | |
| 2603 | 2300 | c->mempool = m; |
| 2604 | 2301 | |
| @@ -2606,16 +2303,6 @@ void tWaveSynthS_initToPool(tWaveSynthS* const cy, tWaveTableS* tables, int size · 1 unmodified line | ||
| 2606 | 2303 | c->tables = tables; |
| 2607 | 2304 | c->numTables = numTables; |
| 2608 | 2305 | |
| 2609 | − //c->oscs = (tWaveSubOscS*) mpool_alloc(sizeof(tWaveSubOscS*) * c->numTables, m); | |
| 2610 | − | |
| 2611 | −// int i = 0; | |
| 2612 | − //for (int t = 0; t < numTables; ++t) | |
| 2613 | − //{ | |
| 2614 | − //tWaveTableS_initToPool(&c->tables[i], table + (size*t), size, maxFreq, mp); //is the sizeoffloat necessary? is the pointer location in bytes or 32-bit words? | |
| 2615 | − //tWaveSubOscS_initToPool(&c->oscs[i], tables[i], mp); | |
| 2616 | − //i++; | |
| 2617 | − //} | |
| 2618 | − | |
| 2619 | 2306 | c->index = 0.0f; |
| 2620 | 2307 | c->o1 = 0; |
| 2621 | 2308 | c->o2 = 1; |
| @@ -2623,46 +2310,36 @@ void tWaveSynthS_initToPool(tWaveSynthS* const cy, tWaveTableS* tables, int size · 1 unmodified line | ||
| 2623 | 2310 | c->phase = 0; |
| 2624 | 2311 | c->inc = 0; |
| 2625 | 2312 | c->oct = 0; |
| 2626 | − c->size = size; | |
| 2313 | + c->size = c->tables[0]->sizes[0]; | |
| 2627 | 2314 | c->w = 0.0f; |
| 2628 | 2315 | c->aa = 0.5f; |
| 2629 | 2316 | c->sampleRate = leaf->sampleRate; |
| 2630 | 2317 | // Determine base frequency |
| 2631 | − c->baseFreq = c->sampleRate / (float) size; | |
| 2318 | + c->baseFreq = c->sampleRate / (float) c->size; | |
| 2632 | 2319 | c->invBaseFreq = 1.0f / c->baseFreq; |
| 2633 | 2320 | c->numSubTables = c->tables[0]->numTables; |
| 2634 | 2321 | |
| 2635 | 2322 | c->invSampleRateTimesTwoTo32 = leaf->invSampleRate * TWO_TO_32; |
| 2636 | − c->maxFreq = maxFreq; | |
| 2323 | + c->maxFreq = c->tables[0]->maxFreq; | |
| 2637 | 2324 | } |
| 2638 | 2325 | |
| 2639 | −void tWaveSynthS_free(tWaveSynthS* const cy) | |
| 2326 | +void tWaveOscS_free(tWaveOscS* const cy) | |
| 2640 | 2327 | { |
| 2641 | − _tWaveSynthS* c = *cy; | |
| 2328 | + _tWaveOscS* c = *cy; | |
| 2642 | 2329 | |
| 2643 | − for (int i = 0; i < c->numTables; ++i) | |
| 2644 | − { | |
| 2645 | − //tWaveSubOscS_free(&c->oscs[i]); | |
| 2646 | − //mpool_free((char*)c->oscs[i], c->mempool); | |
| 2647 | − } | |
| 2648 | − //mpool_free((char*)c->oscs, c->mempool); | |
| 2649 | 2330 | mpool_free((char*)c, c->mempool); |
| 2650 | 2331 | } |
| 2651 | 2332 | |
| 2652 | 2333 | volatile int errorCounter = 0; |
| 2653 | −float tWaveSynthS_tick(tWaveSynthS* const cy) | |
| 2334 | +float tWaveOscS_tick(tWaveOscS* const cy) | |
| 2654 | 2335 | { |
| 2655 | − _tWaveSynthS* c = *cy; | |
| 2336 | + _tWaveOscS* c = *cy; | |
| 2656 | 2337 | |
| 2657 | 2338 | // Phasor increment (unsigned 32bit int wraps automatically with overflow so no need for if branch checks, as you need with float) |
| 2658 | 2339 | c->phase += c->inc; |
| 2659 | 2340 | float floatPhase = (double)c->phase * 2.32830643654e-10; |
| 2660 | 2341 | float s1 = 0.f, s2 = 0.f; |
| 2661 | 2342 | |
| 2662 | − //s1 = tWaveSubOscS_tick(&c->oscs[c->o1], floatPhase, c->oct, c->w); | |
| 2663 | − //s2 = tWaveSubOscS_tick(&c->oscs[c->o2], floatPhase, c->oct, c->w); | |
| 2664 | − | |
| 2665 | − | |
| 2666 | 2343 | float temp; |
| 2667 | 2344 | int idx; |
| 2668 | 2345 | float frac; |
| @@ -2671,7 +2348,6 @@ float tWaveSynthS_tick(tWaveSynthS* const cy) · 2 unmodified lines | ||
| 2671 | 2348 | |
| 2672 | 2349 | int oct = c->oct; |
| 2673 | 2350 | |
| 2674 | − | |
| 2675 | 2351 | int* sizeMasks = c->tables[c->o1]->sizeMasks; |
| 2676 | 2352 | float** tables = c->tables[c->o1]->tables; |
| 2677 | 2353 | |
| @@ -2685,8 +2361,6 @@ float tWaveSynthS_tick(tWaveSynthS* const cy) · 7 unmodified lines | ||
| 2685 | 2361 | |
| 2686 | 2362 | float oct0 = (samp0 + (samp1 - samp0) * frac); |
| 2687 | 2363 | |
| 2688 | − | |
| 2689 | − | |
| 2690 | 2364 | temp = sizeMasks[oct+1] * floatPhase; |
| 2691 | 2365 | idx = (int)temp; |
| 2692 | 2366 | frac = temp - (float)idx; |
| @@ -2698,7 +2372,6 @@ float tWaveSynthS_tick(tWaveSynthS* const cy) · 5 unmodified lines | ||
| 2698 | 2372 | |
| 2699 | 2373 | s1 = oct0 + (oct1 - oct0) * c->w; |
| 2700 | 2374 | |
| 2701 | − | |
| 2702 | 2375 | sizeMasks = c->tables[c->o2]->sizeMasks; |
| 2703 | 2376 | tables = c->tables[c->o2]->tables; |
| 2704 | 2377 | |
| @@ -2727,9 +2400,9 @@ float tWaveSynthS_tick(tWaveSynthS* const cy) · 22 unmodified lines | ||
| 2727 | 2400 | return s1 + (s2 - s1) * c->mix; |
| 2728 | 2401 | } |
| 2729 | 2402 | |
| 2730 | −void tWaveSynthS_setFreq(tWaveSynthS* const cy, float freq) | |
| 2403 | +void tWaveOscS_setFreq(tWaveOscS* const cy, float freq) | |
| 2731 | 2404 | { |
| 2732 | − _tWaveSynthS* c = *cy; | |
| 2405 | + _tWaveOscS* c = *cy; | |
| 2733 | 2406 | |
| 2734 | 2407 | c->freq = freq; |
| 2735 | 2408 | |
| @@ -2747,15 +2420,15 @@ void tWaveSynthS_setFreq(tWaveSynthS* const cy, float freq) · 11 unmodified lines | ||
| 2747 | 2420 | if (c->oct >= c->numSubTables - 1) c->oct = c->numSubTables - 2; |
| 2748 | 2421 | } |
| 2749 | 2422 | |
| 2750 | −void tWaveSynthS_setAntiAliasing(tWaveSynthS* const cy, float aa) | |
| 2423 | +void tWaveOscS_setAntiAliasing(tWaveOscS* const cy, float aa) | |
| 2751 | 2424 | { |
| 2752 | − _tWaveSynthS* c = *cy; | |
| 2425 | + _tWaveOscS* c = *cy; | |
| 2753 | 2426 | c->aa = aa; |
| 2754 | 2427 | } |
| 2755 | 2428 | |
| 2756 | −void tWaveSynthS_setIndex(tWaveSynthS* const cy, float index) | |
| 2429 | +void tWaveOscS_setIndex(tWaveOscS* const cy, float index) | |
| 2757 | 2430 | { |
| 2758 | − _tWaveSynthS* c = *cy; | |
| 2431 | + _tWaveOscS* c = *cy; | |
| 2759 | 2432 | c->index = index; |
| 2760 | 2433 | float f = c->index * (c->numTables - 1); |
| 2761 | 2434 | |
| @@ -2766,9 +2439,9 @@ void tWaveSynthS_setIndex(tWaveSynthS* const cy, float index) · 4 unmodified lines | ||
| 2766 | 2439 | } |
| 2767 | 2440 | |
| 2768 | 2441 | /*//// eventually gotta finish this so you can X/Y control the indices and fade between non-adjacent tables |
| 2769 | −void tWaveSynthS_setIndexXY(tWaveSynthS* const cy, float indexX, float indexY) | |
| 2442 | +void tWaveOscS_setIndexXY(tWaveOscS* const cy, float indexX, float indexY) | |
| 2770 | 2443 | { |
| 2771 | − _tWaveSynthS* c = *cy; | |
| 2444 | + _tWaveOscS* c = *cy; | |
| 2772 | 2445 | c->index = index; |
| 2773 | 2446 | float f1 = c->index * (c->numTables - 1); |
| 2774 | 2447 | |
| @@ -2781,25 +2454,20 @@ void tWaveSynthS_setIndexXY(tWaveSynthS* const cy, float indexX, float indexY) · 6 unmodified lines | ||
| 2781 | 2454 | } |
| 2782 | 2455 | */ |
| 2783 | 2456 | |
| 2784 | −void tWaveSynthS_setSampleRate(tWaveSynthS* const cy, float sr) | |
| 2457 | +void tWaveOscS_setSampleRate(tWaveOscS* const cy, float sr) | |
| 2785 | 2458 | { |
| 2786 | − _tWaveSynthS* c = *cy; | |
| 2459 | + _tWaveOscS* c = *cy; | |
| 2787 | 2460 | //TODO: need to fix this -JS |
| 2788 | 2461 | for (int i = 0; i < c->numTables; ++i) |
| 2789 | 2462 | { |
| 2790 | 2463 | tWaveTableS_setSampleRate(&c->tables[i], sr); |
| 2791 | − //tWaveSubOscS_setSampleRate(&c->oscs[i], sr); | |
| 2792 | 2464 | } |
| 2793 | 2465 | } |
| 2794 | 2466 | // |
| 2795 | −//void tWaveSynthS_setIndexTable(tWaveSynthS* const cy, int i, float* table, int size) | |
| 2467 | +//void tWaveOscS_setIndexTable(tWaveOscS* const cy, int i, float* table, int size) | |
| 2796 | 2468 | //{ |
| 2797 | −// _tWaveSynthS* c = *cy; | |
| 2469 | +// _tWaveOscS* c = *cy; | |
| 2798 | 2470 | // if (i >= c->numTables) return; |
| 2799 | 2471 | // tWaveTableS_free(&c->tables[i]); |
| 2800 | 2472 | // tWaveTableS_initToPool(&c->tables[i], table, size, c->maxFreq, &c->mempool); |
| 2801 | −// for (int v = 0; v < c->numVoices; ++v) | |
| 2802 | −// { | |
| 2803 | −// tWaveOscS_setFreq(&c->oscs[i][v], c->oscs[i][v]->freq); | |
| 2804 | −// } | |
| 2805 | 2473 | //} |
| @@ -1233,7 +1233,7 @@ float tLivingString2_tickEfficient(tLivingString2* const pl, float input) · 1232 unmodified lines | ||
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | 1235 | |
| 1236 | −float tLivingString2_udpateDelays(tLivingString2* const pl) | |
| 1236 | +void tLivingString2_updateDelays(tLivingString2* const pl) | |
| 1237 | 1237 | { |
| 1238 | 1238 | _tLivingString2* p = *pl; |
| 1239 | 1239 | |