Blog / Development

"BLEP, MinBLEP, PolyBLEP: How Soft Synths Hide Their Aliasing"

Write a sawtooth oscillator the obvious way — increment a phase from 0 to 1, output 2 * phase - 1, wrap around — and you have produced one of the noisier signals in digital audio. Tune it to 220 Hz and it sounds correct. Tune it to 2200 Hz and the harmonics that should have lived above Nyquist instead fold back down into the audible band as sour, inharmonic partials that drift in pitch as you sweep the oscillator. This is aliasing, and it is the reason why naive software oscillators sound nothing like the analog hardware they pretend to emulate.

The fix is one of the most elegant tricks in audio DSP. It is called BLEP, it costs almost nothing, and once you understand the underlying idea you understand why every credible soft synth from Diva to Serum to Vital uses some variant of it.

Why a Sawtooth Aliases in the First Place

An ideal sawtooth is a discontinuity that resets every cycle. In the frequency domain, that vertical jump produces a harmonic series that extends to infinity: amplitude 1/n at every integer multiple n of the fundamental. The frequencies above your sample rate's Nyquist limit cannot be represented, so they reflect — a 30 kHz harmonic at 44.1 kHz sample rate becomes an audible 14.1 kHz tone, and crucially that aliased frequency is not harmonically related to the fundamental. As you sweep the oscillator pitch upward, aliased partials sweep downward. Your ear hears it instantly.

The naive solution — render at 8x oversampling, lowpass filter, decimate — works, but the CPU cost is roughly proportional to the oversampling factor. For a polysynth with 16 voices and three oscillators each, that adds up fast.

The Insight: Correct the Discontinuity, Not the Whole Signal

Stilson and Smith published the foundational paper at ICMC 1996, Alias-Free Digital Synthesis of Classic Analog Waveforms. Their observation was that the aliasing in a sawtooth comes entirely from the discontinuity at the wrap point. Between resets, the ramp itself is a perfectly bandlimited signal — its derivative is constant. The energy that aliases lives only in the instant where the waveform jumps from +1 back to -1.

So instead of bandlimiting the entire waveform, bandlimit only the discontinuity.

A perfect bandlimited step (the response of an ideal lowpass filter to a unit step) is a Si(x) function — the running integral of a sinc. It rings symmetrically before and after the step. In a real oscillator, you cannot generate the entire infinite ringing response, so you store a windowed version: a few dozen samples of the bandlimited step, sampled at much higher resolution than your audio rate, and look up the values you need.

The trick is what you do with that table. At every step discontinuity in your naive sawtooth, you take the difference between the ideal bandlimited step and a perfect mathematical step — call this the BLEP residual — and add it to your output samples around the discontinuity. The naive ramp is already bandlimited between discontinuities, and the BLEP residual exactly corrects what would have aliased at the jump.

You are not replacing the waveform. You are surgically patching it.

MinBLEP: When Latency Is the Problem

The original Stilson-Smith BLEP is symmetric — its ringing extends both before and after the step. That means you need to delay your entire signal by half the BLEP table length, because you have to add ringing to samples that come before the discontinuity actually happens. For a 32-sample BLEP, that is 16 samples of latency on every voice.

Eli Brandt fixed this in 2001 with MinBLEP. The idea: take the symmetric BLEP, and apply minimum-phase reconstruction to it. The ringing is now entirely after the discontinuity. No look-ahead is needed, and the spectral magnitude is preserved — only the phase changes. For an oscillator, where you do not care about phase coherence between transients, this is essentially free.

MinBLEP is what you find inside many commercial soft synths. The table is precomputed at startup (typically 4096 to 16384 samples representing a 16- or 32-sample BLEP at 256x or 512x oversampling), and at runtime you just index into it whenever a discontinuity happens.

PolyBLEP: Throwing Away the Table

MinBLEP is excellent but it has two costs: the lookup table and the slight cache-miss penalty when you hit it. For lightweight oscillators, even that is more than necessary.

Välimäki and others popularized the PolyBLEP approach: approximate the BLEP residual with a low-order polynomial. The most common formulation is a 2nd-order polynomial that operates on just two samples — the one immediately before the discontinuity and the one immediately after. The math is roughly:

t = phase / phaseIncrement   // 0 < t < 1, fractional position of the jump
if t < 1:
    output += t*t/2 + t + 0.5     // sample after the jump
else:
    output -= (2-t)*(2-t)/2       // sample before the jump

That is it. No table, no oversampling, two arithmetic operations per affected sample. The aliasing rejection is not as good as a long MinBLEP — you still get measurable aliasing above about 8 kHz at high oscillator pitches — but for the CPU budget it is an outstanding deal. Vital, Surge, and many indie synths use PolyBLEP for their basic shapes.

What This Means for Other Waveforms

Square waves are two BLEPs per cycle (one up, one down). Triangle waves are slightly trickier — they have no discontinuity in the waveform itself, but their first derivative is discontinuous at the peaks. The fix is BLAMP (Band-Limited rAMP), which is the integral of BLEP. Same idea, applied one derivative level higher.

Hard sync, supersaw detuning, and PWM all generate additional discontinuities that need their own BLEPs. The bookkeeping gets fiddly but the principle never changes: find every place the signal or its derivative jumps, and patch each one.

The Practical Takeaway

If you are building an oscillator and your spectrum analyzer shows aliased partials sweeping in the wrong direction when you bend the pitch up, you have three honest options:

  1. PolyBLEP if CPU is tight and the synth will mostly play in the lower three octaves. Cheap, simple, audible aliasing only at the top end.
  2. MinBLEP if you want production-grade quality across the full range. Precompute a table, accept the small lookup cost.
  3. Heavy oversampling if you need analytically perfect output and CPU does not matter — useful for offline rendering, rarely the right choice for real-time.

The thing that is not a real option is the naive oscillator. The five-line version that compiles is an acoustic lie. Once you have heard a true bandlimited sawtooth next to its naive cousin, you cannot un-hear the difference.

References

  • Stilson, T. & Smith, J. O. (1996). Alias-Free Digital Synthesis of Classic Analog Waveforms. ICMC Proceedings. The foundational BLIT/BLEP paper, available via Stanford CCRMA.
  • Brandt, E. (2001). Hard Sync Without Aliasing. ICMC Proceedings. Introduces MinBLEP.
  • Välimäki, V. & Huovilainen, A. (2007). Antialiasing Oscillators in Subtractive Synthesis. IEEE Signal Processing Magazine. Survey paper covering PolyBLEP and related techniques.