exp(-2 * PI * X) approx

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

mistertoast wrote:"usualy in a VST the sample rate can't change"

Is that true? I've been wondering whether I'll need to watch for sample rate change messages in my VSTi.
It's not true, and you do need to watch for changes. I think it's an override of setSampleRate in VST.

Post

mistertoast wrote:"usualy in a VST the sample rate can't change"

Is that true? I've been wondering whether I'll need to watch for sample rate change messages in my VSTi.
No, I think you should be able to handle samplerate changes. There is a setSamplerate method after all. If you don't overload it, I think it will just update the samplerate variable from the base class.

I usually go like this:

Code: Select all

void VSTPlug::setSampleRate (float sampleRate)
{
	AudioEffectX::setSampleRate (sampleRate);
	myStuff->setSampleRate(sampleRate);
}

Post

I haven't thought about taking mine to assembly yet, but the C could look like this:

Code: Select all

float A = 0.44225212101E-01; 
float B = 0.83381933629E+00; 
float C = 0.23339518021E+01;

float t = B - X;
float t2 = t * t;
float out = A + t2 * t2 * t * C;
Swing is the difference between a drum machine and a sex machine.

Post

Rock Hardbuns wrote:
mistertoast wrote:"usualy in a VST the sample rate can't change"

Is that true? I've been wondering whether I'll need to watch for sample rate change messages in my VSTi.
No, I think you should be able to handle samplerate changes. There is a setSamplerate method after all. If you don't overload it, I think it will just update the samplerate variable from the base class.

I usually go like this:

Code: Select all

void VSTPlug::setSampleRate (float sampleRate)
{
	AudioEffectX::setSampleRate (sampleRate);
	myStuff->setSampleRate(sampleRate);
}
OK. I guess I'll deal with it if other VSTis do.
Swing is the difference between a drum machine and a sex machine.

Post

I am using the native int->float / float->int conversation of the CPU as starting point for the approximations for exp/log.

It gives you a very fast (but rough) approximation of 2^x and log2(x). You can gain higher accuracy with a polynomial approximation to shape the error close to the desired function.

It uses slightly more than your x^4 approximation, but it is also closer to the real values.

By scaling the formulas you can derive exp(a * x) or log10(x) or anything else. The order of the polynomial can change the accuracy ranging from very fast and rough to very close and slow. But even a very slow version can perform faster than the native exp() function, especially when only single accuracy is needed.

If you combine this with psychoacoustical listening tests, you can usually use even more rough approximations.

I'm on a vacation right now, but I'll post some formulas if I found the time next week.

Kind regards,

Christian

Post

Christian Budde wrote:I am using the native int->float / float->int conversation of the CPU as starting point for the approximations for exp/log.

It gives you a very fast (but rough) approximation of 2^x and log2(x). You can gain higher accuracy with a polynomial approximation to shape the error close to the desired function.

It uses slightly more than your x^4 approximation, but it is also closer to the real values.

By scaling the formulas you can derive exp(a * x) or log10(x) or anything else. The order of the polynomial can change the accuracy ranging from very fast and rough to very close and slow. But even a very slow version can perform faster than the native exp() function, especially when only single accuracy is needed.

If you combine this with psychoacoustical listening tests, you can usually use even more rough approximations.

I'm on a vacation right now, but I'll post some formulas if I found the time next week.

Kind regards,

Christian
Yeah, I've seen similar stuff. I'd like to see your code. There's this in the musicdsp archive...

http://www.musicdsp.org/showone.php?id=133
Swing is the difference between a drum machine and a sex machine.

Post

Just to give you a rough idea (PASCAL code):

Code: Select all

const
  CP2ContError3 : array [0..2] of Single = (
    6.93282526441610814E-1,
    2.42201488582370950E-1, 
    5.50043626970249666E-2);

function FastPower2ContinousError3(Value: Single): Single;
var
  IntCast : Integer absolute result;
begin
 IntCast := round(Value);
 Value := Value - IntCast;
 IntCast := ($7F + Intcast) shl 23;
 Result := Result * (1 +
            Value * (CP2ContError3[0] +
            Value * (CP2ContError3[1] +
            Value *  CP2ContError3[2])));
end;
This gives a continuous error around the real value. A similar "MinError" version can be found which might jump between the next rough steps of the processor based conversation.

In my open source project there are similar versions for Exp() /Log() and such with varying orders (in the above case it's a 3rd order polynomial).

I once wrote a paper about this approximations, but I kind of lost it somewhere on my HD (I guess I still have it, but can't remember the name/folder right now)

Christian

Post

I'm so tempted to start an approximations web page or blog and get opinions and papers from different people. Should I?
Swing is the difference between a drum machine and a sex machine.

Post

You guys are all a bunch of nerds..

I wish I could do all this cool stuff too :(

Post

rlahalla wrote:You guys are all a bunch of nerds..

I wish I could do all this cool stuff too :(
I gave up contact lenses and hiding my nerdiness once I got married.
Swing is the difference between a drum machine and a sex machine.

Post

mistertoast wrote:
rlahalla wrote:You guys are all a bunch of nerds..

I wish I could do all this cool stuff too :(
I gave up contact lenses and hiding my nerdiness once I got married.
:lol: I'm secretly envious of all your DSP nerdiness and am secretly determined to be just as nerdy very soon.. Well, guess it's not so secret, eh?

Post

You can get my whole approximation code here: http://delphiasiovst.svn.sourceforge.ne ... iew=markup

The unit is not formated as good as it could, but it should give you a clue.

Christian

Post

Christian Budde wrote:You can get my whole approximation code here: http://delphiasiovst.svn.sourceforge.ne ... iew=markup

The unit is not formated as good as it could, but it should give you a clue.

Christian
Thanks!
Swing is the difference between a drum machine and a sex machine.

Post

mistertoast wrote:Should I?
Yes.

Post

LOSER wrote:
mistertoast wrote:Should I?
Yes.
Finally someone agrees. I think I should lead with a post that links to Christian's file. :-)
Swing is the difference between a drum machine and a sex machine.

Post Reply

Return to “DSP and Plugin Development”