Hi,
I found a bug in the current implementation of the ADSR envelope. Namely when void applyEnvelopeToBuffer (AudioBuffer<FloatType>& buffer, int startSample, int numSamples)
is used with parameters attack: 0, decay: 100, sustain: 100%, release: 1000
, the release stage is skipped. The problem seems to be that envelopeVal
is never set to the sustain value when applyEnvelopeToBuffer
is used (because the attack and decay stages are skipped). I managed to solve this by adding the following line to the noteOn
function where the attack and decay stages are skipped:
void noteOn() noexcept
{
if (attackRate > 0.0f)
{
state = State::attack;
}
else if (decayRate > 0.0f)
{
envelopeVal = 1.0f;
state = State::decay;
}
else
{
envelopeVal = parameters.sustain; // This line was added
state = State::sustain;
}
}
I also created a pull request implementing this here