DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::MinBlepTable< T > Class Template Reference

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.
 

Detailed Description

template<typename T>
class dspark::MinBlepTable< T >

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:

  • Causal correction – the residual is zero before the event, so no look-ahead, no pre-ringing, and no kernel halves that must be predicted or un-queued when events collide (the failure mode that makes 2-point PolyBLEP hard-sync bookkeeping delicate).
  • Long kernel for free – since nothing precedes the event, the kernel can be long without adding latency. Its cost is per discontinuity, not per sample.

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):

  • 128 taps, Kaiser window (beta 13, about -127 dB stopband), cut at Nyquist. The transition band then ends near 23.4 kHz at 44.1 kHz, below fs - 20 kHz, so nothing a sweep leaves partially attenuated folds below 20 kHz. The previous 64-tap Blackman-Harris kernel let the harmonics between 24.1 and 24.8 kHz through partially: -95 dB at 440 Hz / 44.1 kHz, landing at 19.5 kHz.
  • 2048 sub-sample phases. Linear interpolation between adjacent rows leaves an error that falls 12 dB per doubling; the previous 64 positions capped the floor at -94 dB (9 kHz / 48 kHz), and 2048 reach -145 dB. The minimum-phase step is built on a 64-position grid (a 2^17 FFT) and refined to the fine grid with Niemitalo's optimal 6-point, 5th-order interpolator for 32x oversampled data: the step is band-limited to the base Nyquist, 64 times below the coarse grid's, so the refinement adds no measurable error and costs milliseconds instead of a 2^22 FFT.
  • Polyphase rows in float. Row q holds the residual at j + q / kPhases for every tap j, so a discontinuity reads two contiguous rows: cache friendly and vectorisable. Float storage keeps the table at 1 MB; its rounding (-150 dB) is below the interpolation floor.

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.

Note
instance() builds the table on first call (FFT work, about 1 MB of table and transient buffers). Call it once from a control thread – e.g. inside 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).
Template Parameters
TSample type (float or double). Table generation always runs in double precision internally.

Definition at line 89 of file MinBlepTable.h.

Member Function Documentation

◆ addDelayedRamp()

template<typename T >
void dspark::MinBlepTable< T >::addDelayedRamp ( T *  ring,
int  head,
T  slopeJump,
T  frac 
) const
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().

Parameters
ringA kTaps-long ring of pending corrections.
headRing slot of the output sample the correction starts at.
slopeJumpChange of the derivative at the event, per sample (new slope minus old slope).
fracTime 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.

◆ addDelayedStep()

template<typename T >
void dspark::MinBlepTable< T >::addDelayedStep ( T *  ring,
int  head,
T  jump,
T  frac 
) const
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.

◆ addStep()

template<typename T >
void dspark::MinBlepTable< T >::addStep ( T *  ring,
int  head,
T  jump,
T  frac 
) const
inlinenoexcept

Adds jump * residual(j + frac) to ring[(head + j) & (kTaps - 1)] for every tap j.

Parameters
ringA kTaps-long ring of pending corrections.
headRing slot of the output sample the correction starts at.
jumpSigned discontinuity amplitude (new value minus old).
fracTime 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.

◆ dcDelay()

template<typename T >
T dspark::MinBlepTable< T >::dcDelay ( ) const
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.

◆ instance()

template<typename T >
static const MinBlepTable & dspark::MinBlepTable< T >::instance ( )
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.

◆ residual()

template<typename T >
T dspark::MinBlepTable< T >::residual ( T  t) const
inlinenoexcept

Residual of the minimum-phase band-limited step at position t.

Parameters
tTime since the discontinuity, in samples (fractional). Values below 0 or at and beyond kTaps return 0 (the step has settled).
Returns
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.

Member Data Documentation

◆ kOversample

template<typename T >
constexpr int dspark::MinBlepTable< T >::kOversample = kPhases
staticconstexpr

Sub-sample positions per output sample (the same resolution).

Definition at line 99 of file MinBlepTable.h.

◆ kPhases

template<typename T >
constexpr int dspark::MinBlepTable< T >::kPhases = 2048
staticconstexpr

Sub-sample resolution: rows per sample, linearly interpolated.

Definition at line 97 of file MinBlepTable.h.

◆ kTableSize

template<typename T >
constexpr int dspark::MinBlepTable< T >::kTableSize = kTaps * kOversample + 1
staticconstexpr

Points of the residual's domain [0, kTaps] at that resolution.

Definition at line 101 of file MinBlepTable.h.

◆ kTaps

template<typename T >
constexpr int dspark::MinBlepTable< T >::kTaps = 128
staticconstexpr

Correction span in base-rate samples (power of two, ring-buffer friendly).

Definition at line 95 of file MinBlepTable.h.


The documentation for this class was generated from the following file: