Unified · Split
Binary file not shown.
Binary file not shown.
| @@ -150,6 +150,7 @@ extern "C" { · 149 unmodified lines | |||
| 150 | float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay); | 150 | float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay); |
| 151 | float tTapeDelay_addTo (tTapeDelay* const, float value, uint32_t tapDelay); | 151 | float tTapeDelay_addTo (tTapeDelay* const, float value, uint32_t tapDelay); |
| 152 | float tTapeDelay_tick (tTapeDelay* const, float sample); | 152 | float tTapeDelay_tick (tTapeDelay* const, float sample); |
| 153 | void tTapeDelay_incrementInPoint(tTapeDelay* const dl); | ||
| 153 | float tTapeDelay_getLastOut (tTapeDelay* const); | 154 | float tTapeDelay_getLastOut (tTapeDelay* const); |
| 154 | float tTapeDelay_getLastIn (tTapeDelay* const); | 155 | float tTapeDelay_getLastIn (tTapeDelay* const); |
| 155 | 156 | ||
| @@ -61,8 +61,8 @@ extern "C" { · 60 unmodified lines | |||
| 61 | 61 | ||
| 62 | float inv_sr, inv_441; | 62 | float inv_sr, inv_441; |
| 63 | 63 | ||
| 64 | tDelay allpassDelays[8]; | 64 | tLinearDelay allpassDelays[8]; |
| 65 | tDelay combDelays[6]; | 65 | tLinearDelay combDelays[6]; |
| 66 | float allpassCoeff; | 66 | float allpassCoeff; |
| 67 | float combCoeffs[6]; | 67 | float combCoeffs[6]; |
| 68 | float lowpassState; | 68 | float lowpassState; |
| @@ -77,6 +77,7 @@ extern "C" { · 8 unmodified lines | |||
| 77 | void tNReverb_free (tNReverb* const); | 77 | void tNReverb_free (tNReverb* const); |
| 78 | 78 | ||
| 79 | float tNReverb_tick (tNReverb* const, float input); | 79 | float tNReverb_tick (tNReverb* const, float input); |
| 80 | void tNReverb_tickStereo(tNReverb* const rev, float input, float* output); | ||
| 80 | 81 | ||
| 81 | // Set reverb time in seconds. | 82 | // Set reverb time in seconds. |
| 82 | void tNReverb_setT60 (tNReverb* const, float t60); | 83 | void tNReverb_setT60 (tNReverb* const, float t60); |
| @@ -93,7 +94,7 @@ extern "C" { · 10 unmodified lines | |||
| 93 | float feedback_filter; | 94 | float feedback_filter; |
| 94 | float feedback_gain; | 95 | float feedback_gain; |
| 95 | float mix; | 96 | float mix; |
| 96 | 97 | uint32_t frozen; | |
| 97 | 98 | ||
| 98 | float size, size_max, t; | 99 | float size, size_max, t; |
| 99 | 100 | ||
| @@ -138,6 +139,7 @@ extern "C" { · 38 unmodified lines | |||
| 138 | float tDattorroReverb_tick (tDattorroReverb* const, float input); | 139 | float tDattorroReverb_tick (tDattorroReverb* const, float input); |
| 139 | void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output); | 140 | void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output); |
| 140 | void tDattorroReverb_setMix (tDattorroReverb* const, float mix); | 141 | void tDattorroReverb_setMix (tDattorroReverb* const, float mix); |
| 142 | void tDattorroReverb_setFreeze (tDattorroReverb* const rev, uint32_t freeze); | ||
| 141 | void tDattorroReverb_setHP (tDattorroReverb* const, float freq); | 143 | void tDattorroReverb_setHP (tDattorroReverb* const, float freq); |
| 142 | void tDattorroReverb_setSize (tDattorroReverb* const, float size); | 144 | void tDattorroReverb_setSize (tDattorroReverb* const, float size); |
| 143 | void tDattorroReverb_setInputDelay (tDattorroReverb* const, float preDelay); | 145 | void tDattorroReverb_setInputDelay (tDattorroReverb* const, float preDelay); |
| @@ -35,8 +35,8 @@ extern "C" { · 34 unmodified lines | |||
| 35 | float* buff; | 35 | float* buff; |
| 36 | 36 | ||
| 37 | uint32_t idx; | 37 | uint32_t idx; |
| 38 | uint32_t length; | 38 | uint32_t bufferLength; |
| 39 | 39 | uint32_t recordedLength; | |
| 40 | RecordMode mode; | 40 | RecordMode mode; |
| 41 | 41 | ||
| 42 | int active; | 42 | int active; |
| @@ -64,7 +64,8 @@ extern "C" { · 21 unmodified lines | |||
| 64 | 64 | ||
| 65 | void tBuffer_clear (tBuffer* const); | 65 | void tBuffer_clear (tBuffer* const); |
| 66 | 66 | ||
| 67 | uint32_t tBuffer_getLength(tBuffer* const); | 67 | uint32_t tBuffer_getBufferLength(tBuffer* const); |
| 68 | uint32_t tBuffer_getRecordedLength(tBuffer* const sb); | ||
| 68 | 69 | ||
| 69 | //============================================================================== | 70 | //============================================================================== |
| 70 | 71 | ||
| @@ -92,6 +93,7 @@ extern "C" { · 21 unmodified lines | |||
| 92 | 93 | ||
| 93 | int32_t start, targetstart; | 94 | int32_t start, targetstart; |
| 94 | int32_t end, targetend; | 95 | int32_t end, targetend; |
| 96 | |||
| 95 | uint32_t len; | 97 | uint32_t len; |
| 96 | uint32_t cfxlen; | 98 | uint32_t cfxlen; |
| 97 | float numticks; | 99 | float numticks; |
| @@ -118,7 +120,7 @@ extern "C" { · 20 unmodified lines | |||
| 118 | 120 | ||
| 119 | void tSampler_setStart (tSampler* const, int32_t start); | 121 | void tSampler_setStart (tSampler* const, int32_t start); |
| 120 | void tSampler_setEnd (tSampler* const, int32_t end); | 122 | void tSampler_setEnd (tSampler* const, int32_t end); |
| 121 | 123 | ||
| 122 | static void handleStartEndChange(tSampler* const sp); | 124 | static void handleStartEndChange(tSampler* const sp); |
| 123 | 125 | ||
| 124 | void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length); | 126 | void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length); |
| @@ -552,6 +552,13 @@ float tTapeDelay_tick (tTapeDelay* const dl, float input) · 551 unmodified lines | |||
| 552 | return d->lastOut; | 552 | return d->lastOut; |
| 553 | } | 553 | } |
| 554 | 554 | ||
| 555 | void tTapeDelay_incrementInPoint(tTapeDelay* const dl) | ||
| 556 | { | ||
| 557 | _tTapeDelay* d = *dl; | ||
| 558 | // Increment input pointer modulo length. | ||
| 559 | if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0; | ||
| 560 | } | ||
| 561 | |||
| 555 | 562 | ||
| 556 | void tTapeDelay_setRate(tTapeDelay* const dl, float rate) | 563 | void tTapeDelay_setRate(tTapeDelay* const dl, float rate) |
| 557 | { | 564 | { |
| @@ -71,9 +71,14 @@ void mpool_create (char* memory, size_t size, mpool_t* pool) · 70 unmodified lines | |||
| 71 | 71 | ||
| 72 | pool->head = create_node(pool->mpool, NULL, NULL, pool->msize-header_size); | 72 | pool->head = create_node(pool->mpool, NULL, NULL, pool->msize-header_size); |
| 73 | 73 | ||
| 74 | for (int i = 0; i < pool->head->size; i++) memory[i+header_size]=0; | 74 | for (int i = 0; i < pool->head->size; i++) |
| 75 | { | ||
| 76 | memory[i+header_size]=0; | ||
| 77 | } | ||
| 75 | } | 78 | } |
| 76 | 79 | ||
| 80 | |||
| 81 | |||
| 77 | void leaf_pool_init(char* memory, size_t size) | 82 | void leaf_pool_init(char* memory, size_t size) |
| 78 | { | 83 | { |
| 79 | mpool_create(memory, size, &leaf_pool); | 84 | mpool_create(memory, size, &leaf_pool); |
| @@ -440,6 +440,7 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 439 unmodified lines | |||
| 440 | p->curr=0.0f; | 440 | p->curr=0.0f; |
| 441 | tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions) | 441 | tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions) |
| 442 | tLivingString_setFreq(pl, freq); | 442 | tLivingString_setFreq(pl, freq); |
| 443 | p->freq = freq; | ||
| 443 | tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position | 444 | tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position |
| 444 | tLivingString_setPickPos(pl, pickPos); | 445 | tLivingString_setPickPos(pl, pickPos); |
| 445 | p->prepIndex=prepIndex; | 446 | p->prepIndex=prepIndex; |
| @@ -447,6 +448,7 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 1 unmodified line | |||
| 447 | tLinearDelay_init(&p->delUF,p->waveLengthInSamples, 2400); | 448 | tLinearDelay_init(&p->delUF,p->waveLengthInSamples, 2400); |
| 448 | tLinearDelay_init(&p->delUB,p->waveLengthInSamples, 2400); | 449 | tLinearDelay_init(&p->delUB,p->waveLengthInSamples, 2400); |
| 449 | tLinearDelay_init(&p->delLB,p->waveLengthInSamples, 2400); | 450 | tLinearDelay_init(&p->delLB,p->waveLengthInSamples, 2400); |
| 451 | p->dampFreq = dampFreq; | ||
| 450 | tOnePole_init(&p->bridgeFilter, dampFreq); | 452 | tOnePole_init(&p->bridgeFilter, dampFreq); |
| 451 | tOnePole_init(&p->nutFilter, dampFreq); | 453 | tOnePole_init(&p->nutFilter, dampFreq); |
| 452 | tOnePole_init(&p->prepFilterU, dampFreq); | 454 | tOnePole_init(&p->prepFilterU, dampFreq); |
| @@ -454,6 +456,7 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 1 unmodified line | |||
| 454 | tHighpass_init(&p->DCblockerU,13); | 456 | tHighpass_init(&p->DCblockerU,13); |
| 455 | tHighpass_init(&p->DCblockerL,13); | 457 | tHighpass_init(&p->DCblockerL,13); |
| 456 | p->decay=decay; | 458 | p->decay=decay; |
| 459 | p->prepIndex = prepIndex; | ||
| 457 | tFeedbackLeveler_init(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode); | 460 | tFeedbackLeveler_init(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode); |
| 458 | tFeedbackLeveler_init(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode); | 461 | tFeedbackLeveler_init(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode); |
| 459 | p->levMode=levMode; | 462 | p->levMode=levMode; |
| @@ -149,19 +149,15 @@ void tNReverb_init(tNReverb* const rev, float t60) · 148 unmodified lines | |||
| 149 | 149 | ||
| 150 | for ( i=0; i<6; i++ ) | 150 | for ( i=0; i<6; i++ ) |
| 151 | { | 151 | { |
| 152 | tDelay_init(&r->combDelays[i], lengths[i], lengths[i] * 2.0f); | 152 | tLinearDelay_init(&r->combDelays[i], lengths[i], lengths[i] * 2.0f); |
| 153 | r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60)); | 153 | r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60)); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | for ( i=0; i<8; i++ ) | 156 | for ( i=0; i<8; i++ ) |
| 157 | { | 157 | { |
| 158 | tDelay_init(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f); | 158 | tLinearDelay_init(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f); |
| 159 | } | ||
| 160 | |||
| 161 | for ( i=0; i<2; i++ ) | ||
| 162 | { | ||
| 163 | tDelay_setDelay(&r->combDelays[i], lengths[i+2]); | ||
| 164 | } | 159 | } |
| 160 | |||
| 165 | 161 | ||
| 166 | tNReverb_setT60(rev, t60); | 162 | tNReverb_setT60(rev, t60); |
| 167 | r->allpassCoeff = 0.7f; | 163 | r->allpassCoeff = 0.7f; |
| @@ -174,12 +170,12 @@ void tNReverb_free(tNReverb* const rev) · 6 unmodified lines | |||
| 174 | 170 | ||
| 175 | for (int i = 0; i < 6; i++) | 171 | for (int i = 0; i < 6; i++) |
| 176 | { | 172 | { |
| 177 | tDelay_free(&r->combDelays[i]); | 173 | tLinearDelay_free(&r->combDelays[i]); |
| 178 | } | 174 | } |
| 179 | 175 | ||
| 180 | for (int i = 0; i < 8; i++) | 176 | for (int i = 0; i < 8; i++) |
| 181 | { | 177 | { |
| 182 | tDelay_free(&r->allpassDelays[i]); | 178 | tLinearDelay_free(&r->allpassDelays[i]); |
| 183 | } | 179 | } |
| 184 | 180 | ||
| 185 | leaf_free(r); | 181 | leaf_free(r); |
| @@ -193,7 +189,7 @@ void tNReverb_setT60(tNReverb* const rev, float t60) · 7 unmodified lines | |||
| 193 | 189 | ||
| 194 | r->t60 = t60; | 190 | r->t60 = t60; |
| 195 | 191 | ||
| 196 | for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / t60 )); | 192 | for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / t60 )); |
| 197 | 193 | ||
| 198 | } | 194 | } |
| 199 | 195 | ||
| @@ -208,60 +204,114 @@ float tNReverb_tick(tNReverb* const rev, float input) · 8 unmodified lines | |||
| 208 | _tNReverb* r = *rev; | 204 | _tNReverb* r = *rev; |
| 209 | r->lastIn = input; | 205 | r->lastIn = input; |
| 210 | 206 | ||
| 211 | float temp, temp0, temp1, temp2, out; | 207 | float temp, temp0, temp1, temp2, temp3, out; |
| 212 | int i; | 208 | int i; |
| 213 | 209 | ||
| 214 | temp0 = 0.0; | 210 | temp0 = 0.0; |
| 215 | for ( i=0; i<6; i++ ) | 211 | for ( i=0; i<6; i++ ) |
| 216 | { | 212 | { |
| 217 | temp = input + (r->combCoeffs[i] * tDelay_getLastOut(&r->combDelays[i])); | 213 | temp = input + (r->combCoeffs[i] * tLinearDelay_getLastOut(&r->combDelays[i])); |
| 218 | temp0 += tDelay_tick(&r->combDelays[i],temp); | 214 | temp0 += tLinearDelay_tick(&r->combDelays[i],temp); |
| 219 | } | 215 | } |
| 220 | 216 | ||
| 221 | for ( i=0; i<3; i++ ) | 217 | for ( i=0; i<3; i++ ) |
| 222 | { | 218 | { |
| 223 | temp = tDelay_getLastOut(&r->allpassDelays[i]); | 219 | temp = tLinearDelay_getLastOut(&r->allpassDelays[i]); |
| 224 | temp1 = r->allpassCoeff * temp; | 220 | temp1 = r->allpassCoeff * temp; |
| 225 | temp1 += temp0; | 221 | temp1 += temp0; |
| 226 | tDelay_tick(&r->allpassDelays[i], temp1); | 222 | tLinearDelay_tick(&r->allpassDelays[i], temp1); |
| 227 | temp0 = -(r->allpassCoeff * temp1) + temp; | 223 | temp0 = -(r->allpassCoeff * temp1) + temp; |
| 228 | } | 224 | } |
| 229 | 225 | ||
| 230 | // One-pole lowpass filter. | 226 | // One-pole lowpass filter. |
| 231 | r->lowpassState = 0.7f * r->lowpassState + 0.3f * temp0; | 227 | r->lowpassState = 0.7f * r->lowpassState + 0.3f * temp0; |
| 232 | temp = tDelay_getLastOut(&r->allpassDelays[3]); | 228 | |
| 229 | temp = tLinearDelay_getLastOut(&r->allpassDelays[3]); | ||
| 233 | temp1 = r->allpassCoeff * temp; | 230 | temp1 = r->allpassCoeff * temp; |
| 234 | temp1 += r->lowpassState; | 231 | temp1 += r->lowpassState; |
| 235 | tDelay_tick(&r->allpassDelays[3], temp1 ); | 232 | tLinearDelay_tick(&r->allpassDelays[3], temp1 ); |
| 236 | temp1 = -(r->allpassCoeff * temp1) + temp; | 233 | temp1 = -(r->allpassCoeff * temp1) + temp; |
| 237 | 234 | ||
| 238 | temp = tDelay_getLastOut(&r->allpassDelays[4]); | 235 | temp = tLinearDelay_getLastOut(&r->allpassDelays[4]); |
| 239 | temp2 = r->allpassCoeff * temp; | 236 | temp2 = r->allpassCoeff * temp; |
| 240 | temp2 += temp1; | 237 | temp2 += temp1; |
| 241 | tDelay_tick(&r->allpassDelays[4], temp2 ); | 238 | tLinearDelay_tick(&r->allpassDelays[4], temp2 ); |
| 242 | out = r->mix * ( -( r->allpassCoeff * temp2 ) + temp ); | 239 | out = -( r->allpassCoeff * temp2 ) + temp ; |
| 243 | 240 | ||
| 244 | /* | 241 | //the other channel in stereo version below |
| 245 | temp = tLinearDelayGetLastOut(&r->allpassDelays[5]); | 242 | /* |
| 243 | temp = tLinearDelay_getLastOut(&r->allpassDelays[5]); | ||
| 246 | temp3 = r->allpassCoeff * temp; | 244 | temp3 = r->allpassCoeff * temp; |
| 247 | temp3 += temp1; | 245 | temp3 += temp1; |
| 248 | tLinearDelayTick(&r->allpassDelays[5], temp3 ); | 246 | tLinearDelay_tick(&r->allpassDelays[5], temp3 ); |
| 249 | lastFrame_[1] = effectMix_*( - ( r->allpassCoeff * temp3 ) + temp ); | 247 | out = r->mix *( - ( r->allpassCoeff * temp3 ) + temp ); |
| 250 | */ | 248 | */ |
| 251 | 249 | ||
| 252 | temp = ( 1.0f - r->mix ) * input; | 250 | temp = ( 1.0f - r->mix ) * input; |
| 253 | 251 | ||
| 254 | out += temp; | 252 | out += temp; |
| 255 | 253 | ||
| 256 | r->lastOut = out; | 254 | r->lastOut = out; |
| 257 | 255 | ||
| 258 | return out; | 256 | return out; |
| 259 | } | 257 | } |
| 260 | 258 | ||
| 259 | void tNReverb_tickStereo(tNReverb* const rev, float input, float* output) | ||
| 260 | { | ||
| 261 | _tNReverb* r = *rev; | ||
| 262 | r->lastIn = input; | ||
| 263 | |||
| 264 | float temp, temp0, temp1, temp2, temp3, out; | ||
| 265 | int i; | ||
| 266 | |||
| 267 | temp0 = 0.0; | ||
| 268 | for ( i=0; i<6; i++ ) | ||
| 269 | { | ||
| 270 | temp = input + (r->combCoeffs[i] * tLinearDelay_getLastOut(&r->combDelays[i])); | ||
| 271 | temp0 += tLinearDelay_tick(&r->combDelays[i],temp); | ||
| 272 | } | ||
| 273 | |||
| 274 | for ( i=0; i<3; i++ ) | ||
| 275 | { | ||
| 276 | temp = tLinearDelay_getLastOut(&r->allpassDelays[i]); | ||
| 277 | temp1 = r->allpassCoeff * temp; | ||
| 278 | temp1 += temp0; | ||
| 279 | tLinearDelay_tick(&r->allpassDelays[i], temp1); | ||
| 280 | temp0 = -(r->allpassCoeff * temp1) + temp; | ||
| 281 | } | ||
| 282 | |||
| 283 | // One-pole lowpass filter. | ||
| 284 | r->lowpassState = 0.7f * r->lowpassState + 0.3f * temp0; | ||
| 285 | |||
| 286 | temp = tLinearDelay_getLastOut(&r->allpassDelays[3]); | ||
| 287 | temp1 = r->allpassCoeff * temp; | ||
| 288 | temp1 += r->lowpassState; | ||
| 289 | tLinearDelay_tick(&r->allpassDelays[3], temp1 ); | ||
| 290 | temp1 = -(r->allpassCoeff * temp1) + temp; | ||
| 291 | |||
| 292 | float drymix = ( 1.0f - r->mix ) * input; | ||
| 293 | |||
| 294 | temp = tLinearDelay_getLastOut(&r->allpassDelays[4]); | ||
| 295 | temp2 = r->allpassCoeff * temp; | ||
| 296 | temp2 += temp1; | ||
| 297 | tLinearDelay_tick(&r->allpassDelays[4], temp2 ); | ||
| 298 | output[0] = -( r->allpassCoeff * temp2 ) + temp + drymix; | ||
| 299 | out = output[0]; | ||
| 300 | |||
| 301 | |||
| 302 | temp = tLinearDelay_getLastOut(&r->allpassDelays[5]); | ||
| 303 | temp3 = r->allpassCoeff * temp; | ||
| 304 | temp3 += temp1; | ||
| 305 | tLinearDelay_tick(&r->allpassDelays[5], temp3 ); | ||
| 306 | output[1] = r->mix *( - ( r->allpassCoeff * temp3 ) + temp + drymix); | ||
| 307 | |||
| 308 | r->lastOut = out; | ||
| 309 | } | ||
| 310 | |||
| 261 | void tNReverbSampleRateChanged (tNReverb* const rev) | 311 | void tNReverbSampleRateChanged (tNReverb* const rev) |
| 262 | { | 312 | { |
| 263 | _tNReverb* r = *rev; | 313 | _tNReverb* r = *rev; |
| 264 | for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 )); | 314 | for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 )); |
| 265 | } | 315 | } |
| 266 | 316 | ||
| 267 | // ======================================DATTORRO========================================= | 317 | // ======================================DATTORRO========================================= |
| @@ -279,7 +329,7 @@ void tDattorroReverb_init (tDattorroReverb* const rev) · 11 unmodified lines | |||
| 279 | r->size_max = 2.0f; | 329 | r->size_max = 2.0f; |
| 280 | r->size = 1.f; | 330 | r->size = 1.f; |
| 281 | r->t = r->size * leaf.sampleRate * 0.001f; | 331 | r->t = r->size * leaf.sampleRate * 0.001f; |
| 282 | 332 | r->frozen = 0; | |
| 283 | // INPUT | 333 | // INPUT |
| 284 | tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f)); | 334 | tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f)); |
| 285 | tOnePole_init(&r->in_filter, 1.f); | 335 | tOnePole_init(&r->in_filter, 1.f); |
| @@ -381,66 +431,74 @@ float tDattorroReverb_tick (tDattorroReverb* const rev, float inp · 95 unmodified lines | |||
| 381 | { | 431 | { |
| 382 | _tDattorroReverb* r = *rev; | 432 | _tDattorroReverb* r = *rev; |
| 383 | 433 | ||
| 384 | // INPUT | 434 | |
| 385 | float in_sample = tTapeDelay_tick(&r->in_delay, input); | 435 | float in_sample, f1_sample,f1_delay_2_sample, f2_sample, f2_delay_2_sample; |
| 386 | 436 | ||
| 387 | in_sample = tOnePole_tick(&r->in_filter, in_sample); | 437 | if (r->frozen) |
| 388 | |||
| 389 | for (int i = 0; i < 4; i++) | ||
| 390 | { | 438 | { |
| 391 | in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); | 439 | input = 0.0f; |
| 392 | } | 440 | //r->f1_last = 0.0f; |
| 393 | 441 | //r->f2_last = 0.0f; | |
| 394 | // FEEDBACK 1 | 442 | } |
| 395 | float f1_sample = in_sample + r->f2_last; // + f2_last_out; | 443 | // INPUT |
| 396 | 444 | in_sample = tTapeDelay_tick(&r->in_delay, input); | |
| 397 | tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); | 445 | |
| 398 | 446 | in_sample = tOnePole_tick(&r->in_filter, in_sample); | |
| 399 | f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); | 447 | |
| 400 | 448 | for (int i = 0; i < 4; i++) | |
| 401 | f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); | 449 | { |
| 402 | 450 | in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); | |
| 403 | f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); | 451 | } |
| 404 | 452 | ||
| 405 | f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; | 453 | // FEEDBACK 1 |
| 406 | 454 | f1_sample = in_sample + r->f2_last; // + f2_last_out; | |
| 407 | float f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); | 455 | |
| 408 | 456 | tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); | |
| 409 | r->f1_delay_2_last = f1_delay_2_sample; | 457 | |
| 410 | 458 | f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); | |
| 411 | f1_sample = r->f1_delay_2_last + f1_sample; | 459 | |
| 412 | 460 | f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); | |
| 413 | f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); | 461 | |
| 414 | 462 | f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); | |
| 415 | f1_sample *= r->feedback_gain; | 463 | |
| 416 | 464 | f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; | |
| 417 | r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); | 465 | |
| 418 | 466 | f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); | |
| 419 | // FEEDBACK 2 | 467 | |
| 420 | float f2_sample = in_sample + r->f1_last; | 468 | r->f1_delay_2_last = f1_delay_2_sample; |
| 421 | 469 | ||
| 422 | tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); | 470 | f1_sample = r->f1_delay_2_last + f1_sample; |
| 423 | 471 | ||
| 424 | f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); | 472 | f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); |
| 425 | 473 | ||
| 426 | f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); | 474 | f1_sample *= r->feedback_gain; |
| 427 | 475 | ||
| 428 | f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); | 476 | r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); |
| 429 | 477 | ||
| 430 | f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; | 478 | // FEEDBACK 2 |
| 431 | 479 | f2_sample = in_sample + r->f1_last; | |
| 432 | float f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); | 480 | |
| 433 | 481 | tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); | |
| 434 | r->f2_delay_2_last = f2_delay_2_sample; | 482 | |
| 435 | 483 | f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); | |
| 436 | f2_sample = r->f2_delay_2_last + f2_sample; | 484 | |
| 437 | 485 | f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); | |
| 438 | f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); | 486 | |
| 439 | 487 | f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); | |
| 440 | f2_sample *= r->feedback_gain; | 488 | |
| 441 | 489 | f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; | |
| 442 | r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); | 490 | |
| 443 | 491 | f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); | |
| 492 | |||
| 493 | r->f2_delay_2_last = f2_delay_2_sample; | ||
| 494 | |||
| 495 | f2_sample = r->f2_delay_2_last + f2_sample; | ||
| 496 | |||
| 497 | f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); | ||
| 498 | |||
| 499 | f2_sample *= r->feedback_gain; | ||
| 500 | |||
| 501 | r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); | ||
| 444 | 502 | ||
| 445 | // TAP OUT 1 | 503 | // TAP OUT 1 |
| 446 | f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) + | 504 | f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) + |
| @@ -482,70 +540,84 @@ float tDattorroReverb_tick (tDattorroReverb* const rev, float inp · 35 unmodified lines | |||
| 482 | void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output) | 540 | void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output) |
| 483 | { | 541 | { |
| 484 | _tDattorroReverb* r = *rev; | 542 | _tDattorroReverb* r = *rev; |
| 543 | float in_sample, f1_sample,f1_delay_2_sample, f2_sample, f2_delay_2_sample; | ||
| 485 | 544 | ||
| 486 | // INPUT | 545 | if (r->frozen) |
| 487 | float in_sample = tTapeDelay_tick(&r->in_delay, input); | ||
| 488 | |||
| 489 | in_sample = tOnePole_tick(&r->in_filter, in_sample); | ||
| 490 | |||
| 491 | for (int i = 0; i < 4; i++) | ||
| 492 | { | 546 | { |
| 493 | in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); | 547 | input = 0.0f; |
| 548 | //r->f1_last = 0.0f; | ||
| 549 | //r->f2_last = 0.0f; | ||
| 494 | } | 550 | } |
| 551 | // INPUT | ||
| 552 | in_sample = tTapeDelay_tick(&r->in_delay, input); | ||
| 495 | 553 | ||
| 496 | // FEEDBACK 1 | 554 | in_sample = tOnePole_tick(&r->in_filter, in_sample); |
| 497 | float f1_sample = in_sample + r->f2_last; // + f2_last_out; | ||
| 498 | 555 | ||
| 499 | tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); | 556 | for (int i = 0; i < 4; i++) |
| 557 | { | ||
| 558 | in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); | ||
| 559 | } | ||
| 500 | 560 | ||
| 501 | f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); | ||
| 502 | 561 | ||
| 503 | f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); | 562 | // FEEDBACK 1 |
| 563 | f1_sample = in_sample + r->f2_last; // + f2_last_out; | ||
| 504 | 564 | ||
| 505 | f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); | 565 | tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); |
| 506 | 566 | ||
| 507 | f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; | 567 | f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); |
| 508 | 568 | ||
| 509 | float f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); | 569 | f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); |
| 510 | 570 | ||
| 511 | r->f1_delay_2_last = f1_delay_2_sample; | 571 | f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); |
| 512 | 572 | ||
| 513 | f1_sample = r->f1_delay_2_last + f1_sample; | 573 | f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; |
| 514 | 574 | ||
| 515 | f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); | 575 | f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); |
| 516 | 576 | ||
| 517 | f1_sample *= r->feedback_gain; | 577 | r->f1_delay_2_last = f1_delay_2_sample; |
| 518 | 578 | ||
| 519 | f1_sample = tanhf(f1_sample); | 579 | f1_sample = r->f1_delay_2_last + f1_sample; |
| 520 | 580 | ||
| 521 | r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); | 581 | f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); |
| 522 | 582 | ||
| 523 | // FEEDBACK 2 | 583 | f1_sample *= r->feedback_gain; |
| 524 | float f2_sample = in_sample + r->f1_last; | ||
| 525 | 584 | ||
| 526 | tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); | 585 | if (r->frozen) |
| 586 | { | ||
| 587 | f1_sample = 0.0f; | ||
| 588 | } | ||
| 527 | 589 | ||
| 528 | f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); | 590 | r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); |
| 529 | 591 | ||
| 530 | f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); | 592 | // FEEDBACK 2 |
| 593 | f2_sample = in_sample + r->f1_last; | ||
| 531 | 594 | ||
| 532 | f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); | 595 | tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); |
| 533 | 596 | ||
| 534 | f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; | 597 | f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); |
| 535 | 598 | ||
| 536 | float f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); | 599 | f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); |
| 537 | 600 | ||
| 538 | r->f2_delay_2_last = f2_delay_2_sample; | 601 | f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); |
| 539 | 602 | ||
| 540 | f2_sample = r->f2_delay_2_last + f2_sample; | 603 | f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; |
| 541 | 604 | ||
| 542 | f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); | 605 | f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); |
| 543 | 606 | ||
| 544 | f2_sample *= r->feedback_gain; | 607 | r->f2_delay_2_last = f2_delay_2_sample; |
| 545 | 608 | ||
| 546 | f2_sample = tanhf(f2_sample); | 609 | f2_sample = r->f2_delay_2_last + f2_sample; |
| 610 | |||
| 611 | f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); | ||
| 612 | |||
| 613 | f2_sample *= r->feedback_gain; | ||
| 614 | |||
| 615 | if (r->frozen) | ||
| 616 | { | ||
| 617 | f2_sample = 0.0f; | ||
| 618 | } | ||
| 619 | r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); | ||
| 547 | 620 | ||
| 548 | r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); | ||
| 549 | 621 | ||
| 550 | 622 | ||
| 551 | // TAP OUT 1 | 623 | // TAP OUT 1 |
| @@ -591,6 +663,35 @@ void tDattorroReverb_setMix (tDattorroReverb* const rev, float mix · 39 unmodified lines | |||
| 591 | r->mix = LEAF_clip(0.0f, mix, 1.0f); | 663 | r->mix = LEAF_clip(0.0f, mix, 1.0f); |
| 592 | } | 664 | } |
| 593 | 665 | ||
| 666 | void tDattorroReverb_setFreeze (tDattorroReverb* const rev, uint32_t freeze) | ||
| 667 | { | ||
| 668 | _tDattorroReverb* r = *rev; | ||
| 669 | r->frozen = freeze; | ||
| 670 | if (freeze) | ||
| 671 | { | ||
| 672 | tAllpass_setGain(&r->f2_allpass, 1.0f); | ||
| 673 | tAllpass_setGain(&r->f1_allpass, 1.0f); | ||
| 674 | for (int i = 0; i < 4; i++) | ||
| 675 | { | ||
| 676 | |||
| 677 | //tAllpass_setGain(&r->in_allpass[i], 1.0f); | ||
| 678 | } | ||
| 679 | tCycle_setFreq(&r->f1_lfo, 0.0f); | ||
| 680 | tCycle_setFreq(&r->f2_lfo, 0.0f); | ||
| 681 | } | ||
| 682 | else | ||
| 683 | { | ||
| 684 | tAllpass_setGain(&r->f2_allpass, 0.7f); | ||
| 685 | tAllpass_setGain(&r->f1_allpass, 0.7f); | ||
| 686 | for (int i = 0; i < 4; i++) | ||
| 687 | { | ||
| 688 | //tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]); | ||
| 689 | } | ||
| 690 | tCycle_setFreq(&r->f1_lfo, 0.1f); | ||
| 691 | tCycle_setFreq(&r->f2_lfo, 0.07f); | ||
| 692 | } | ||
| 693 | } | ||
| 694 | |||
| 594 | 695 | ||
| 595 | void tDattorroReverb_setHP (tDattorroReverb* const rev, float freq) | 696 | void tDattorroReverb_setHP (tDattorroReverb* const rev, float freq) |
| 596 | { | 697 | { |
| @@ -30,7 +30,8 @@ void tBuffer_init (tBuffer* const sb, uint32_t length) · 29 unmodified lines | |||
| 30 | 30 | ||
| 31 | s->buff = (float*) leaf_alloc( sizeof(float) * length); | 31 | s->buff = (float*) leaf_alloc( sizeof(float) * length); |
| 32 | 32 | ||
| 33 | s->length = length; | 33 | s->bufferLength = length; |
| 34 | s->recordedLength = 0; | ||
| 34 | s->active = 0; | 35 | s->active = 0; |
| 35 | s->idx = 0; | 36 | s->idx = 0; |
| 36 | s->mode = RecordOneShot; | 37 | s->mode = RecordOneShot; |
| @@ -44,8 +45,8 @@ void tBuffer_init_locate (tBuffer* const sb, uint32_t length, mpool_t* pool) · 7 unmodified lines | |||
| 44 | 45 | ||
| 45 | s->buff = (float*) mpool_alloc( sizeof(float) * length, pool); | 46 | s->buff = (float*) mpool_alloc( sizeof(float) * length, pool); |
| 46 | 47 | ||
| 47 | s->length = length; | 48 | s->bufferLength = length; |
| 48 | s->active = 0; | 49 | s->recordedLength = 0; |
| 49 | s->idx = 0; | 50 | s->idx = 0; |
| 50 | s->mode = RecordOneShot; | 51 | s->mode = RecordOneShot; |
| 51 | 52 | ||
| @@ -79,7 +80,7 @@ void tBuffer_tick (tBuffer* const sb, float sample) · 27 unmodified lines | |||
| 79 | 80 | ||
| 80 | s->idx += 1; | 81 | s->idx += 1; |
| 81 | 82 | ||
| 82 | if (s->idx >= s->length) | 83 | if (s->idx >= s->bufferLength) |
| 83 | { | 84 | { |
| 84 | if (s->mode == RecordOneShot) | 85 | if (s->mode == RecordOneShot) |
| 85 | { | 86 | { |
| @@ -96,17 +97,18 @@ void tBuffer_tick (tBuffer* const sb, float sample) · 10 unmodified lines | |||
| 96 | void tBuffer_read(tBuffer* const sb, float* buff, uint32_t len) | 97 | void tBuffer_read(tBuffer* const sb, float* buff, uint32_t len) |
| 97 | { | 98 | { |
| 98 | _tBuffer* s = *sb; | 99 | _tBuffer* s = *sb; |
| 99 | for (int i = 0; i < s->length; i++) | 100 | for (int i = 0; i < s->bufferLength; i++) |
| 100 | { | 101 | { |
| 101 | if (i < len) s->buff[i] = buff[i]; | 102 | if (i < len) s->buff[i] = buff[i]; |
| 102 | else s->buff[i] = 0.f; | 103 | else s->buff[i] = 0.f; |
| 103 | } | 104 | } |
| 105 | s->recordedLength = len; | ||
| 104 | } | 106 | } |
| 105 | 107 | ||
| 106 | float tBuffer_get (tBuffer* const sb, int idx) | 108 | float tBuffer_get (tBuffer* const sb, int idx) |
| 107 | { | 109 | { |
| 108 | _tBuffer* s = *sb; | 110 | _tBuffer* s = *sb; |
| 109 | if ((idx < 0) || (idx >= s->length)) return 0.f; | 111 | if ((idx < 0) || (idx >= s->bufferLength)) return 0.f; |
| 110 | return s->buff[idx]; | 112 | return s->buff[idx]; |
| 111 | } | 113 | } |
| 112 | 114 | ||
| @@ -121,6 +123,7 @@ void tBuffer_stop(tBuffer* const sb) · 8 unmodified lines | |||
| 121 | { | 123 | { |
| 122 | _tBuffer* s = *sb; | 124 | _tBuffer* s = *sb; |
| 123 | s->active = 0; | 125 | s->active = 0; |
| 126 | s->recordedLength = s->idx; | ||
| 124 | } | 127 | } |
| 125 | 128 | ||
| 126 | int tBuffer_getRecordPosition(tBuffer* const sb) | 129 | int tBuffer_getRecordPosition(tBuffer* const sb) |
| @@ -138,16 +141,22 @@ void tBuffer_setRecordMode (tBuffer* const sb, RecordMode mode) · 11 unmodified lines | |||
| 138 | void tBuffer_clear (tBuffer* const sb) | 141 | void tBuffer_clear (tBuffer* const sb) |
| 139 | { | 142 | { |
| 140 | _tBuffer* s = *sb; | 143 | _tBuffer* s = *sb; |
| 141 | for (int i = 0; i < s->length; i++) | 144 | for (int i = 0; i < s->bufferLength; i++) |
| 142 | { | 145 | { |
| 143 | s->buff[i] = 0.f; | 146 | s->buff[i] = 0.f; |
| 144 | } | 147 | } |
| 145 | } | 148 | } |
| 146 | 149 | ||
| 147 | uint32_t tBuffer_getLength(tBuffer* const sb) | 150 | uint32_t tBuffer_getBufferLength(tBuffer* const sb) |
| 148 | { | 151 | { |
| 149 | _tBuffer* s = *sb; | 152 | _tBuffer* s = *sb; |
| 150 | return s->length; | 153 | return s->bufferLength; |
| 154 | } | ||
| 155 | |||
| 156 | uint32_t tBuffer_getRecordedLength(tBuffer* const sb) | ||
| 157 | { | ||
| 158 | _tBuffer* s = *sb; | ||
| 159 | return s->recordedLength; | ||
| 151 | } | 160 | } |
| 152 | 161 | ||
| 153 | //================================tSampler===================================== | 162 | //================================tSampler===================================== |
| @@ -156,8 +165,6 @@ static void handleStartEndChange(tSampler* const sp); · 2 unmodified lines | |||
| 156 | 165 | ||
| 157 | static void attemptStartEndChange(tSampler* const sp); | 166 | static void attemptStartEndChange(tSampler* const sp); |
| 158 | 167 | ||
| 159 | static void updateStartEnd(tSampler* const sp); | ||
| 160 | |||
| 161 | void tSampler_init(tSampler* const sp, tBuffer* const b) | 168 | void tSampler_init(tSampler* const sp, tBuffer* const b) |
| 162 | { | 169 | { |
| 163 | _tSampler* p = *sp = (_tSampler*) leaf_alloc(sizeof(_tSampler)); | 170 | _tSampler* p = *sp = (_tSampler*) leaf_alloc(sizeof(_tSampler)); |
| @@ -168,7 +175,7 @@ void tSampler_init(tSampler* const sp, tBuffer* const b) · 4 unmodified lines | |||
| 168 | p->active = 0; | 175 | p->active = 0; |
| 169 | 176 | ||
| 170 | p->start = 0; | 177 | p->start = 0; |
| 171 | p->end = p->samp->length - 1; | 178 | p->end = p->samp->bufferLength - 1; |
| 172 | 179 | ||
| 173 | p->len = p->end - p->start; | 180 | p->len = p->end - p->start; |
| 174 | 181 | ||
| @@ -205,8 +212,17 @@ void tSampler_setSample (tSampler* const sp, tBuffer* const b) · 30 unmodified lines | |||
| 205 | _tBuffer* s = *b; | 212 | _tBuffer* s = *b; |
| 206 | 213 | ||
| 207 | p->samp = s; | 214 | p->samp = s; |
| 215 | |||
| 216 | p->start = 0; | ||
| 217 | p->end = p->samp->bufferLength - 1; | ||
| 218 | |||
| 219 | p->len = p->end - p->start; | ||
| 220 | |||
| 221 | p->idx = 0.f; | ||
| 208 | } | 222 | } |
| 209 | 223 | ||
| 224 | volatile uint32_t errorState = 0; | ||
| 225 | |||
| 210 | float tSampler_tick (tSampler* const sp) | 226 | float tSampler_tick (tSampler* const sp) |
| 211 | { | 227 | { |
| 212 | _tSampler* p = *sp; | 228 | _tSampler* p = *sp; |
| @@ -227,46 +243,22 @@ float tSampler_tick (tSampler* const sp) · 14 unmodified lines | |||
| 227 | 243 | ||
| 228 | float* buff = p->samp->buff; | 244 | float* buff = p->samp->buff; |
| 229 | 245 | ||
| 230 | int dir = p->bnf * p->dir * p->flip; | ||
| 231 | 246 | ||
| 247 | |||
| 232 | int idx, revidx; | 248 | int idx, revidx; |
| 233 | float alpha, revalpha; | 249 | float alpha, revalpha; |
| 234 | 250 | ||
| 235 | int32_t start = p->start, end = p->end; | 251 | int32_t start = p->start; |
| 252 | int32_t end = p->end; | ||
| 236 | if (p->flip < 0) | 253 | if (p->flip < 0) |
| 237 | { | 254 | { |
| 238 | start = p->end; | 255 | start = p->end; |
| 239 | end = p->start; | 256 | end = p->start; |
| 240 | } | 257 | } |
| 241 | if (p->mode == PlayLoop) | ||
| 242 | { | ||
| 243 | 258 | ||
| 244 | while((int)p->idx < start) | ||
| 245 | { | ||
| 246 | p->idx += (float)(p->len); | ||
| 247 | } | ||
| 248 | while((int)p->idx > end) | ||
| 249 | { | ||
| 250 | |||
| 251 | p->idx -= (float)(p->len); | ||
| 252 | } | ||
| 253 | } | ||
| 254 | else // == PlayBackAndForth | ||
| 255 | { | ||
| 256 | if (p->idx < start) | ||
| 257 | { | ||
| 258 | p->bnf = -p->bnf; | ||
| 259 | p->idx = start; | ||
| 260 | } | ||
| 261 | else if (p->idx > end) | ||
| 262 | { | ||
| 263 | p->bnf = -p->bnf; | ||
| 264 | p->idx = end; | ||
| 265 | } | ||
| 266 | } | ||
| 267 | 259 | ||
| 268 | 260 | ||
| 269 | 261 | int dir = p->bnf * p->dir * p->flip; | |
| 270 | idx = (int) p->idx; | 262 | idx = (int) p->idx; |
| 271 | alpha = p->idx - idx; | 263 | alpha = p->idx - idx; |
| 272 | 264 | ||
| @@ -280,7 +272,7 @@ float tSampler_tick (tSampler* const sp) · 7 unmodified lines | |||
| 280 | uint32_t cfxlen = p->cfxlen; | 272 | uint32_t cfxlen = p->cfxlen; |
| 281 | if (p->len < cfxlen) cfxlen = p->len * 0.25f;//p->len; | 273 | if (p->len < cfxlen) cfxlen = p->len * 0.25f;//p->len; |
| 282 | 274 | ||
| 283 | int length = p->samp->length; | 275 | int length = p->samp->recordedLength; |
| 284 | 276 | ||
| 285 | if (dir > 0) | 277 | if (dir > 0) |
| 286 | { // num samples (hopping the increment size) to end of loop | 278 | { // num samples (hopping the increment size) to end of loop |
| @@ -291,24 +283,22 @@ float tSampler_tick (tSampler* const sp) · 4 unmodified lines | |||
| 291 | numticks = (revidx-start) * p->iinc; | 283 | numticks = (revidx-start) * p->iinc; |
| 292 | } | 284 | } |
| 293 | 285 | ||
| 294 | 286 | // Check dir (direction) to interpolate properly | |
| 295 | 287 | if (dir > 0) | |
| 296 | if (cfxlen > 0) // necessary to avoid divide by zero, also a waste of computation otherwise | ||
| 297 | { | 288 | { |
| 298 | 289 | // FORWARD NORMAL SAMPLE | |
| 299 | // Check dir (direction) to interpolate properly | 290 | int i1 = ((idx-1) < 0) ? 0 : idx-1; |
| 300 | if (dir > 0) | 291 | int i3 = ((idx+1) >= length) ? (idx) : (idx+1); |
| 292 | int i4 = ((idx+2) >= length) ? (length-1) : (idx+2); | ||
| 293 | |||
| 294 | sample = LEAF_interpolate_hermite_x (buff[i1], | ||
| 295 | buff[idx], | ||
| 296 | buff[i3], | ||
| 297 | buff[i4], | ||
| 298 | alpha); | ||
| 299 | |||
| 300 | if (cfxlen > 0)// necessary to avoid divide by zero, also a waste of computation otherwise | ||
| 301 | { | 301 | { |
| 302 | // FORWARD NORMAL SAMPLE | ||
| 303 | int i1 = ((idx-1) < 0) ? 0 : idx-1; | ||
| 304 | int i3 = ((idx+1) >= length) ? (idx) : (idx+1); | ||
| 305 | int i4 = ((idx+2) >= length) ? (length-1) : (idx+2); | ||
| 306 | |||
| 307 | sample = LEAF_interpolate_hermite (buff[i1], | ||
| 308 | buff[idx], | ||
| 309 | buff[i3], | ||
| 310 | buff[i4], | ||
| 311 | alpha); | ||
| 312 | 302 | ||
| 313 | if (p->mode == PlayLoop) | 303 | if (p->mode == PlayLoop) |
| 314 | { | 304 | { |
| @@ -351,32 +341,43 @@ float tSampler_tick (tSampler* const sp) · 36 unmodified lines | |||
| 351 | } | 341 | } |
| 352 | 342 | ||
| 353 | } | 343 | } |
| 354 | |||
| 355 | } | 344 | } |
| 356 | else | 345 | else |
| 357 | { | 346 | { |
| 358 | // REVERSE | 347 | g2 = 0.0f; |
| 359 | int i1 = ((revidx+1) >= length) ? (length-1) : revidx+1; | 348 | } |
| 360 | int i3 = ((revidx-1) < 0) ? revidx : (revidx-1); | ||
| 361 | int i4 = ((revidx-2) < 0) ? 0 : (revidx-2); | ||
| 362 | 349 | ||
| 363 | sample = LEAF_interpolate_hermite_x (buff[i1], | 350 | } |
| 364 | buff[revidx], | 351 | else |
| 365 | buff[i3], | 352 | { |
| 366 | buff[i4], | 353 | // REVERSE |
| 367 | revalpha); | 354 | int i1 = ((revidx+1) >= length) ? (length-1) : revidx+1; |
| 355 | int i3 = ((revidx-1) < 0) ? revidx : (revidx-1); | ||
| 356 | int i4 = ((revidx-2) < 0) ? 0 : (revidx-2); | ||
| 368 | 357 | ||
| 358 | sample = LEAF_interpolate_hermite_x (buff[i1], | ||
| 359 | buff[revidx], | ||
| 360 | buff[i3], | ||
| 361 | buff[i4], | ||
| 362 | revalpha); | ||
| 369 | 363 | ||
| 370 | 364 | ||
| 371 | 365 | ||
| 366 | if (cfxlen > 0)// necessary to avoid divide by zero, also a waste of computation otherwise | ||
| 367 | { | ||
| 368 | |||
| 372 | if (p->mode == PlayLoop) | 369 | if (p->mode == PlayLoop) |
| 373 | { | 370 | { |
| 374 | if (numticks <= (float) cfxlen) | 371 | if (numticks <= (float) cfxlen) |
| 375 | { | 372 | { |
| 376 | // CROSSFADE SAMPLE | 373 | // CROSSFADE SAMPLE |
| 377 | int cdx = end + (numticks * p->inc); | 374 | int cdx = end + (numticks * p->inc); |
| 378 | if (cdx > p->samp->length - 2) | 375 | if (cdx > length - 2) |
| 379 | { | 376 | { |
| 377 | |||
| 378 | //the problem with the click is here --- at some point it crosses this threshold and jumps from a point near the boundary to a point far away from the boundary - that's not correct | ||
| 379 | ///// ooooops | ||
| 380 | |||
| 380 | cdx = end - (numticks * p->inc); | 381 | cdx = end - (numticks * p->inc); |
| 381 | 382 | ||
| 382 | i1 = ((cdx-1) < 0) ? 0 : cdx-1; | 383 | i1 = ((cdx-1) < 0) ? 0 : cdx-1; |
| @@ -403,22 +404,51 @@ float tSampler_tick (tSampler* const sp) · 20 unmodified lines | |||
| 403 | } | 404 | } |
| 404 | g2 = (float) (cfxlen - numticks) / (float) cfxlen; | 405 | g2 = (float) (cfxlen - numticks) / (float) cfxlen; |
| 405 | } | 406 | } |
| 407 | |||
| 406 | } | 408 | } |
| 407 | } | 409 | } |
| 410 | else | ||
| 411 | { | ||
| 412 | g2 = 0.0f; | ||
| 413 | } | ||
| 414 | |||
| 408 | } | 415 | } |
| 409 | else | 416 | |
| 410 | { | 417 | |
| 411 | g2 = 0.0f; | ||
| 412 | } | ||
| 413 | |||
| 414 | 418 | ||
| 415 | float inc = fmod(p->inc, p->len); | 419 | float inc = fmod(p->inc, p->len); |
| 416 | p->idx += (dir * inc); | 420 | p->idx += (dir * inc); |
| 417 | 421 | ||
| 422 | //handle start and end cases for looping and back and forth modes | ||
| 423 | if (p->mode == PlayLoop) | ||
| 424 | { | ||
| 418 | 425 | ||
| 426 | while((int)p->idx < start) | ||
| 427 | { | ||
| 428 | p->idx += (float)(p->len); | ||
| 429 | } | ||
| 430 | while((int)p->idx > end) | ||
| 431 | { | ||
| 432 | |||
| 433 | p->idx -= (float)(p->len); | ||
| 434 | } | ||
| 435 | } | ||
| 436 | else // == PlayBackAndForth | ||
| 437 | { | ||
| 438 | if (p->idx < start) | ||
| 439 | { | ||
| 440 | p->bnf = -p->bnf; | ||
| 441 | p->idx = start + 1; | ||
| 442 | } | ||
| 443 | else if (p->idx > end) | ||
| 444 | { | ||
| 445 | p->bnf = -p->bnf; | ||
| 446 | p->idx = end - 1; | ||
| 447 | } | ||
| 448 | } | ||
| 419 | 449 | ||
| 420 | // attemptStartEndChange(sp); | ||
| 421 | 450 | ||
| 451 | //handle very short fade out for end of one-shot normal playback | ||
| 422 | if (p->mode == PlayNormal) | 452 | if (p->mode == PlayNormal) |
| 423 | { | 453 | { |
| 424 | if (numticks < (0.007f * leaf.sampleRate)) | 454 | if (numticks < (0.007f * leaf.sampleRate)) |
| @@ -463,11 +493,14 @@ float tSampler_tick (tSampler* const sp) · 38 unmodified lines | |||
| 463 | } | 493 | } |
| 464 | } | 494 | } |
| 465 | 495 | ||
| 496 | if (fabsf(sample-p->last) > 0.1f) | ||
| 497 | { | ||
| 498 | errorState = 1; | ||
| 499 | } | ||
| 466 | 500 | ||
| 467 | p->last = sample; | 501 | p->last = sample; |
| 468 | 502 | ||
| 469 | 503 | ||
| 470 | |||
| 471 | return p->last; | 504 | return p->last; |
| 472 | } | 505 | } |
| 473 | 506 | ||
| @@ -532,11 +565,11 @@ void tSampler_stop (tSampler* const sp) · 58 unmodified lines | |||
| 532 | static void handleStartEndChange(tSampler* const sp) | 565 | static void handleStartEndChange(tSampler* const sp) |
| 533 | { | 566 | { |
| 534 | _tSampler* p = *sp; | 567 | _tSampler* p = *sp; |
| 535 | 568 | ||
| 536 | p->len = abs(p->end - p->start); | 569 | p->len = abs(p->end - p->start); |
| 537 | 570 | ||
| 538 | if (p->len < (p->cfxlen * 0.25f)) p->cfxlen = p->len * 0.25f; | 571 | if (p->len < (p->cfxlen * 0.25f)) p->cfxlen = p->len * 0.25f; |
| 539 | 572 | ||
| 540 | if (p->start > p->end) | 573 | if (p->start > p->end) |
| 541 | { | 574 | { |
| 542 | p->flip = -1; | 575 | p->flip = -1; |
| @@ -562,32 +595,6 @@ static void attemptStartEndChange(tSampler* const sp) · 19 unmodified lines | |||
| 562 | } | 595 | } |
| 563 | } | 596 | } |
| 564 | 597 | ||
| 565 | static void updateStartEnd(tSampler* const sp) | ||
| 566 | { | ||
| 567 | _tSampler* p = *sp; | ||
| 568 | |||
| 569 | |||
| 570 | |||
| 571 | if (p->targetstart >= 0) | ||
| 572 | { | ||
| 573 | if (p->targetstart != p->end) | ||
| 574 | { | ||
| 575 | p->start = p->targetstart; | ||
| 576 | handleStartEndChange(sp); | ||
| 577 | p->targetstart = -1; | ||
| 578 | } | ||
| 579 | } | ||
| 580 | if (p->targetend >= 0) | ||
| 581 | { | ||
| 582 | if (p->targetend != p->start) | ||
| 583 | { | ||
| 584 | p->end = p->targetend; | ||
| 585 | handleStartEndChange(sp); | ||
| 586 | p->targetend = -1; | ||
| 587 | } | ||
| 588 | } | ||
| 589 | } | ||
| 590 | |||
| 591 | void tSampler_setStart (tSampler* const sp, int32_t start) | 598 | void tSampler_setStart (tSampler* const sp, int32_t start) |
| 592 | { | 599 | { |
| 593 | _tSampler* p = *sp; | 600 | _tSampler* p = *sp; |
| @@ -611,7 +618,7 @@ void tSampler_setStart (tSampler* const sp, int32_t start) · 17 unmodified lines | |||
| 611 | 618 | ||
| 612 | int dir = p->bnf * p->dir * tempflip; | 619 | int dir = p->bnf * p->dir * tempflip; |
| 613 | uint32_t cfxlen = (p->len < p->cfxlen) ? 0 : p->cfxlen; | 620 | uint32_t cfxlen = (p->len < p->cfxlen) ? 0 : p->cfxlen; |
| 614 | if (tempflip > 0 && dir > 0) // start is start and we're playing forward | 621 | if ((tempflip > 0) && (dir > 0)) // start is start and we're playing forward |
| 615 | { | 622 | { |
| 616 | if (((start > p->idx) || (p->end-p->idx <= cfxlen)) && (start > p->end))// start given is after current index or we're in a crossfade | 623 | if (((start > p->idx) || (p->end-p->idx <= cfxlen)) && (start > p->end))// start given is after current index or we're in a crossfade |
| 617 | { | 624 | { |
| @@ -619,7 +626,7 @@ void tSampler_setStart (tSampler* const sp, int32_t start) · 1 unmodified line | |||
| 619 | return; | 626 | return; |
| 620 | } | 627 | } |
| 621 | } | 628 | } |
| 622 | else if (tempflip < 0 && dir < 0) // start is end and we're playing in reverse | 629 | else if ((tempflip < 0) && (dir < 0)) // start is end and we're playing in reverse |
| 623 | { | 630 | { |
| 624 | if (((start < p->idx) || (p->idx-p->end <= cfxlen)) && (start < p->end))// start given is before current index or we're in a crossfade | 631 | if (((start < p->idx) || (p->idx-p->end <= cfxlen)) && (start < p->end))// start given is before current index or we're in a crossfade |
| 625 | { | 632 | { |
| @@ -629,7 +636,7 @@ void tSampler_setStart (tSampler* const sp, int32_t start) · 3 unmodified lines | |||
| 629 | } | 636 | } |
| 630 | } | 637 | } |
| 631 | 638 | ||
| 632 | p->start = LEAF_clipInt(0, start, p->samp->length - 1); | 639 | p->start = LEAF_clipInt(0, start, p->samp->recordedLength - 1); |
| 633 | handleStartEndChange(sp); | 640 | handleStartEndChange(sp); |
| 634 | p->targetstart = -1; | 641 | p->targetstart = -1; |
| 635 | 642 | ||
| @@ -676,7 +683,7 @@ void tSampler_setEnd (tSampler* const sp, int32_t end) · 40 unmodified lines | |||
| 676 | } | 683 | } |
| 677 | } | 684 | } |
| 678 | } | 685 | } |
| 679 | p->end = LEAF_clipInt(0, end, (p->samp->length - 1)); | 686 | p->end = LEAF_clipInt(0, end, (p->samp->recordedLength - 1)); |
| 680 | handleStartEndChange(sp); | 687 | handleStartEndChange(sp); |
| 681 | p->targetend = -1; | 688 | p->targetend = -1; |
| 682 | } | 689 | } |
| @@ -21,6 +21,7 @@ · 20 unmodified lines | |||
| 21 | LEAF leaf; | 21 | LEAF leaf; |
| 22 | 22 | ||
| 23 | void LEAF_init(float sr, int blocksize, char* memory, size_t memorysize, float(*random)(void)) | 23 | void LEAF_init(float sr, int blocksize, char* memory, size_t memorysize, float(*random)(void)) |
| 24 | |||
| 24 | { | 25 | { |
| 25 | leaf_pool_init(memory, memorysize); | 26 | leaf_pool_init(memory, memorysize); |
| 26 | 27 | ||