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

mskala at northcoastsynthesis.com mskala at northcoastsynthesis.com
Wed Nov 5 23:48:03 CET 2025


On Wed, 5 Nov 2025, Chris McDowell via Synth-diy wrote:

> output += (target - output) * rate 

> 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 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

I don't know what the "similar strategy" you have in mind is.  The way
I'm familiar with doing this kind of moving average looks like:

output += (target*rate)
output *= 1/(1+rate)

You precalculate target*rate when you change the target, and 1/(1+rate)
when you change the rate, so it's one add and one multiply, of stored
constant values, per ordinary iteration.

I'm not sure how log() would come into it - maybe if you're trying to
choose the rate based on a desired length of time to charge or discharge
to a certain point, but that's no more true here than in the original
iteration.

-- 
Matthew Skala
North Coast Synthesis Ltd.


More information about the Synth-diy mailing list