Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
polyblep.hpp
Go to the documentation of this file.
1// sbl/dsp/polyblep.hpp — Polynomial band-limited step (Audio Stack — Atoms)
2//
3// PolyBLEP correction for band-limited waveform synthesis.
4//
5// Two function pairs:
6// this_blep / next_blep — correct step discontinuities (saw, square)
7// this_integrated_blep / next_integrated_blep — correct slope
8// discontinuities (triangle, variable-slope ramps)
9//
10// Adapted from Mutable Instruments stmlib/dsp/polyblep.h (MIT license).
11// Copyright 2017 Emilie Gillet.
12//
13// Usage (step discontinuity — saw reset):
14// float t = phase_overshoot / frequency;
15// this_sample -= this_blep(t);
16// next_sample -= next_blep(t);
17//
18// Usage (slope discontinuity — triangle inflection):
19// float discontinuity = (slope_up + slope_down) * frequency;
20// this_sample -= this_integrated_blep(t) * discontinuity;
21// next_sample -= next_integrated_blep(t) * discontinuity;
22
23#pragma once
24
26
27// --- Step BLEP (2nd-order) — for value discontinuities ---
28
29/// Correction for the current sample at a step discontinuity.
30/// t = normalized time since discontinuity (phase overshoot / frequency).
31inline float this_blep(float t) {
32 return 0.5f * t * t;
33}
34
35/// Correction for the next sample at a step discontinuity.
36inline float next_blep(float t) {
37 t = 1.0f - t;
38 return -0.5f * t * t;
39}
40
41// --- Integrated BLEP (4th-order) — for slope discontinuities ---
42
43/// Correction for the next sample at a slope discontinuity.
44/// 4th-order polynomial: antiderivative of the quadratic BLEP.
45/// Multiply by (slope_up + slope_down) * frequency to get the actual correction.
46inline float next_integrated_blep(float t) {
47 const float t1 = 0.5f * t;
48 const float t2 = t1 * t1;
49 const float t4 = t2 * t2;
50 return 0.1875f - t1 + 1.5f * t2 - t4;
51}
52
53/// Correction for the current sample at a slope discontinuity.
54inline float this_integrated_blep(float t) {
55 return next_integrated_blep(1.0f - t);
56}
57
58} // namespace sbl::dsp::polyblep
Band-limited oscillator corrections.
Definition polyblep.hpp:25
float next_integrated_blep(float t)
Definition polyblep.hpp:46
float this_integrated_blep(float t)
Correction for the current sample at a slope discontinuity.
Definition polyblep.hpp:54
float this_blep(float t)
Definition polyblep.hpp:31
float next_blep(float t)
Correction for the next sample at a step discontinuity.
Definition polyblep.hpp:36