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.
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
adsr.setSustainLevel(1.0);
// 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!
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
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:
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!!