Juce::ADSR with Slope?


i see Juce has its own ADSR class. But I can’t figure out how to apply to it “Slope” it seems the envelopes only linear. By slope I mean the following (see decay on pic):

Can someone suggest please how to do this with minimal cost?

I thought to put the float value = adsr.getNextSample() level through something like this: pow(value, pow(2, -1.25f) but this only works in the case of attack and I don’t know the current state like decay/sustain/release.

I would be grateful if someone could suggest a simple and inexpensive solution. Thanks!

Not sure if it will help you, but I use a table, similar to a wavetable, which my envelopes follow. That way I can use all sorts of envelope shapes, curves and slopes, even modulated envelopes! And my method is fairly CPU cheap considering my possibilities, as I only change the table with the math when I change a parameter.


Yes I tried to use that in my old implementation (before I started use Juce framework). That is, something like “c arrays” with pre-generated slope lines - sampleAttack[sampleIndex % 20 sec * 44100], sampleDecay[sampleIndex % 20 sec * 44100], sampleRelease[sampleIndex % 20 sec * 44100]
where sampleIndex is adsr level, but then my app use a lot of memory, because I have about 5 envelopes and it’s about 13-14 mb memory, so that’s seems a lot.

My semi-modular synth has 8 envelope modules, each with a pre-sustain (attack, hold, decay) lookup table of 384 floats, plus a post-sustain (release 1 and release 2) table of 256 gloats. I don’t interpolate the data upon retrieval, as I can’t discern any difference, however for smoother requirements you can. Also as you can see I don’t use table lookup for the sustain part.

1 Like