Unified · Split
Binary file not shown.
Binary file not shown.
| @@ -150,6 +150,7 @@ extern "C" { · 149 unmodified lines | ||
| 150 | 150 | float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay); |
| 151 | 151 | float tTapeDelay_addTo (tTapeDelay* const, float value, uint32_t tapDelay); |
| 152 | 152 | float tTapeDelay_tick (tTapeDelay* const, float sample); |
| 153 | + void tTapeDelay_incrementInPoint(tTapeDelay* const dl); | |
| 153 | 154 | float tTapeDelay_getLastOut (tTapeDelay* const); |
| 154 | 155 | float tTapeDelay_getLastIn (tTapeDelay* const); |
| 155 | 156 | |
| @@ -61,8 +61,8 @@ extern "C" { · 60 unmodified lines | ||
| 61 | 61 | |
| 62 | 62 | float inv_sr, inv_441; |
| 63 | 63 | |
| 64 | − tDelay allpassDelays[8]; | |
| 65 | − tDelay combDelays[6]; | |
| 64 | + tLinearDelay allpassDelays[8]; | |
| 65 | + tLinearDelay combDelays[6]; | |
| 66 | 66 | float allpassCoeff; |
| 67 | 67 | float combCoeffs[6]; |
| 68 | 68 | float lowpassState; |
| @@ -77,6 +77,7 @@ extern "C" { · 8 unmodified lines | ||
| 77 | 77 | void tNReverb_free (tNReverb* const); |
| 78 | 78 | |
| 79 | 79 | float tNReverb_tick (tNReverb* const, float input); |
| 80 | + void tNReverb_tickStereo(tNReverb* const rev, float input, float* output); | |
| 80 | 81 | |
| 81 | 82 | // Set reverb time in seconds. |
| 82 | 83 | void tNReverb_setT60 (tNReverb* const, float t60); |
| @@ -93,7 +94,7 @@ extern "C" { · 10 unmodified lines | ||
| 93 | 94 | float feedback_filter; |
| 94 | 95 | float feedback_gain; |
| 95 | 96 | float mix; |
| 96 | − | |
| 97 | + uint32_t frozen; | |
| 97 | 98 | |
| 98 | 99 | float size, size_max, t; |
| 99 | 100 | |
| @@ -138,6 +139,7 @@ extern "C" { · 38 unmodified lines | ||
| 138 | 139 | float tDattorroReverb_tick (tDattorroReverb* const, float input); |
| 139 | 140 | void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output); |
| 140 | 141 | void tDattorroReverb_setMix (tDattorroReverb* const, float mix); |
| 142 | + void tDattorroReverb_setFreeze (tDattorroReverb* const rev, uint32_t freeze); | |
| 141 | 143 | void tDattorroReverb_setHP (tDattorroReverb* const, float freq); |
| 142 | 144 | void tDattorroReverb_setSize (tDattorroReverb* const, float size); |
| 143 | 145 | void tDattorroReverb_setInputDelay (tDattorroReverb* const, float preDelay); |
| @@ -35,8 +35,8 @@ extern "C" { · 34 unmodified lines | ||
| 35 | 35 | float* buff; |
| 36 | 36 | |
| 37 | 37 | uint32_t idx; |
| 38 | − uint32_t length; | |
| 39 | − | |
| 38 | + uint32_t bufferLength; | |
| 39 | + uint32_t recordedLength; | |
| 40 | 40 | RecordMode mode; |
| 41 | 41 | |
| 42 | 42 | int active; |
| @@ -64,7 +64,8 @@ extern "C" { · 21 unmodified lines | ||
| 64 | 64 | |
| 65 | 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 | 94 | int32_t start, targetstart; |
| 94 | 95 | int32_t end, targetend; |
| 96 | + | |
| 95 | 97 | uint32_t len; |
| 96 | 98 | uint32_t cfxlen; |
| 97 | 99 | float numticks; |
| @@ -118,7 +120,7 @@ extern "C" { · 20 unmodified lines | ||
| 118 | 120 | |
| 119 | 121 | void tSampler_setStart (tSampler* const, int32_t start); |
| 120 | 122 | void tSampler_setEnd (tSampler* const, int32_t end); |
| 121 | − | |
| 123 | + | |
| 122 | 124 | static void handleStartEndChange(tSampler* const sp); |
| 123 | 125 | |
| 124 | 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 | 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 | 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 | 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 | 82 | void leaf_pool_init(char* memory, size_t size) |
| 78 | 83 | { |
| 79 | 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 | 440 | p->curr=0.0f; |
| 441 | 441 | tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions) |
| 442 | 442 | tLivingString_setFreq(pl, freq); |
| 443 | + p->freq = freq; | |
| 443 | 444 | tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position |
| 444 | 445 | tLivingString_setPickPos(pl, pickPos); |
| 445 | 446 | p->prepIndex=prepIndex; |
| @@ -447,6 +448,7 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 1 unmodified line | ||
| 447 | 448 | tLinearDelay_init(&p->delUF,p->waveLengthInSamples, 2400); |
| 448 | 449 | tLinearDelay_init(&p->delUB,p->waveLengthInSamples, 2400); |
| 449 | 450 | tLinearDelay_init(&p->delLB,p->waveLengthInSamples, 2400); |
| 451 | + p->dampFreq = dampFreq; | |
| 450 | 452 | tOnePole_init(&p->bridgeFilter, dampFreq); |
| 451 | 453 | tOnePole_init(&p->nutFilter, dampFreq); |
| 452 | 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 | 456 | tHighpass_init(&p->DCblockerU,13); |
| 455 | 457 | tHighpass_init(&p->DCblockerL,13); |
| 456 | 458 | p->decay=decay; |
| 459 | + p->prepIndex = prepIndex; | |
| 457 | 460 | tFeedbackLeveler_init(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode); |
| 458 | 461 | tFeedbackLeveler_init(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode); |
| 459 | 462 | p->levMode=levMode; |
| @@ -149,19 +149,15 @@ void tNReverb_init(tNReverb* const rev, float t60) · 148 unmodified lines | ||
| 149 | 149 | |
| 150 | 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 | 153 | r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60)); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | for ( i=0; i<8; i++ ) |
| 157 | 157 | { |
| 158 | − tDelay_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]); | |
| 158 | + tLinearDelay_init(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f); | |
| 164 | 159 | } |
| 160 | + | |
| 165 | 161 | |
| 166 | 162 | tNReverb_setT60(rev, t60); |
| 167 | 163 | r->allpassCoeff = 0.7f; |
| @@ -174,12 +170,12 @@ void tNReverb_free(tNReverb* const rev) · 6 unmodified lines | ||
| 174 | 170 | |
| 175 | 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 | 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 | 181 | leaf_free(r); |
| @@ -193,7 +189,7 @@ void tNReverb_setT60(tNReverb* const rev, float t60) · 7 unmodified lines | ||
| 193 | 189 | |
| 194 | 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 | 204 | _tNReverb* r = *rev; |
| 209 | 205 | r->lastIn = input; |
| 210 | 206 | |
| 211 | − float temp, temp0, temp1, temp2, out; | |
| 207 | + float temp, temp0, temp1, temp2, temp3, out; | |
| 212 | 208 | int i; |
| 213 | 209 | |
| 214 | 210 | temp0 = 0.0; |
| 215 | 211 | for ( i=0; i<6; i++ ) |
| 216 | 212 | { |
| 217 | − temp = input + (r->combCoeffs[i] * tDelay_getLastOut(&r->combDelays[i])); | |
| 218 | − temp0 += tDelay_tick(&r->combDelays[i],temp); | |
| 213 | + temp = input + (r->combCoeffs[i] * tLinearDelay_getLastOut(&r->combDelays[i])); | |
| 214 | + temp0 += tLinearDelay_tick(&r->combDelays[i],temp); | |
| 219 | 215 | } |
| 220 | 216 | |
| 221 | 217 | for ( i=0; i<3; i++ ) |
| 222 | 218 | { |
| 223 | − temp = tDelay_getLastOut(&r->allpassDelays[i]); | |
| 219 | + temp = tLinearDelay_getLastOut(&r->allpassDelays[i]); | |
| 224 | 220 | temp1 = r->allpassCoeff * temp; |
| 225 | 221 | temp1 += temp0; |
| 226 | − tDelay_tick(&r->allpassDelays[i], temp1); | |
| 222 | + tLinearDelay_tick(&r->allpassDelays[i], temp1); | |
| 227 | 223 | temp0 = -(r->allpassCoeff * temp1) + temp; |
| 228 | 224 | } |
| 229 | 225 | |
| 230 | 226 | // One-pole lowpass filter. |
| 231 | 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 | 230 | temp1 = r->allpassCoeff * temp; |
| 234 | 231 | temp1 += r->lowpassState; |
| 235 | − tDelay_tick(&r->allpassDelays[3], temp1 ); | |
| 232 | + tLinearDelay_tick(&r->allpassDelays[3], temp1 ); | |
| 236 | 233 | temp1 = -(r->allpassCoeff * temp1) + temp; |
| 237 | 234 | |
| 238 | − temp = tDelay_getLastOut(&r->allpassDelays[4]); | |
| 235 | + temp = tLinearDelay_getLastOut(&r->allpassDelays[4]); | |
| 239 | 236 | temp2 = r->allpassCoeff * temp; |
| 240 | 237 | temp2 += temp1; |
| 241 | − tDelay_tick(&r->allpassDelays[4], temp2 ); | |
| 242 | − out = r->mix * ( -( r->allpassCoeff * temp2 ) + temp ); | |
| 238 | + tLinearDelay_tick(&r->allpassDelays[4], temp2 ); | |
| 239 | + out = -( r->allpassCoeff * temp2 ) + temp ; | |
| 243 | 240 | |
| 244 | − /* | |
| 245 | − temp = tLinearDelayGetLastOut(&r->allpassDelays[5]); | |
| 241 | + //the other channel in stereo version below | |
| 242 | +/* | |
| 243 | + temp = tLinearDelay_getLastOut(&r->allpassDelays[5]); | |
| 246 | 244 | temp3 = r->allpassCoeff * temp; |
| 247 | 245 | temp3 += temp1; |
| 248 | − tLinearDelayTick(&r->allpassDelays[5], temp3 ); | |
| 249 | − lastFrame_[1] = effectMix_*( - ( r->allpassCoeff * temp3 ) + temp ); | |
| 250 | − */ | |
| 251 | − | |
| 246 | + tLinearDelay_tick(&r->allpassDelays[5], temp3 ); | |
| 247 | + out = r->mix *( - ( r->allpassCoeff * temp3 ) + temp ); | |
| 248 | +*/ | |
| 249 | + | |
| 252 | 250 | temp = ( 1.0f - r->mix ) * input; |
| 253 | − | |
| 251 | + | |
| 254 | 252 | out += temp; |
| 255 | − | |
| 253 | + | |
| 256 | 254 | r->lastOut = out; |
| 257 | − | |
| 255 | + | |
| 258 | 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 | 311 | void tNReverbSampleRateChanged (tNReverb* const rev) |
| 262 | 312 | { |
| 263 | 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 | 317 | // ======================================DATTORRO========================================= |
| @@ -279,7 +329,7 @@ void tDattorroReverb_init (tDattorroReverb* const rev) · 11 unmodified lines | ||
| 279 | 329 | r->size_max = 2.0f; |
| 280 | 330 | r->size = 1.f; |
| 281 | 331 | r->t = r->size * leaf.sampleRate * 0.001f; |
| 282 | − | |
| 332 | + r->frozen = 0; | |
| 283 | 333 | // INPUT |
| 284 | 334 | tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f)); |
| 285 | 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 | 432 | _tDattorroReverb* r = *rev; |
| 383 | 433 | |
| 384 | − // INPUT | |
| 385 | − float in_sample = tTapeDelay_tick(&r->in_delay, input); | |
| 386 | − | |
| 387 | − in_sample = tOnePole_tick(&r->in_filter, in_sample); | |
| 388 | − | |
| 389 | − for (int i = 0; i < 4; i++) | |
| 434 | + | |
| 435 | + float in_sample, f1_sample,f1_delay_2_sample, f2_sample, f2_delay_2_sample; | |
| 436 | + | |
| 437 | + if (r->frozen) | |
| 390 | 438 | { |
| 391 | − in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); | |
| 392 | − } | |
| 393 | − | |
| 394 | − // FEEDBACK 1 | |
| 395 | − float f1_sample = in_sample + r->f2_last; // + f2_last_out; | |
| 396 | − | |
| 397 | − tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); | |
| 398 | − | |
| 399 | − f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); | |
| 400 | − | |
| 401 | − f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); | |
| 402 | − | |
| 403 | − f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); | |
| 404 | − | |
| 405 | − f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; | |
| 406 | − | |
| 407 | − float f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); | |
| 408 | − | |
| 409 | − r->f1_delay_2_last = f1_delay_2_sample; | |
| 410 | − | |
| 411 | − f1_sample = r->f1_delay_2_last + f1_sample; | |
| 412 | − | |
| 413 | − f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); | |
| 414 | − | |
| 415 | − f1_sample *= r->feedback_gain; | |
| 416 | − | |
| 417 | − r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); | |
| 418 | − | |
| 419 | − // FEEDBACK 2 | |
| 420 | − float f2_sample = in_sample + r->f1_last; | |
| 421 | − | |
| 422 | − tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); | |
| 423 | − | |
| 424 | − f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); | |
| 425 | − | |
| 426 | − f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); | |
| 427 | − | |
| 428 | − f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); | |
| 429 | − | |
| 430 | − f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; | |
| 431 | − | |
| 432 | − float f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f); | |
| 433 | − | |
| 434 | − r->f2_delay_2_last = f2_delay_2_sample; | |
| 435 | − | |
| 436 | − f2_sample = r->f2_delay_2_last + f2_sample; | |
| 437 | − | |
| 438 | − f2_sample = tHighpass_tick(&r->f2_hp, f2_sample); | |
| 439 | − | |
| 440 | − f2_sample *= r->feedback_gain; | |
| 441 | − | |
| 442 | − r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample); | |
| 443 | − | |
| 439 | + input = 0.0f; | |
| 440 | + //r->f1_last = 0.0f; | |
| 441 | + //r->f2_last = 0.0f; | |
| 442 | + } | |
| 443 | + // INPUT | |
| 444 | + in_sample = tTapeDelay_tick(&r->in_delay, input); | |
| 445 | + | |
| 446 | + in_sample = tOnePole_tick(&r->in_filter, in_sample); | |
| 447 | + | |
| 448 | + for (int i = 0; i < 4; i++) | |
| 449 | + { | |
| 450 | + in_sample = tAllpass_tick(&r->in_allpass[i], in_sample); | |
| 451 | + } | |
| 452 | + | |
| 453 | + // FEEDBACK 1 | |
| 454 | + f1_sample = in_sample + r->f2_last; // + f2_last_out; | |
| 455 | + | |
| 456 | + tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f)); | |
| 457 | + | |
| 458 | + f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample); | |
| 459 | + | |
| 460 | + f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample); | |
| 461 | + | |
| 462 | + f1_sample = tOnePole_tick(&r->f1_filter, f1_sample); | |
| 463 | + | |
| 464 | + f1_sample = f1_sample + r->f1_delay_2_last * 0.5f; | |
| 465 | + | |
| 466 | + f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f); | |
| 467 | + | |
| 468 | + r->f1_delay_2_last = f1_delay_2_sample; | |
| 469 | + | |
| 470 | + f1_sample = r->f1_delay_2_last + f1_sample; | |
| 471 | + | |
| 472 | + f1_sample = tHighpass_tick(&r->f1_hp, f1_sample); | |
| 473 | + | |
| 474 | + f1_sample *= r->feedback_gain; | |
| 475 | + | |
| 476 | + r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample); | |
| 477 | + | |
| 478 | + // FEEDBACK 2 | |
| 479 | + f2_sample = in_sample + r->f1_last; | |
| 480 | + | |
| 481 | + tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f)); | |
| 482 | + | |
| 483 | + f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample); | |
| 484 | + | |
| 485 | + f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample); | |
| 486 | + | |
| 487 | + f2_sample = tOnePole_tick(&r->f2_filter, f2_sample); | |
| 488 | + | |
| 489 | + f2_sample = f2_sample + r->f2_delay_2_last * 0.5f; | |
| 490 | + | |
| 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 | 503 | // TAP OUT 1 |
| 446 | 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 | 540 | void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output) |
| 483 | 541 | { |
| 484 | 542 | _tDattorroReverb* r = *rev; |
| 543 | + float in_sample, f1_sample,f1_delay_2_sample, f2_sample, f2_delay_2_sample; | |
| 485 | 544 | |
| 486 | − // INPUT | |
| 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++) | |
| 545 | + if (r->frozen) | |
| 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 | |
| 497 | − float f1_sample = in_sample + r->f2_last; // + f2_last_out; | |
| 554 | + in_sample = tOnePole_tick(&r->in_filter, in_sample); | |
| 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 | |
| 524 | − float f2_sample = in_sample + r->f1_last; | |
| 583 | + f1_sample *= r->feedback_gain; | |
| 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 | 623 | // TAP OUT 1 |
| @@ -591,6 +663,35 @@ void tDattorroReverb_setMix (tDattorroReverb* const rev, float mix · 39 unmodified lines | ||
| 591 | 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 | 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 | 31 | s->buff = (float*) leaf_alloc( sizeof(float) * length); |
| 32 | 32 | |
| 33 | − s->length = length; | |
| 33 | + s->bufferLength = length; | |
| 34 | + s->recordedLength = 0; | |
| 34 | 35 | s->active = 0; |
| 35 | 36 | s->idx = 0; |
| 36 | 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 | 46 | s->buff = (float*) mpool_alloc( sizeof(float) * length, pool); |
| 46 | 47 | |
| 47 | − s->length = length; | |
| 48 | − s->active = 0; | |
| 48 | + s->bufferLength = length; | |
| 49 | + s->recordedLength = 0; | |
| 49 | 50 | s->idx = 0; |
| 50 | 51 | s->mode = RecordOneShot; |
| 51 | 52 | |
| @@ -79,7 +80,7 @@ void tBuffer_tick (tBuffer* const sb, float sample) · 27 unmodified lines | ||
| 79 | 80 | |
| 80 | 81 | s->idx += 1; |
| 81 | 82 | |
| 82 | − if (s->idx >= s->length) | |
| 83 | + if (s->idx >= s->bufferLength) | |
| 83 | 84 | { |
| 84 | 85 | if (s->mode == RecordOneShot) |
| 85 | 86 | { |
| @@ -96,17 +97,18 @@ void tBuffer_tick (tBuffer* const sb, float sample) · 10 unmodified lines | ||
| 96 | 97 | void tBuffer_read(tBuffer* const sb, float* buff, uint32_t len) |
| 97 | 98 | { |
| 98 | 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 | 102 | if (i < len) s->buff[i] = buff[i]; |
| 102 | 103 | else s->buff[i] = 0.f; |
| 103 | 104 | } |
| 105 | + s->recordedLength = len; | |
| 104 | 106 | } |
| 105 | 107 | |
| 106 | 108 | float tBuffer_get (tBuffer* const sb, int idx) |
| 107 | 109 | { |
| 108 | 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 | 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 | 124 | _tBuffer* s = *sb; |
| 123 | 125 | s->active = 0; |
| 126 | + s->recordedLength = s->idx; | |
| 124 | 127 | } |
| 125 | 128 | |
| 126 | 129 | int tBuffer_getRecordPosition(tBuffer* const sb) |
| @@ -138,16 +141,22 @@ void tBuffer_setRecordMode (tBuffer* const sb, RecordMode mode) · 11 unmodified lines | ||
| 138 | 141 | void tBuffer_clear (tBuffer* const sb) |
| 139 | 142 | { |
| 140 | 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 | 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 | 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 | 162 | //================================tSampler===================================== |
| @@ -156,8 +165,6 @@ static void handleStartEndChange(tSampler* const sp); · 2 unmodified lines | ||
| 156 | 165 | |
| 157 | 166 | static void attemptStartEndChange(tSampler* const sp); |
| 158 | 167 | |
| 159 | −static void updateStartEnd(tSampler* const sp); | |
| 160 | − | |
| 161 | 168 | void tSampler_init(tSampler* const sp, tBuffer* const b) |
| 162 | 169 | { |
| 163 | 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 | 175 | p->active = 0; |
| 169 | 176 | |
| 170 | 177 | p->start = 0; |
| 171 | − p->end = p->samp->length - 1; | |
| 178 | + p->end = p->samp->bufferLength - 1; | |
| 172 | 179 | |
| 173 | 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 | 212 | _tBuffer* s = *b; |
| 206 | 213 | |
| 207 | 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 | 226 | float tSampler_tick (tSampler* const sp) |
| 211 | 227 | { |
| 212 | 228 | _tSampler* p = *sp; |
| @@ -227,46 +243,22 @@ float tSampler_tick (tSampler* const sp) · 14 unmodified lines | ||
| 227 | 243 | |
| 228 | 244 | float* buff = p->samp->buff; |
| 229 | 245 | |
| 230 | − int dir = p->bnf * p->dir * p->flip; | |
| 231 | 246 | |
| 247 | + | |
| 232 | 248 | int idx, revidx; |
| 233 | 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 | 253 | if (p->flip < 0) |
| 237 | 254 | { |
| 238 | 255 | start = p->end; |
| 239 | 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 | 262 | idx = (int) p->idx; |
| 271 | 263 | alpha = p->idx - idx; |
| 272 | 264 | |
| @@ -280,7 +272,7 @@ float tSampler_tick (tSampler* const sp) · 7 unmodified lines | ||
| 280 | 272 | uint32_t cfxlen = p->cfxlen; |
| 281 | 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 | 277 | if (dir > 0) |
| 286 | 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 | 283 | numticks = (revidx-start) * p->iinc; |
| 292 | 284 | } |
| 293 | 285 | |
| 294 | − | |
| 295 | − | |
| 296 | − if (cfxlen > 0) // necessary to avoid divide by zero, also a waste of computation otherwise | |
| 286 | + // Check dir (direction) to interpolate properly | |
| 287 | + if (dir > 0) | |
| 297 | 288 | { |
| 298 | − | |
| 299 | − // Check dir (direction) to interpolate properly | |
| 300 | − if (dir > 0) | |
| 289 | + // FORWARD NORMAL SAMPLE | |
| 290 | + int i1 = ((idx-1) < 0) ? 0 : idx-1; | |
| 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 | 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 | |
| 357 | − { | |
| 358 | − // REVERSE | |
| 359 | − int i1 = ((revidx+1) >= length) ? (length-1) : revidx+1; | |
| 360 | − int i3 = ((revidx-1) < 0) ? revidx : (revidx-1); | |
| 361 | − int i4 = ((revidx-2) < 0) ? 0 : (revidx-2); | |
| 345 | + else | |
| 346 | + { | |
| 347 | + g2 = 0.0f; | |
| 348 | + } | |
| 362 | 349 | |
| 363 | − sample = LEAF_interpolate_hermite_x (buff[i1], | |
| 364 | − buff[revidx], | |
| 365 | − buff[i3], | |
| 366 | − buff[i4], | |
| 367 | − revalpha); | |
| 350 | + } | |
| 351 | + else | |
| 352 | + { | |
| 353 | + // REVERSE | |
| 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 | 369 | if (p->mode == PlayLoop) |
| 373 | 370 | { |
| 374 | 371 | if (numticks <= (float) cfxlen) |
| 375 | 372 | { |
| 376 | 373 | // CROSSFADE SAMPLE |
| 377 | 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 | 381 | cdx = end - (numticks * p->inc); |
| 381 | 382 | |
| 382 | 383 | i1 = ((cdx-1) < 0) ? 0 : cdx-1; |
| @@ -403,22 +404,51 @@ float tSampler_tick (tSampler* const sp) · 20 unmodified lines | ||
| 403 | 404 | } |
| 404 | 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 | |
| 410 | − { | |
| 411 | − g2 = 0.0f; | |
| 412 | − } | |
| 413 | − | |
| 416 | + | |
| 417 | + | |
| 414 | 418 | |
| 415 | 419 | float inc = fmod(p->inc, p->len); |
| 416 | 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 | 452 | if (p->mode == PlayNormal) |
| 423 | 453 | { |
| 424 | 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 | 501 | p->last = sample; |
| 468 | 502 | |
| 469 | 503 | |
| 470 | − | |
| 471 | 504 | return p->last; |
| 472 | 505 | } |
| 473 | 506 | |
| @@ -532,11 +565,11 @@ void tSampler_stop (tSampler* const sp) · 58 unmodified lines | ||
| 532 | 565 | static void handleStartEndChange(tSampler* const sp) |
| 533 | 566 | { |
| 534 | 567 | _tSampler* p = *sp; |
| 535 | − | |
| 568 | + | |
| 536 | 569 | p->len = abs(p->end - p->start); |
| 537 | 570 | |
| 538 | 571 | if (p->len < (p->cfxlen * 0.25f)) p->cfxlen = p->len * 0.25f; |
| 539 | − | |
| 572 | + | |
| 540 | 573 | if (p->start > p->end) |
| 541 | 574 | { |
| 542 | 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 | 598 | void tSampler_setStart (tSampler* const sp, int32_t start) |
| 592 | 599 | { |
| 593 | 600 | _tSampler* p = *sp; |
| @@ -611,7 +618,7 @@ void tSampler_setStart (tSampler* const sp, int32_t start) · 17 unmodified lines | ||
| 611 | 618 | |
| 612 | 619 | int dir = p->bnf * p->dir * tempflip; |
| 613 | 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 | 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 | 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 | 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 | 640 | handleStartEndChange(sp); |
| 634 | 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 | 687 | handleStartEndChange(sp); |
| 681 | 688 | p->targetend = -1; |
| 682 | 689 | } |
| @@ -21,6 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | LEAF leaf; |
| 22 | 22 | |
| 23 | 23 | void LEAF_init(float sr, int blocksize, char* memory, size_t memorysize, float(*random)(void)) |
| 24 | + | |
| 24 | 25 | { |
| 25 | 26 | leaf_pool_init(memory, memorysize); |
| 26 | 27 | |