I've tried to implement anti aliasing on a simple Saw, using minBLEP. I wonder if somebody could correct my code because the current output aliases like crazy and has a very strange spectrum, as shown below
So, in my oscillator's constructor I have the following, using Daniel's 'GenerateMinBLEP' with 24 zero crossings and 32 oversampling, giving minBLEP data 1537 in length with a circular buffer 48 in length :
Code: Select all
circularBuffer = new float[48];
for (int i = 0; i < 48; i++)
{
circularBuffer[i] = 0.0f;
}
minBlep = GenerateMinBLEP(24, 32);
nextSample looks like this:
Code: Select all
#define LERP(A,B,F) ((B-A)*F+A)
double MinBlepOsc::nextSample() {
mPhase += mPhaseIncrement;
index = (index+1)%48;
while(mPhase >= 1.0)
{
mPhase -= 1.0;
double exactCrossTime = 1.0-((mPhaseIncrement-mPhase)/mPhaseIncrement);
for(int i = 0; i < 47; i++)
{
double tempIndex = (exactCrossTime*32.0)+(i*32.0);
double tempFraction = tempIndex-floor(tempIndex);
circularBuffer[(index+i)%48] += (1.0-LERP(tempFraction, minBlep[(int)floor(tempIndex)], minBlep[(int)ceil(tempIndex)]));
}
}
circularBuffer[index] += (mPhase-mPhaseIncrement);
double output = 1.0*circularBuffer[index];
circularBuffer[index] = 0.0;
return output;
}
Cheers, Dave