Just like (min)BLEPs, the basic idea of polyBLEPs is that you calculate a naive (non-bandlimited) waveform, and you then correct it at the transients. However, unlike minBLEPs you don't need an extra large precomputed table for this, you just caclulate a trivial polynomial, and you only do this for two(!) samples per transient. Check this out:
Code: Select all
double t = 0.; // 0 <= t < 1
double dt = freq / sample_rate;
...
double poly_blep(double t, double dt)
{
// 0 <= t < 1
if (t < dt)
{
t /= dt;
// 2 * (t - t^2/2 - 0.5)
return t+t - t*t - 1.;
}
// -1 < t < 0
else if (t > 1. - dt)
{
t = (t - 1.) / dt;
// 2 * (t^2/2 + t + 0.5)
return t*t + t+t + 1.;
}
// 0 otherwise
else
{
return 0.;
}
}
double poly_saw(double t, double dt)
{
// Correct phase, so it would be in line with sin(2.*M_PI * t)
t += 0.5;
if (t >= 1.) t -= 1.;
double naive_saw = 2.*t - 1.;
return naive_saw - poly_blep(t, dt);
}
...
for (int i = 0; i < nFrames; ++i)
{
output[i] = poly_saw(t, dt);
t += dt;
}
Using the code above you can also create other waveforms, either directly (square, pulse), or by integrating other waveforms (square/pulse for triangle, saw for full-wave rectified sine).
Because PolyBLEPs are quasi-bandlimited, there will be some audible aliasing, especially when the fundamental approaches the Nyquist frequency. This is because the polynomial doesn't produce a clean sine. At 44.1 or 48 kHz this may be a problem, but this could be fixed by crossfading to a actual sine wave or to a brute-force Fourier series waveform. At higher sample rates this problem should fix itself, because the fundamental frequency will be way out of audible range before it approaches Nyquist.
PolyBLEPs attenuate higher harmonics slightly too much, so they might sound slightly dull, but again, this will probably only be audible at lower sample rates. (That being said, I have rejected polyBLEPs for Combo Model V for this very reason. That, and because in my case it was only marginally faster than BLITs.)
For those running REAPER (or ReaJS): I have a demo synth in JS that uses polyBLEPs:
Discussion/download:
http://forum.cockos.com/showthread.php?t=108288
Lame audio demo:
http://www.taletn.com/reaper/mono_synth.mp3
Slighty less lame audio demo:
http://www.taletn.com/reaper/poly_blep.mp3