[sdiy] software / firmware envelopes in C (or anything else)

Roman Sowa modular at go2.pl
Thu Nov 6 10:00:15 CET 2025


What you say here:
output += (target - output) * rate
is basicaly digital representation of RC network, the core of any analog 
envelope. Who needs anything better if it's simple enough.

Anyway, I do it exactly like in your equation. Target is changing 
between 0, full scale and sustain level, depending on ADSR phase.
All done in fixed point math, but 24 bits is a must, as 16-bit 
truncation errors spoil the ends of decaying phases.
I also thought about doing it for decades, but when finally did it, I 
couldn't understand why I waited so long, as the code turned out to be 
pretty simple. All done in 8-bit PIC micro in assembler.
I don't use any log or other advanced math, I take rate values from look 
up table.

Roman

W dniu 2025-11-05 o 22:55, Chris McDowell via Synth-diy pisze:
> Howdy list,
>
> I've been thinking about this for about a decade. I use what the web 
> calls a "leaky integrator" all over my synth code. I first used it as 
> the basis of an envelope some 15 years ago when mimicking the Moog 
> Rogue's strategy of providing a target and a "rate" to a lowpass 
> filter built around a 3080 OTA. On an MCU with an FPU, it works pretty 
> much great. the basics:
>
> output += (target - output) * rate
>
> where target changes based on what stage of an envelope we're in and 
> rate is some small float coefficient calculated based on desired stage 
> length in milliseconds.
>
> my question for this deep well of synth experience: is there a better 
> way to do it? I came across a similar strategy on musicdsp.org 
> <http://musicdsp.org> recently that suggested baking the target into 
> the coefficient, which does indeed save one subtract per iteration 
> with the tradeoff that you have to do more math when changing envelope 
> states. its use of log() (admittedly infrequently) makes me not all 
> that interested, even if that's maybe a little irrational. If I find 
> myself num_envelopes cycles away from meeting a timing deadline, I'll 
> consider it...
>
> I'm familiar with Tom Wiltshire's envelope chip, which is another cool 
> and very different strategy. What else is out there?!
>
> Cheers,
> Chris McDowell
>
> ________________________________________________________
> This is the Synth-diy mailing list
> Submit email to: Synth-diy at synth-diy.org
> View archive at: https://synth-diy.org/pipermail/synth-diy/
> Check your settings at: https://synth-diy.org/mailman/listinfo/synth-diy
> Selling or trading? Use marketplace at synth-diy.org



More information about the Synth-diy mailing list