[sharing] Analog-style ADSR envelopes

Peter McCulloch's icon

Here's an example of analog-style ADSR envelopes created in gen~. These are RC style (so convex going up, concave going down) and are the sum of an AD envelope and an ASR envelope. If you are interested in analog-style envelopes or slew limiters, there is some useful code that demonstrates how to calculate the attack and decay coefficients for slide.

They can respond to changes in parameters at signal rate and they (should) behave similar to analog envelopes in that they are constant rate rather than constant time. That means that the release time of the envelope may be different depending on where the envelope is when the release is triggered. There is also an attack lockout feature which prevents release/decay from occurring until the attack has finished; this is off by default.

The first one behaves like the Moog Mini (no retriggering while sustaining) and the second one behaves like the Arp 2600 (retriggering on every new note). These are not optimized, but they are functional and commented for learning purposes. I haven't included a reset from 0. capability in order to keep the code simpler, but it is certainly possible to implement this feature. Like analog envelopes, these envelopes are not velocity sensitive, though it is possible to modify them so that they are.

================== UPDATED VERSION POSTED IN COMMENT BELOW =================

PM.Analog-Style-Envelopes.maxpat
Max Patch
PM.Analog-Style-Envelopes1.maxpat
Max Patch
redhexagonal's icon

Thats really great Peter, but I get an error for the gen~ for gate+trigger :

compile errors
clang: error line 2132 column 43: use of undeclared identifier 'decay'
gen~: failed to compile patcher

Would there be any way to vary the curves amount?

Peter McCulloch's icon

Here's a fixed version. It isn't possible to vary the curves in this version as it is now.

A way of doing that would be to construct a linear version of this then selectively apply the curves in the code via scale, though it will take some fancy footwork if you want to be able to change the curves rapidly without introducing discontinuities.

PM.Analog-Style-Envelopes2.maxpat
Max Patch
stkr's icon

hi peter.

just wanna say thanks for this and congratulations on the work.

it is not only typically mccullochian, but is also some of the most amazing dsp research and code i have seen done in max for a very long time.

your contributions to the community are always fantastic and have been so for over a decade.

that's enough bro-mance for now.

i'll think of something more creatively useful to contribute to this at some stage.

alfonso santimone's icon

nice stuff!
thanks!

Wetterberg's icon

I'd like to join the chorus here. It's such a treat to be around you egg-heads these days. Amazing work. I've wanted to help out in the BEAP project and such, but I've simply been too swamped to participate. Watching from the sidelines is such great entertainment, though.

Peter McCulloch's icon

Thanks for the feedback, everyone! Maybe with some tweaking these could work in BEAP...

Wetterberg's icon

My biggest flaw is constantly ripping open BEAP modules and using them for my own non-standard purposes. Eh. I *love* BEAP, but I don't "use BEAP".

Peter McCulloch's icon

I had been working on a modular synth library A couple of years ago but realized I wasn't going to have time to finish it and my dissertation, so I rolled some of it into BEAP. (For instance, Bp.AHD is the guts from MOD.AHD~ with 5V stuff added) The stuff from that project is different from BEAP in that it's much lower level (just objects and arguments; no nice GUI) and inputs are not normalized to 5V.

Maybe when I can get some time I'll throw some of the modules up on GitHub. I learned a lot from working on that and BEAP, and found the Sound On Sound Synth Secrets articles to be really handy, since I don't have a ton of old synth hardware experience.

endageorge's icon

First of all, these envelopes are amazing work.
I realize this is an old thread. I'm a newbie with gen so I wonder how difficult it would be to modify the gen~ here to so that the envelopes could ramp logarithmically or exponentially??

flaviogaete's icon

I second everyone here, thanks Peter for all the generous and amazing work! I have zero experience with gen and would love to learn how the code works for this envelope. I'll jump over the search box in a minute and start doing my gen tutorial hunt, but if anyone has a suggestion for where to start, it will be much welcome and appreciated!

D1rty Duck's icon

Just found this while I was looking for some ideas on how to build a ADSR in gen~. And its really nice great work.
I used the first one without a trigger, but added Velocity-sensitivity. It just needs some small additions, so at the begining of the codebox I added:

History vel(1);

if (in1 > 0) {
    vel = in1;
    }

And changed the second last line which sets out1 to:

out1 = (mix(ad,asr,sustain)) * vel;

Here's the whole thing:

Max Patch
Copy patch and select New From Clipboard in Max.