[sdiy] Help with math, please

Olivier Gillet ol.gillet at gmail.com
Tue Aug 9 22:40:45 CEST 2011


> Thanks everyone! I think Oliver's formula is what I need. I just did some spreadsheet simulation and it looks good.
>
> Now the only question is: can I get away with 32-bit math or do I have to do floating point to make this work. I'll code it up tonight and see.

I've got this to work in the past using a 16--0 bits accumulator and
0--16 bits for the factor (which is always below 1). So this sets a
limit on the slowest envelope you can reach and on the precision with
which you can reach a particular slow time. The sample rate I was
using was 1378 Hz, so I could have 2% of error for times in the second
range (eg if I wanted RC = 4.0s, the multiplicative in the update
equation was 1.0 / 1378 / 4.0 * 65536 = 11.88 ; and once rounded to
12, this gives an actual RC of 3.96s).

Another thing: to avoid the situation where you get stuck with
accumulator != target because (target_value - accumulator) * Ts / RC
is null due to truncation, you need to round away from 0 (or use the
sign of target_value - accumulator when the whole  (target_value -
accumulator) * Ts / RC increment is null because of truncation).

Olivier



More information about the Synth-diy mailing list