Unified · Split
| @@ -19,31 +19,12 @@ · 18 unmodified lines | ||
| 19 | 19 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tPluck ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ |
| 20 | 20 | void tPluck_init (tPluck* const pl, float lowestFrequency) |
| 21 | 21 | { |
| 22 | − _tPluck* p = *pl = (_tPluck*) leaf_alloc(sizeof(_tPluck)); | |
| 23 | − | |
| 24 | − if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f; | |
| 25 | − | |
| 26 | − tNoise_init(&p->noise, WhiteNoise); | |
| 27 | − | |
| 28 | − tOnePole_init(&p->pickFilter, 0.0f); | |
| 29 | − | |
| 30 | − tOneZero_init(&p->loopFilter, 0.0f); | |
| 31 | − | |
| 32 | − tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2); | |
| 33 | − | |
| 34 | − tPluck_setFrequency(pl, 220.0f); | |
| 22 | + tPluck_initToPool(pl, lowestFrequency, &leaf_mempool); | |
| 35 | 23 | } |
| 36 | 24 | |
| 37 | 25 | void tPluck_free (tPluck* const pl) |
| 38 | 26 | { |
| 39 | − _tPluck* p = *pl; | |
| 40 | − | |
| 41 | − tNoise_free(&p->noise); | |
| 42 | − tOnePole_free(&p->pickFilter); | |
| 43 | − tOneZero_free(&p->loopFilter); | |
| 44 | − tAllpassDelay_free(&p->delayLine); | |
| 45 | − | |
| 46 | − leaf_free(p); | |
| 27 | + tPluck_freeFromPool(pl, &leaf_mempool); | |
| 47 | 28 | } |
| 48 | 29 | |
| 49 | 30 | void tPluck_initToPool (tPluck* const pl, float lowestFrequency, tMempool* const mp) |
| @@ -60,6 +41,7 @@ void tPluck_initToPool (tPluck* const pl, float lowestFrequency, tMempool* · 10 unmodified lines | ||
| 60 | 41 | tOneZero_initToPool(&p->loopFilter, 0.0f, mp); |
| 61 | 42 | |
| 62 | 43 | tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp); |
| 44 | + tAllpassDelay_clear(&p->delayLine); | |
| 63 | 45 | |
| 64 | 46 | tPluck_setFrequency(pl, 220.0f); |
| 65 | 47 | } |
| @@ -157,48 +139,12 @@ void tPluckSampleRateChanged(tPluck* const pl) · 91 unmodified lines | ||
| 157 | 139 | /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tKarplusStrong ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ |
| 158 | 140 | void tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency) |
| 159 | 141 | { |
| 160 | − _tKarplusStrong* p = *pl = (_tKarplusStrong*) leaf_alloc(sizeof(_tKarplusStrong)); | |
| 161 | − | |
| 162 | − if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f; | |
| 163 | − | |
| 164 | − tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2); | |
| 165 | − | |
| 166 | − tLinearDelay_init(&p->combDelay, 0.0f, leaf.sampleRate * 2); | |
| 167 | − | |
| 168 | − tOneZero_init(&p->filter, 0.0f); | |
| 169 | − | |
| 170 | − tNoise_init(&p->noise, WhiteNoise); | |
| 171 | − | |
| 172 | − for (int i = 0; i < 4; i++) | |
| 173 | − { | |
| 174 | − tBiQuad_init(&p->biquad[i]); | |
| 175 | − } | |
| 176 | − | |
| 177 | − p->pluckAmplitude = 0.3f; | |
| 178 | − p->pickupPosition = 0.4f; | |
| 179 | − | |
| 180 | − p->stretching = 0.9999f; | |
| 181 | − p->baseLoopGain = 0.995f; | |
| 182 | − p->loopGain = 0.999f; | |
| 183 | − | |
| 184 | − tKarplusStrong_setFrequency( pl, 220.0f ); | |
| 142 | + tKarplusStrong_initToPool(pl, lowestFrequency, &leaf_mempool); | |
| 185 | 143 | } |
| 186 | 144 | |
| 187 | 145 | void tKarplusStrong_free (tKarplusStrong* const pl) |
| 188 | 146 | { |
| 189 | − _tKarplusStrong* p = *pl; | |
| 190 | − | |
| 191 | − tAllpassDelay_free(&p->delayLine); | |
| 192 | − tLinearDelay_free(&p->combDelay); | |
| 193 | − tOneZero_free(&p->filter); | |
| 194 | − tNoise_free(&p->noise); | |
| 195 | − | |
| 196 | − for (int i = 0; i < 4; i++) | |
| 197 | − { | |
| 198 | − tBiQuad_free(&p->biquad[i]); | |
| 199 | − } | |
| 200 | − | |
| 201 | − leaf_free(p); | |
| 147 | + tKarplusStrong_freeFromPool(pl, &leaf_mempool); | |
| 202 | 148 | } |
| 203 | 149 | |
| 204 | 150 | void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequency, tMempool* const mp) |
| @@ -209,8 +155,10 @@ void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequ · 4 unmodified lines | ||
| 209 | 155 | if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f; |
| 210 | 156 | |
| 211 | 157 | tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp); |
| 158 | + tAllpassDelay_clear(&p->delayLine); | |
| 212 | 159 | |
| 213 | 160 | tLinearDelay_initToPool(&p->combDelay, 0.0f, leaf.sampleRate * 2, mp); |
| 161 | + tLinearDelay_clear(&p->combDelay); | |
| 214 | 162 | |
| 215 | 163 | tOneZero_initToPool(&p->filter, 0.0f, mp); |
| 216 | 164 | |
| @@ -410,30 +358,12 @@ void tSimpleLivingString_init(tSimpleLivingString* const pl, float freq, floa · 193 unmodified lines | ||
| 410 | 358 | float decay, float targetLev, float levSmoothFactor, |
| 411 | 359 | float levStrength, int levMode) |
| 412 | 360 | { |
| 413 | − _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) leaf_alloc(sizeof(_tSimpleLivingString)); | |
| 414 | − | |
| 415 | − p->curr=0.0f; | |
| 416 | − tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions) | |
| 417 | − tSimpleLivingString_setFreq(pl, freq); | |
| 418 | − tLinearDelay_init(&p->delayLine,p->waveLengthInSamples, 2400); | |
| 419 | − tOnePole_init(&p->bridgeFilter, dampFreq); | |
| 420 | − tHighpass_init(&p->DCblocker,13); | |
| 421 | − p->decay=decay; | |
| 422 | − tFeedbackLeveler_init(&p->fbLev, targetLev, levSmoothFactor, levStrength, levMode); | |
| 423 | − p->levMode=levMode; | |
| 361 | + tSimpleLivingString_initToPool(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf_mempool); | |
| 424 | 362 | } |
| 425 | 363 | |
| 426 | 364 | void tSimpleLivingString_free(tSimpleLivingString* const pl) |
| 427 | 365 | { |
| 428 | − _tSimpleLivingString* p = *pl; | |
| 429 | − | |
| 430 | − tExpSmooth_free(&p->wlSmooth); | |
| 431 | − tLinearDelay_free(&p->delayLine); | |
| 432 | − tOnePole_free(&p->bridgeFilter); | |
| 433 | − tHighpass_free(&p->DCblocker); | |
| 434 | − tFeedbackLeveler_free(&p->fbLev); | |
| 435 | − | |
| 436 | − leaf_free(p); | |
| 366 | + tSimpleLivingString_freeFromPool(pl, &leaf_mempool); | |
| 437 | 367 | } |
| 438 | 368 | |
| 439 | 369 | void tSimpleLivingString_initToPool (tSimpleLivingString* const pl, float freq, float dampFreq, |
| @@ -447,6 +377,7 @@ void tSimpleLivingString_initToPool (tSimpleLivingString* const pl, float fr · 7 unmodified lines | ||
| 447 | 377 | tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions) |
| 448 | 378 | tSimpleLivingString_setFreq(pl, freq); |
| 449 | 379 | tLinearDelay_initToPool(&p->delayLine,p->waveLengthInSamples, 2400, mp); |
| 380 | + tLinearDelay_clear(&p->delayLine); | |
| 450 | 381 | tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp); |
| 451 | 382 | tHighpass_initToPool(&p->DCblocker,13, mp); |
| 452 | 383 | p->decay=decay; |
| @@ -549,53 +480,11 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 96 unmodified lines | ||
| 549 | 480 | float dampFreq, float decay, float targetLev, float levSmoothFactor, |
| 550 | 481 | float levStrength, int levMode) |
| 551 | 482 | { |
| 552 | − _tLivingString* p = *pl = (_tLivingString*) leaf_alloc(sizeof(_tLivingString)); | |
| 553 | − | |
| 554 | − p->curr=0.0f; | |
| 555 | − tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions) | |
| 556 | − tLivingString_setFreq(pl, freq); | |
| 557 | − p->freq = freq; | |
| 558 | − tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position | |
| 559 | − tLivingString_setPickPos(pl, pickPos); | |
| 560 | − p->prepIndex=prepIndex; | |
| 561 | − tLinearDelay_init(&p->delLF,p->waveLengthInSamples, 2400); | |
| 562 | − tLinearDelay_init(&p->delUF,p->waveLengthInSamples, 2400); | |
| 563 | − tLinearDelay_init(&p->delUB,p->waveLengthInSamples, 2400); | |
| 564 | − tLinearDelay_init(&p->delLB,p->waveLengthInSamples, 2400); | |
| 565 | − p->dampFreq = dampFreq; | |
| 566 | − tOnePole_init(&p->bridgeFilter, dampFreq); | |
| 567 | − tOnePole_init(&p->nutFilter, dampFreq); | |
| 568 | − tOnePole_init(&p->prepFilterU, dampFreq); | |
| 569 | − tOnePole_init(&p->prepFilterL, dampFreq); | |
| 570 | − tHighpass_init(&p->DCblockerU,13); | |
| 571 | − tHighpass_init(&p->DCblockerL,13); | |
| 572 | − p->decay=decay; | |
| 573 | − p->prepIndex = prepIndex; | |
| 574 | − tFeedbackLeveler_init(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode); | |
| 575 | − tFeedbackLeveler_init(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode); | |
| 576 | − p->levMode=levMode; | |
| 577 | −} | |
| 483 | + tLivingString_initToPool(pl, fre, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf_mempool); | |
| 578 | 484 | |
| 579 | 485 | void tLivingString_free(tLivingString* const pl) |
| 580 | 486 | { |
| 581 | − _tLivingString* p = *pl; | |
| 582 | − | |
| 583 | − tExpSmooth_free(&p->wlSmooth); | |
| 584 | − tExpSmooth_free(&p->ppSmooth); | |
| 585 | − tLinearDelay_free(&p->delLF); | |
| 586 | − tLinearDelay_free(&p->delUF); | |
| 587 | − tLinearDelay_free(&p->delUB); | |
| 588 | − tLinearDelay_free(&p->delLB); | |
| 589 | − tOnePole_free(&p->bridgeFilter); | |
| 590 | − tOnePole_free(&p->nutFilter); | |
| 591 | − tOnePole_free(&p->prepFilterU); | |
| 592 | − tOnePole_free(&p->prepFilterL); | |
| 593 | − tHighpass_free(&p->DCblockerU); | |
| 594 | − tHighpass_free(&p->DCblockerL); | |
| 595 | − tFeedbackLeveler_free(&p->fbLevU); | |
| 596 | − tFeedbackLeveler_free(&p->fbLevL); | |
| 597 | − | |
| 598 | − leaf_free(p); | |
| 487 | + tLivingString_freeFromPool(pl, &leaf_mempool); | |
| 599 | 488 | } |
| 600 | 489 | |
| 601 | 490 | void tLivingString_initToPool (tLivingString* const pl, float freq, float pickPos, float prepIndex, |
| @@ -616,6 +505,10 @@ void tLivingString_initToPool (tLivingString* const pl, float freq, float · 14 unmodified lines | ||
| 616 | 505 | tLinearDelay_initToPool(&p->delUF,p->waveLengthInSamples, 2400, mp); |
| 617 | 506 | tLinearDelay_initToPool(&p->delUB,p->waveLengthInSamples, 2400, mp); |
| 618 | 507 | tLinearDelay_initToPool(&p->delLB,p->waveLengthInSamples, 2400, mp); |
| 508 | + tLinearDelay_clear(&p->delLF); | |
| 509 | + tLinearDelay_clear(&p->delUF); | |
| 510 | + tLinearDelay_clear(&p->delUB); | |
| 511 | + tLinearDelay_clear(&p->delLB); | |
| 619 | 512 | p->dampFreq = dampFreq; |
| 620 | 513 | tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp); |
| 621 | 514 | tOnePole_initToPool(&p->nutFilter, dampFreq, mp); |