# [sdiy] Fast envelope generation

Donald Tillman don at till.com
Tue Dec 18 22:59:03 CET 2012

```On Dec 18, 2012, at 12:38 PM, Tom Wiltshire wrote:

> Yes. Use a "phase accumulator"-style approach to move through a look-up table at variable speed, and use low bits from the accumulator to provide linear interpolation between table values.
> This provides a simple way to stretch *any* curve to the required time, with no extra overhead for different curves and no calculation required beyond one multiplication for the interp. This is exactly what Gordon originally proposed, and exactly what I did in the code I posted.
> I've tried other ways and I honestly don't see the point of a "more realistic" proper IIR RC simulation for this particular job. It doesn't add anything, it's far more limited (does one curve and one curve only), and it takes as much or more calculation.
>
> But I'm willing to be convinced by good arguments!

Certainly true that the lookup table provides any curve that you care to set up.  But it doesn't give you an easy or natural way to make changes to the curve, or dynamically change parameters during the envelope.

The table lookup is more computationally intensive because you have to scale the curve for the size of your step, and you have to perform the interpolation, and that requires some accuracy.  The RC simulation is dead simple (one subtraction, one multiplication, accumulate), and because it's a feedback system the operations don't have to be very precise, it'll correct over time.

With the RC simulation, the parameters can change dynamically during the envelope, it's easy to mix some linear into the curve, it's easy to add slew limiting, and that can vary dynamically.  It's easy to throw nonlinearities into the curve, again dynamically.  So while the RC simulation can't do any curve, it can easily do some very interesting variations on the classic exponential curve.

It's more of a philosophical position, really.  You can either play back a spec'd curve, or you can go exploring with the mechanism that created the curve in the first place.  I'm biased toward the latter, but that's me.

-- Don

--
Don Tillman
Palo Alto, California
don at till.com
http://www.till.com

```