I have the following code snippet for single cycle wave interpolation and resampling.
if i hard reset the counter I get absolutely no aliasing.
It resamples perfectly 5 octaves up with no mip mapping required
if( counter >= len) {
counter = 0;
}
If i wrap the counter I get tons of artifacts like amplitude modulation and phasiness and need for mip mapping possibly
if( counter >= len) {
counter %= len;
}
Any idea which is correct?
I would prefer:
if( counter >= len) {
counter = 0;
}
as its so much easier
counter is 32.32 fixed point counter.
Code: Select all
float up(Sample * sample) {
auto len = static_cast<uint64_t>(sample->getLength()) << 32;
auto buf = sample->getBuffer().getArrayOfReadPointers();
int ixflt = ((counter) >> 26) & 0x3F;
float t = ((counter) & 0x3FFFFFF) * 0x1p-26;
float *y0 = imp + ixflt*12;
float *y1 = y0 + 12;
long long j = counter >> 32;
float y = 0;
float x0 = 0;
float x1 = 0;
for(int i=0; i < 12; i++)
{
long long idx = j+i-5;
if(idx < 0) {
idx+=sample->getLength();
}
if(idx >= sample->getLength()) {
idx -= sample->getLength();
}
float se = buf[0][idx];
float x = se;
x0 += *y0++*x;
x1 += *y1++*x;
}
y = x0 + (x1-x0)*t;
counter += deltaup;
if( counter >= len) {
counter = 0;//counter%len;
}
return y;
}
