basic envelope example?

working on another module for the plugin i’m currently working on, but find myself needing a good example of how to build a simple envelope generator. i only need rise/attack and fall/decay stages, so an AD is preferable.

i tried checking out Bogaudio’s AD envelope, but it was a bit more in-depth than i was comfortable trying to pick apart. i’m currently looking through the Fundamental ADSR as i’m guessing that’s one of the most basic, but even that has some stuff in it i’m unfamiliar with and not sure how to adapt for my use.

i was hoping to look at NYSTHI’s AD envelope, but didn’t realize until now that his modules are proprietary.

does anyone know of any other decent examples? the simpler the better.

If you don’t need to build it yourself, you might consider using this mature one by Nigel Redmond:

Here’s an article he wrote about it:

Basic usage looks something like this:

ADSR adsr;

adsr.setAttackRate(0); // You'd want to set this to whatever you need
adsr.setDecayRate(0); // You'd want to set this to whatever you need
adsr.setReleaseRate(1 * APP->engine->getSampleRate()); // Example: 1 second

// Then later on
adsr.gate(true); // Trigger the ADSR

// and in your main loop
float adsr_value = adsr.process();

If you go this direction and need more direction, I’d be happy to help out!

1 Like

thanks a bunch :smiley: i’ll take a look at this as soon as i have the time, and i’ll get back to you if i have any questions.

1 Like

Are you on GitHub? I have a project I don’t want to open completely, but I can share it with you. It has precisely the AD envelope. I’ve made it from this ADSR code Envelope generators—ADSR code | EarLevel Engineering

1 Like

Nek, please excuse me as I’m not trying to say that Nigel’s version is better than yours. But in case alefnull chooses Nigel’s version, here’s how to convert it to an attack/decay envelope:

if(adsr.getState() == ADSR::env_sustain) adsr.gate(false);

This will essentially skip the sustain stage, and if the decay rate is set to 0, will end up behaving like an A/D envelope. I hope that one of our solutions helps him out!!

1 Like

i am on github, with the same username. i’d certainly appreciate at least a peek to see what it looks like!

thanks again for the info! i’ll give this a try as well :slight_smile:

Added you!

1 Like

Fundamental series is open source and are nice to cruise and learn from.

1 Like

well i was trying to make a linear function generator, and the Fundamental ADSR is exponential, but i did find some useful info in there, for sure.