|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Shared minimum-phase band-limited step (minBLEP) residual table. More...
#include <MinBlepTable.h>
Public Member Functions | |
| T | residual (T t) const noexcept |
Residual of the minimum-phase band-limited step at position t. | |
| void | addStep (T *ring, int head, T jump, T frac) const noexcept |
Adds jump * residual(j + frac) to ring[(head + j) & (kTaps - 1)] for every tap j. | |
| void | addDelayedStep (T *ring, int head, T jump, T frac) const noexcept |
| Step correction for a waveform rendered dcDelay() samples late. | |
| void | addDelayedRamp (T *ring, int head, T slopeJump, T frac) const noexcept |
| Slope-change (kink) correction for a waveform rendered dcDelay() samples late: the minimum-phase band-limited ramp (minBLAMP) minus the ideal ramp delayed by dcDelay(). | |
| T | dcDelay () const noexcept |
| Low-frequency delay of the minimum-phase step, in samples. | |
Static Public Member Functions | |
| static const MinBlepTable & | instance () noexcept |
| Returns the process-wide shared table, building it on first call. | |
Static Public Attributes | |
| static constexpr int | kTaps = 128 |
| Correction span in base-rate samples (power of two, ring-buffer friendly). | |
| static constexpr int | kPhases = 2048 |
| Sub-sample resolution: rows per sample, linearly interpolated. | |
| static constexpr int | kOversample = kPhases |
| Sub-sample positions per output sample (the same resolution). | |
| static constexpr int | kTableSize = kTaps * kOversample + 1 |
| Points of the residual's domain [0, kTaps] at that resolution. | |
Shared minimum-phase band-limited step (minBLEP) residual table.
A discontinuity rendered naively into a sample stream aliases. The classic fix is to replace the ideal step with a band-limited one; the minimum-phase variant (Brandt, ICMC 2001) concentrates all of its energy at and after the discontinuity, which has two practical consequences:
Design, each choice measured on free-running saws and pulses at 44.1 and 48 kHz (worst inharmonic component below 20 kHz, 110 Hz to 14 kHz):
Measured floors: -145 dB or better from 110 Hz to 14 kHz at 48 kHz and 44.1 kHz, against -89 to -121 dB for the previous table.
Usage – for a discontinuity of amplitude jump occurring frac samples before output sample n (frac >= 0), add jump * residual(j + frac) to output sample n + j for j = 0 .. kTaps - 1; addStep() does exactly that into a ring buffer. The naive signal must already contain the raw step.
prepare() – never from the audio thread. After construction the table is immutable and lock-free to read from any thread. The build is noexcept by design: an allocation failure during it terminates (fail-fast; the only caller path is a noexcept prepare() anyway).| T | Sample type (float or double). Table generation always runs in double precision internally. |
Definition at line 89 of file MinBlepTable.h.
|
inlinenoexcept |
Slope-change (kink) correction for a waveform rendered dcDelay() samples late: the minimum-phase band-limited ramp (minBLAMP) minus the ideal ramp delayed by dcDelay().
| ring | A kTaps-long ring of pending corrections. |
| head | Ring slot of the output sample the correction starts at. |
| slopeJump | Change of the derivative at the event, per sample (new slope minus old slope). |
| frac | Time from the event to the ring's head sample (>= 0). |
Unlike a ramp correction against the undelayed ideal ramp, which tends to -dcDelay() * slopeJump and cannot be truncated, this one settles at exactly 0 at the kernel's end.
Definition at line 183 of file MinBlepTable.h.
|
inlinenoexcept |
Step correction for a waveform rendered dcDelay() samples late.
A generator that evaluates its whole naive waveform dcDelay() samples in the past (so its smooth segments line up with the band-limited steps and ramps) corrects a jump of the CURRENT waveform with the band-limited step minus the step delayed by dcDelay(): the residual plus 1 before dcDelay(). The jump is still timed at the event.
Definition at line 162 of file MinBlepTable.h.
|
inlinenoexcept |
Adds jump * residual(j + frac) to ring[(head + j) & (kTaps - 1)] for every tap j.
| ring | A kTaps-long ring of pending corrections. |
| head | Ring slot of the output sample the correction starts at. |
| jump | Signed discontinuity amplitude (new value minus old). |
| frac | Time from the event to that output sample, in samples (>= 0; ages of kTaps or more add nothing). |
Definition at line 148 of file MinBlepTable.h.
|
inlinenoexcept |
Low-frequency delay of the minimum-phase step, in samples.
Equals minus the integral of the residual: the band-limited step completes its rise about this much later than the ideal step it replaces. A generator that adds the residuals to a naive waveform must delay the waveform's continuous (sloped) segments by the same amount, i.e. subtract slope * dcDelay(): otherwise every jump contributes jump * -dcDelay() of area, a DC offset of 2 * dcDelay() * f0 / fs on a sawtooth.
Definition at line 201 of file MinBlepTable.h.
|
inlinestaticnoexcept |
Returns the process-wide shared table, building it on first call.
Thread-safe (C++11 magic static). The one-time build performs FFTs and temporary allocations – touch it from prepare(), not the audio thread.
Definition at line 109 of file MinBlepTable.h.
|
inlinenoexcept |
Residual of the minimum-phase band-limited step at position t.
| t | Time since the discontinuity, in samples (fractional). Values below 0 or at and beyond kTaps return 0 (the step has settled). |
minBlepStep(t) - 1 – starts near -1 right at the event (the band-limited transition has barely begun) and decays to exactly 0 at the end of the table. Definition at line 124 of file MinBlepTable.h.
|
staticconstexpr |
Sub-sample positions per output sample (the same resolution).
Definition at line 99 of file MinBlepTable.h.
|
staticconstexpr |
Sub-sample resolution: rows per sample, linearly interpolated.
Definition at line 97 of file MinBlepTable.h.
|
staticconstexpr |
Points of the residual's domain [0, kTaps] at that resolution.
Definition at line 101 of file MinBlepTable.h.
|
staticconstexpr |
Correction span in base-rate samples (power of two, ring-buffer friendly).
Definition at line 95 of file MinBlepTable.h.