PaulStoffregen/Audio

Update envelope sustain level while note on

BourgeoisLab opened this issue · 1 comments

Description

When changing the sustain level of an envelope while the note is currently on will not update the level. The new level will only be effetive on the next noteOn() call.

Steps To Reproduce Problem

Change the sustain level while a note is playing. The level will not change immediately but only on the next note.

Possible solution (not nice)

in effect_envelope.h

void sustain(float level) {
    if (level < 0.0) level = 0;
    else if (level > 1.0) level = 1.0;
    sustain_mult = level * 1073741824.0;
    // add this 2 lines
    if (isSustain())
        mult_hires = sustain_mult;
}

Hello,
I had the same need, and modified my files this way. It works, but it causes clipping if the sustain is modified during the decay phase.
So I've also modified that, and moved sustain from .h to .cpp to test for state. I've added this line at the end of the sustain() method, so whenever sustain level is changed, decay accumulators are updated :

__disable_irq();
if(state == STATE_SUSTAIN){
	mult_hires = sustain_mult;
} else if(state == STATE_DECAY){
	inc_hires = (sustain_mult - mult_hires) / (int32_t)count;
}
__enable_irq();

Maybe I should make a pull request ? I've never do that, don't how it works...