[sdiy] Help with math, please
Tom Wiltshire
tom at electricdruid.net
Tue Aug 9 23:53:30 CEST 2011
Hi Tim,
My advice when programming lightweight chips like a lot of us use would be "Don't do hard maths - at all".
Anything more taxing than a multiplication might be better calculated beforehand and done using a lookup table instead, if at all possible.
For your envelope generator, you can use your linear value as an index into a "exponential curve" lookup table and get the required value out quickly and easily. If necessary, interpolation can be used between table entries to prevent stepping and provide a piecewise-linear approximation to the required curve. As a side-benefit, this method works for arbitrary curves, so you can easily alter your envelope generator to tweak the response, or provide responses which aren't available on standard envelopes.
I'm not trying to disagree with everyone else (who've all given entirely valid answers), but I thought someone should point out that actually solving the equations isn't always the best policy when programming.
Regards,
Tom
On 9 Aug 2011, at 17:18, Tim Ressel wrote:
> Hi,
>
> Okay, I admit it: math is not my strong suit, and I need help with a problem. I am trying to program a cv envelope generator with exponential and linear curves. The linear part works just fine, but I am having a real hard time wrapping my neurons around the exponential part.
>
> The way I've implemented the code is this: there is an accumulator that values get added or subtracted to at each time slice, which is 1ms currently. An ADC value adjusts the amount that gets added. In the case of the exponential curve I am trying to use the RC time constant equation to calculate the value to add to the accumulator. The thing is, the RC time constant formula calculates from time zero, and I need an incremental value. So given the current accumulator value (analogous to voltage on the cap) and the current ADC value (the RC value) I need an equation that gives an increment value to add to the accumulator.
>
> Any math whizzes out there that can help?
>
> Thanks in advance,
>
> --TimR
>
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at dropmix.xs4all.nl
> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
More information about the Synth-diy
mailing list