# [sdiy] Fast envelope generation

Donald Tillman don at till.com
Tue Dec 18 20:06:42 CET 2012

```Gentlemen,

Perhaps I'm misunderstanding something, but it looks like everyone is trying way, way too hard to do something very simple.  So, Gordon, could you restate the problem a little more clearly and completely?

It sounds to me that you're trying to digitally simulate the exponential RC curves that go from one step to another in an ADSR.  Is that right?  And that the exponential calculation is expensive on the device you are using.  Is that right?

And Tom, is your approach to the problem a lookup table for the curve?

Note that the ADDSR rise and fall curves aren't intentionally exponential; it's a side effect of the way an RC circuit charges and discharges.  As the voltage on a cap rises, the difference between the source voltage and the cap voltage is less, and thus the charging current through the resistor is less, so the voltage rises slower.  Repeat.  So all you really need to do is duplicate that process: on each iteration take the difference between the source voltage and cap voltage, scale that by the time constant, and add that to the cap voltage each time.

Or am I missing something?

-- Don

On Dec 18, 2012, at 2:54 AM, Tom Wiltshire wrote:

> On 18 Dec 2012, at 01:05, Gordon JC Pearce wrote:
>
>> 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?
>
> This is my own example of exactly what you're talking about:
>
> 	http://www.electricdruid.net/index.php?page=projects.envgen7
>
> 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.

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

```