[sdiy] Fast envelope generation

Tom Wiltshire tom at electricdruid.net
Tue Dec 18 11:54:05 CET 2012

On 18 Dec 2012, at 01:05, Gordon JC Pearce wrote:

> Hi all,
> I had a thought about generating exponential envelopes on "small" microcontrollers.  Actually calculating an exponential decay is computationally expensive, so how about using a lookup table and then using something akin to a phase accumulator to set the decay time?
> I'd need to work out exactly how to go from the attack phase to the release phase, if you released the key during attack.  However for a simple decay/release envelope like on a TB303 it would be fine.
> I await the onslaught of "it's been done" and "it doesn't work" ;-)

This is my own example of exactly what you're talking about:


The technique is good, but needs linear interpolation to hide the gaps between table entries at very slow times. Which isn't an argument against it, just an observation. For shorter stage times and long tables, you could get away without it.

The only tricky bits are:

1) Making sure you have enough bits for the variables to give you the range you need. I wanted a 1msec-10sec range on the curves, and the first version with a 16-bit accumulator couldn't do it. I had to up it to 24-bit.

2) Dealing with the scaling and offset of the curve sections. As you've already spotted, the release stage has to be scaled from *whatever the value is when the gate goes low* to zero. Similarly the attack is scaled between whatever the value when the gate goes high and the max value.

It's a simple technique, but very versatile.


More information about the Synth-diy mailing list