[sdiy] Soft ADSR ways?
Richie Burnett
rburnett at richieburnett.co.uk
Mon Feb 14 12:14:13 CET 2011
That technique of squaring x to get an approximate exponential shape is
certainly useful for changing a linear pot characteristic into a
"logarithmic pot" characteristic for software volume controls etc. After
all most people adjust a volume control by ear rather than relying on it
having perfect exponential conformance.
For envelopes, if you have the resources to do a multiply and shift you
might as well implement the envelope generator as a first-order IIR filter.
This models the exponential charge and discharge you get with a 1st order RC
circuit...
new_y = old_y + c * (input - old_y)
Where "input" is the level you want to tend towards, and the value "c" sets
the exponential time constant. You can change the value of c on-the-fly
depending on whether the target level "input" is above or below the current
level "old_y". This allows you to set different attack, decay and release
time constants. You don't need any look-up tables or interpolation. You
just need to make sure you use a sufficient number of bits to store the
current level "old_y".
Also if you do choose to use a look-up table for expo function shape, you
only need to store one octave's worth (one half-life if you prefer!) of the
expo function in the lookup table. So for instance you could store the
release part of an envelope where it decays from an amplitude of 1 to 0.5 in
a LUT. You then repeatedly replay this section, each time with one more
binary right shift. This gives 0.5 to 0.25, then 0.25 to 0.125, etc, etc...
This greatly saves LUT space, as the decaying expo theoretically takes
forever to decay away completely to zero!
I hope this helps,
-Richie,
> can I make a suggestion?
>
> a square function is a lot less CPU intensive than an expo function.
> to the ear, there's very little different between a square and an expo.
>
> I'd suggest using a square, then halve it.
>
> X *= X;
> X >>=1 ;
>
> Paul
More information about the Synth-diy
mailing list