Unified · Split
Binary file not shown.
Binary file not shown.
| @@ -104,6 +104,7 @@ extern "C" { · 103 unmodified lines | ||
| 104 | 104 | |
| 105 | 105 | float attackPhase, decayPhase, releasePhase, rampPhase; |
| 106 | 106 | |
| 107 | + float leakFactor; | |
| 107 | 108 | |
| 108 | 109 | |
| 109 | 110 | } _tADSR; |
| @@ -120,6 +121,7 @@ extern "C" { · 10 unmodified lines | ||
| 120 | 121 | void tADSR_setDecay (tADSR* const, float decay); |
| 121 | 122 | void tADSR_setSustain (tADSR* const, float sustain); |
| 122 | 123 | void tADSR_setRelease (tADSR* const, float release); |
| 124 | + void tADSR_setLeakFactor (tADSR* const, float leakFactor); | |
| 123 | 125 | void tADSR_on (tADSR* const, float velocity); |
| 124 | 126 | void tADSR_off (tADSR* const); |
| 125 | 127 | |
| @@ -309,6 +309,8 @@ void tADSR_init(tADSR* const adsrenv, float attack, float decay, float sustai · 308 unmodified lines | ||
| 309 | 309 | adsr->releaseInc = adsr->inc_buff[releaseIndex]; |
| 310 | 310 | adsr->rampInc = adsr->inc_buff[rampIndex]; |
| 311 | 311 | |
| 312 | + adsr->leakFactor = 1.0f; | |
| 313 | + | |
| 312 | 314 | } |
| 313 | 315 | |
| 314 | 316 | void tADSR_free(tADSR* const adsrenv) |
| @@ -374,6 +376,7 @@ void tADSR_initToPool (tADSR* const adsrenv, float attack, float decay, fl · 59 unmodified lines | ||
| 374 | 376 | adsr->releaseInc = adsr->inc_buff[releaseIndex]; |
| 375 | 377 | adsr->rampInc = adsr->inc_buff[rampIndex]; |
| 376 | 378 | |
| 379 | + adsr->leakFactor = 1.0f; | |
| 377 | 380 | } |
| 378 | 381 | |
| 379 | 382 | void tADSR_freeFromPool (tADSR* const adsrenv, tMempool* const mp) |
| @@ -443,7 +446,14 @@ void tADSR_setRelease(tADSR* const adsrenv, float release) · 63 unmodified lines | ||
| 443 | 446 | adsr->releaseInc = adsr->inc_buff[releaseIndex]; |
| 444 | 447 | } |
| 445 | 448 | |
| 449 | +// 0.999999 is slow leak, 0.9 is fast leak | |
| 450 | +void tADSR_setLeakFactor(tADSR* const adsrenv, float leakFactor) | |
| 451 | +{ | |
| 452 | + _tADSR* adsr = *adsrenv; | |
| 453 | + | |
| 446 | 454 | |
| 455 | + adsr->leakFactor = leakFactor; | |
| 456 | +} | |
| 447 | 457 | |
| 448 | 458 | void tADSR_on(tADSR* const adsrenv, float velocity) |
| 449 | 459 | { |
| @@ -545,6 +555,11 @@ float tADSR_tick(tADSR* const adsrenv) · 95 unmodified lines | ||
| 545 | 555 | adsr->decayPhase += adsr->decayInc; |
| 546 | 556 | } |
| 547 | 557 | |
| 558 | + if (adsr->inSustain) | |
| 559 | + { | |
| 560 | + adsr->next = adsr->next * adsr->leakFactor; | |
| 561 | + } | |
| 562 | + | |
| 548 | 563 | if (adsr->inRelease) |
| 549 | 564 | { |
| 550 | 565 | // If release done, finish. |