[sdiy] Help with math, please

Scott Nordlund gsn10 at hotmail.com
Tue Aug 9 22:20:53 CEST 2011


> 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

Envelope generators can have some tricky peculiarities. What you're trying to do is make something that asymptotically approaches the destination value, like an analog envelope generator. That's sometimes less than desirable, because it never really gets there. An alternative is to put the linear envelope through an exponential-like function. x^4 works fairly well for this, and is easy to implement (called a quartic envelope, at least by Miller Puckette). Making something too close to a real exponential can make longer attacks sound weird, sort of delayed and "reversed" (the DX7 always annoyed me this way). x^4 seems to work a little better. If you just shape the linear envelope this way, it won't (in the general case) slow down as it approaches the destination value, but if you use an asymptotic envelope, the exponential decay won't always be with respect to zero, so it's not going to make a nice curve in dB. Whatever you do, it's sort of a weird set of compromises. I generally prefer to have the envelope reach its destination in finite time, to facilitate multi-stage envelopes. If I want the asymptotic smoothing of an analog style envelope, an easy fix is to just follow the whole thing with a lowpass filter, though this will have a fixed time constant over the envelope's progression... 		 	   		  


More information about the Synth-diy mailing list