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

mskala at northcoastsynthesis.com mskala at northcoastsynthesis.com
Thu Nov 6 00:17:59 CET 2025


On Wed, 5 Nov 2025, Chris McDowell wrote:

> Woops, certainly meant to include thelink: https://www.musicdsp.org/en/latest/Synthesis/189-fast-exponential-env
> elope-generator.html
> and yes, their usage of log() is just about calculating the rate. 
>
> your version looks to be functionally the same as the one in the link, one
> multiply and one add. my version has a subtract in there that I apparently
> don't need and this is, of course, why I asked :) 

Well, I think what's at that link is not quite the same thing because it's
making the rate proportional to the current level, whereas both the
equation you first posted, and mine, make the rate proportional to the
*difference* between the current level and the target, like a charging
capacitor.  Those are only the same thing in the case of a decay heading
for zero.

In particular, with the iteration I described, an envelope going from zero
up to a peak for an attack would go first fast then slow, like a charging
capacitor, whereas the link's version when going up would go first slow,
then fast, and wouldn't work at all for really starting at exactly zero.
Whenever currentLevel is zero, either version of the musicdsp.org code
(with += and *, or just *=) will keep it permanently at zero.

Probably a good idea to think carefully about what shape you actually want
the output to take.

-- 
Matthew Skala
North Coast Synthesis Ltd.


More information about the Synth-diy mailing list