How to make this infinite decay envelope (y=1/(x+1)^c curve) more CPU efficient?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

Max M. wrote: Mon Dec 03, 2018 8:12 pm Z1202
That's what I meant saying that b is the major source of precision loss.

Now I see what you mean. And I agree.

mikejm
What is the math to calculate k, a, b in this case? How do I graph it on desmos.com to confirm?

Roughly:
For `x[n] = a*x[n-1]` the impulse responce is `y = 1*a^n` (where n is number of iterations starting from 0)
For `x[n] = a*x[n-1] - b` it becomes `y = (1-b*n)*a^n`
and `n` -> `T in seconds` is obviously `n/sampleRate`.
E.g.:
https://www.desmos.com/calculator/cdjre0xvfq
https://www.desmos.com/calculator/2emxae2d6m

The rest depends on how exactly you're going to use it. Specifically if you need a separate "curve shape" parameter. In simple case we can for example choose values of the two curve points:
end point - to represent decay time,
some mid point - for its x or y value to specify the "curveness".
Then it becomes a usual "two-equations -> two-unknowns" solution.
Thanks max, but as noted by sonigen above those are c^x curves, and I want x^c, so recursion won't help me. Looks like the other optimizations already noted are as far as I can go.

Thanks all. This has been very instructive.

Post

2DaT wrote: Mon Dec 03, 2018 3:11 pm Replace pow(x,c) with exp(log(x)*c).
Well I implemented all the changes reviewed in this thread and it caused a dramatic drop in CPU usage so hugely successful.

The only thing I don't understand is this one (even though I did implement it).

So:

x^c = e^(ln(x)*c)
ln(x^c) = ln(x)*c

I get that.

But why is it cheaper to do e^(ln(x)*c) than just plain x^c?

Is C++ or the computer in general better "optimized" for base e calculations such that two base e calculations are cheaper than one non base e calculation?

Thanks.

Post

mikejm wrote: Tue Dec 04, 2018 3:22 am But why is it cheaper to do e^(ln(x)*c) than just plain x^c?

Is C++ or the computer in general better "optimized" for base e calculations such that two base e calculations are cheaper than one non base e calculation?

Thanks.
In floating point it's less precise that way. In order to maintain precision, pow function has to do some calculations in extra precision.

Post

mikejm wrote: Mon Dec 03, 2018 9:31 pm Thanks max, but as noted by sonigen above those are c^x curves, and I want x^c
Any particular reason for that? x^c curves for envelopes are rather uncommon I'd say (except for automation curves in some DAWs, no idea why they decided to do it that way)

Post Reply

Return to “DSP and Plugin Development”