So, recently I have been experimenting with polyBLEPS a little bit.
I tried to implement the algorithm described in this blog: http://www.martin-finke.de/blog/arti...ep-oscillator/ into the Audio library.
It hurts a little bit to contaminate the highly optimized Audio Library with float calculations, but the Teensy 4.0 is fast enough to hande these.
For anyone, who wants to try this out, here is what I've done:
I added a polyblep method to the top of the waveform.cpp file:
Code:
int16_t polyblep(uint32_t phase, uint32_t inc, int32_t magnitude){
//0 <= t < 1
if (phase < inc){
float t = (float) phase/inc;
return (int16_t) magnitude * (t*t - t+t - 1.0);
}else{
//-1 < t < 0
if(phase > (4294967296 - inc) ){
float t = (float) (phase - 4294967296) /inc;
return (int16_t) magnitude * (t*t + t+t + 1.0);
}else{
return 0;
}
}
}
then, in AudioSynthWaveformModulated::update(void) (since I work with modulated oscillators on my synth), I modified the Square and Sawtooth waveforms:
Code:
case WAVEFORM_SQUARE:
magnitude15 = signed_saturate_rshift(magnitude, 16, 1);
for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
if (phasedata[i] & 0x80000000) {
*bp = -magnitude15;
*bp += polyblep(phasedata[i], inc, magnitude15);
*bp++ -= polyblep(phasedata[i] + 0x80000000, inc, magnitude15);
} else {
*bp = +magnitude15;
*bp += polyblep(phasedata[i], inc, magnitude15);
*bp++ -= polyblep(phasedata[i] + 0x80000000, inc, magnitude15);
}
}
break;
case WAVEFORM_SAWTOOTH:
magnitude15 = signed_saturate_rshift(magnitude, 16, 1);
for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
*bp = signed_multiply_32x16t(magnitude, phasedata[i]);
*bp++ -= polyblep(phasedata[i]+ 0x80000000, inc, magnitude15);
}
break;
It turns out, that the aliasing is reduced somewhat, but the algorithm also kills high harmonics.
So I will use it, when (lowpass-) filtering my signal while playing in high octaves. For lower octaves and less filtering, the benefit of the reduced aliasing is (in my opinion) not worth it, since the high harmonics are sometimes wanted (well, depends on your musical taste).
For anyone who wants to dig deeper into the Topic of polyBLEPS or anti-aliasing in general, the guys on kvraudio have lots of helpful threads there.