Linear AD Envelope Generator

geddonn's icon

Hi guys, I'm trying to hack together a simple 2 step Envelope Generator (AD) from the 7-step envelope generator example patch. I'm trying to make it react exactly like the ADSR~ object with Sustain and Release set to 0.

Unfortunately I can't seem to make the envelope retrigger without first sending a zero value.
Also I can't seem to make it retrigger until the envelope has finished.

Is there a way to do this simply? Possibly more simply than the 7-stage envelope generator method, I feel it's maybe overkill for a 2 step envelope.

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

Anyway, here's what I have so far.

kleine's icon
Max Patch
Copy patch and select New From Clipboard in Max.

without gen~:
you can use e.g. function with line~  or curve~...

geddonn's icon

Thanks for your reply. I know several ways I can do it in MSP and this is a good one, but the point was to achieve it in gen so I can make a sample accurate envelope generator.

kleine's icon
Max Patch
Copy patch and select New From Clipboard in Max.

like this?

geddonn's icon

Aha, thanks, I guess I can use a pulse train to get it out of the max and into MSP too.
Now I guess my only problem is how to get the envelope to reset to zero quickly if it is retriggered while it's still ramping.
Any ideas?
I'm gonna have a rummage.

Peter McCulloch's icon

Here's a way of doing it. This is not as flexible as the seven stage envelope in terms of number of stages, but (I think) it has the same retriggering behavior as adsr~. I've also added the legato mode, which I find more useful for monosynths.

Also, you can prematurely short-circuit the attack (i.e. if you release the envelope before it's reached the decay phase, it will decay from there)

I highly recommend checking out some of the threads on envelopes on kvraudio. I've found them greatly helpful.

FWIW, envelopes can be surprisingly hard to write, especially with features such as those found in adsr~. I'm working on an analog style ADSR now that has a retriggering model similar to the Moog mini. (where rapid retriggering of notes would cause an increase in volume)

For no-frill two-stage envelopes you can look at models that are much simpler: a pulse-wave generator (I'd look at sig~ 1 into +=~ into

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

HTH

Sanjay Das's icon

@Peter's Gen~ patch:

Is it possible to change the attack/decay time WHILE the ramp is in progress?
Help appreciated!

Peter McCulloch's icon

Sure! I'd encourage you to check out the Bp.AHD and Bp.AD2 in BEAP for some examples. (Especially the latter one)

Sanjay Das's icon

Thanks a lot, that helped clear a lot of doubts. Boy was I wrong about making Envelope Generators :3 :3 :3 :3 :3

Ernest's icon

Here is a gen~ implementation of an ADSR envelope, first published in May 2014, with full documentation. It uses the same envelope-phase calculation method as the 7-stage envelope, and is openly expansible to any number of stages

Peter McCulloch's icon

Ernest, have you considered adding a Delay stage (for a DADSR)? Might be handy for LFOs, and a fun one to figure out.

Ernest's icon

It really isn't very difficult to add a delay stage in gen~. One simply puts a delay object on the gate-on input, with time set in sample periods.

Peter McCulloch's icon

I think it's slightly different, since the attack of the envelope is delayed but the release is not. Also, the wait period might interact with the release in a monophonic setting. For controlling the amplitude of a pitch LFO, a hard reset to 0 would probably be fine, but this might not be ideal for an amplitude LFO's envelope. My guess is that you could probably just model it as an additional stage in the envelope which has 0 amplitude.

Ernest's icon

My design does both of those things already. Delaying the gate-on signal would not affect the gate-off signal, and it already has a pre-attack phase that only happens on gate-off events while the envelope is on, to prevent clicks.

Roman Thilenius's icon

if i may ask: why is it a problem that you are required to send 0 before the list?

anyhow, if you dont need to modulate the envelope in realtime, you could use a buffer~ with the pregenerated envelope inside.

Peter McCulloch's icon

@Ernest, I'm doing analog-style envelopes triggered at signal rate so gate-on and gate-off are usually in the same stream and then a separate stream containing triggers is used to indicate new envelopes. I took a look at it and the delay triggering at signal rate ended up being pretty easy to add to existing envelopes; the key is not using a delay to begin with.

For anyone curious, here's an example of a signal rate triggered DADSR. It uses an asymmetrical rampsmooth~ (with arguments of 88200 1) in combination with a threshold so that it takes extra time to trigger the start (2 seconds), but the release is triggered immediately. This also allows it to be cancelled without being triggered.

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

Benjamin Whateley's icon

Here is a simple version of an AD envelope I have made, it does not yet have a re-trig mode like Ernest's, and is not as sophisticated as the other's here created by Peter Mcculloch. I look forward to diving into their designs later.

I'm working on the re-trig, but here is the current version, you can set the curve for attack and decay independently, one thing I noticed about the 7 segment example is that the shape of each curve is a bit odd, so I used pow and that seemed to give a more evenly distributed curve than exponent in scale.

envelope_example_project.zip
application/x-zip-compressed 6.51 KB