DSPark 1.8.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark Namespace Reference

Main namespace for the DSPark framework. More...

Namespaces

namespace  AnalogRandom
 
namespace  detail
 
namespace  harmony
 
namespace  plugin
 
namespace  simd
 
namespace  Smoothers
 
namespace  wdf
 

Classes

class  ADSREnvelope
 Classic ADSR envelope generator with exponential curves. More...
 
class  AlgorithmicReverb
 True-stereo 32-line FDN reverb with exact per-band decay and 6 presets. More...
 
class  AudioBuffer
 Owning audio buffer with contiguous, 32-byte aligned storage. More...
 
class  AudioBufferView
 Non-owning view over audio channel data. More...
 
class  AudioFile
 Abstract base class for audio file readers and writers. More...
 
struct  AudioFileInfo
 Metadata describing an audio file's format and dimensions. More...
 
class  AudioIntervalAnalyzer
 One requested mono/stereo interval per instance; feed several instances the same blocks to measure overlapping intervals in one source pass. The region is always measured as an independent finite fragment. Optional continuous loudness observations are separate, explicitly scoped results; they never replace or masquerade as the region's integrated loudness. More...
 
struct  AudioSpec
 Describes the audio environment for a DSP processor. More...
 
class  AutoGain
 Block-adaptive automatic gain compensation with SIMD-friendly linear interpolation. More...
 
class  BeatTracker
 Tempo and beat tracking with an offline grid and a causal readout. More...
 
class  Biquad
 Biquad filter using Transposed Direct Form II (TDF-II) with thread-safe updates. More...
 
struct  BiquadCoeffs
 Stores normalised biquad coefficients (b0, b1, b2, a1, a2), always double. More...
 
class  ChordDetector
 Monophonic-buffer chord recognition with confidence gating. More...
 
class  Chorus
 Multi-voice chorus/flanger with true stereo spread and smooth parameter handling. More...
 
class  Clipper
 Real-time audio clipper with analog modeling and anti-aliasing features. More...
 
class  Compressor
 High-fidelity modular compressor designed for real-time applications. More...
 
class  Convolver
 Real-time partitioned convolution using overlap-save with FFT. More...
 
class  Crossfade
 Artifact-free, SIMD-friendly crossfader for two audio signals. More...
 
class  CrossoverFilter
 Linkwitz-Riley crossover with 2-12 bands, LR12/LR24/LR48. More...
 
class  DCBlocker
 DC blocking filter with configurable Butterworth order (1-10). More...
 
class  DeEsser
 Stereo-linked, CPU-optimized dynamic-EQ de-esser. More...
 
class  Delay
 
class  DelayEstimator
 Streaming GCC-PHAT delay estimator with sub-sample refinement. More...
 
class  DenormalGuard
 RAII scope guard to disable denormalised (subnormal) floating-point numbers. More...
 
class  Dither
 TPDF dithering processor with optional 1st-order noise shaping. More...
 
class  DryWetMixer
 Pre-allocated, SIMD-friendly dry/wet blender for real-time audio. More...
 
class  DynamicEQ
 Dynamic parametric EQ with dual above/below threshold per band. More...
 
class  EnvelopeFollower
 Attack/release envelope detector (Peak or RMS). More...
 
class  Equalizer
 Parametric multi-band EQ using cascaded biquads or FFT overlap-save convolution. More...
 
class  Expander
 Downward expander with ratio control, hysteresis, and sidechain. More...
 
class  FFTComplex
 Complex FFT on interleaved data (Stockham radix-4 engine, SIMD). More...
 
class  FFTReal
 FFT optimised for real-valued input signals (the common audio case). More...
 
class  FilterEngine
 Professional multi-mode filter with cascaded biquad stages. More...
 
class  FIRDesign
 Static methods for designing FIR filter coefficients. More...
 
class  FIRFilter
 FIR filter using direct-form convolution with a mirrored delay line. More...
 
class  FlacFile
 Decode-only native FLAC implementation with eager integrity checks. More...
 
class  FrequencyShifter
 Constant-Hz frequency shift optimized via Quadrature Oscillator. More...
 
class  Gain
 Professional click-free gain processor. More...
 
class  Goertzel
 Single-frequency magnitude detector using the Goertzel algorithm. More...
 
class  GranularProcessor
 Granular clouds and spectral-freeze textures from live input. More...
 
class  Hilbert
 90-degree phase-differencing network (analytic-signal generator). More...
 
class  HilbertIIR
 Zero-latency analytic pair from two allpass chains (a 90-degree phase-difference network). More...
 
class  Hysteresis
 Per-channel Jiles-Atherton hysteresis processor (field in, M out). More...
 
class  KeyDetector
 Key estimation by profile correlation over an accumulated chroma. More...
 
class  LadderFilter
 4-pole resonant ladder filter (Moog topology, TPT discretization). More...
 
class  LevelFollower
 Per-channel peak and RMS envelope follower with lock-free readout. More...
 
class  Limiter
 High-performance brickwall lookahead limiter. More...
 
class  LoopFinder
 Finds and renders bounded, deterministic loop seams. More...
 
class  LoudnessMeter
 Real-time safe EBU R128 loudness meter. More...
 
class  LoudnessNormalizer
 Offline waveform-preserving LUFS normalizer with a hard true-peak ceiling. More...
 
struct  MidiEvent
 One semantic SMF event with a delta time. More...
 
class  MidiFile
 Transactional, resource-bounded SMF parser and authoring API. More...
 
struct  MidiTempoChange
 Effective tempo at an absolute tick. More...
 
struct  MidiTrack
 Ordered events belonging to one SMF track chunk. More...
 
struct  MidSide
 Static utility for Mid/Side stereo encoding and decoding. More...
 
class  MinBlepTable
 Shared minimum-phase band-limited step (minBLEP) residual table. More...
 
class  ModulationRouter
 Fixed-capacity source-to-target router with per-route depth/smoothing. More...
 
class  Mp3File
 
class  MultibandCompressor
 Multi-band compressor: crossover split, per-band compression, sum. More...
 
class  NoiseGate
 High-performance noise gate with state machine, hysteresis, and zero-allocation processing. More...
 
class  NoiseGenerator
 Generates decorellated noise (white, pink, brown) across multiple channels. More...
 
class  OfflineAudioSink
 Transactional worker sink for arbitrarily long offline output. More...
 
class  OfflineAudioSource
 Rewindable, complete-file source with int64 positions and bounded blocks. More...
 
struct  OfflineAudioSpec
 Immutable source format and host-provided content/timeline identity. More...
 
class  OfflineBeatCompressor
 Complete-source pulse compression with one positive reduction-dB control. More...
 
class  OfflineBufferSource
 Borrowed planar-buffer adapter; does not allocate, copy or own input. More...
 
class  OfflineEnergyAnalyzer
 Complete-file fixed-duration energy analysis for offline processors. More...
 
struct  OfflineFingerprint
 Noncryptographic PCM fingerprint, stable across block divisions. More...
 
struct  OfflineGainRenderInfo
 Measured-render control adjustments; no clipping or master gain trim. More...
 
class  OfflineHardClipper
 OFFLINE ONLY: calibrates an antialiased hard curve on the complete source. More...
 
struct  OfflineJobOptions
 Resource and cooperative-cancellation controls for one worker operation. More...
 
class  OfflineLeveler
 Complete-file automatic upward leveling, with reusable immutable plans. More...
 
class  OfflinePeakCompressor
 Complete-file peak compressor with a positive reduction-dB control. More...
 
struct  OfflineProgress
 Worker progress in source frames, or control points in the Plan pass. More...
 
class  OfflinePunch
 Offline transient emphasis with a positive boost-dB control. More...
 
struct  OfflineRegion
 Source-frame interval [begin,end), relative to the start of the source. More...
 
class  OfflineSoftClipper
 OFFLINE ONLY: calibrates a soft curve to reduce the complete source peak. More...
 
class  OfflineStereoBalance
 Optional offline balance of an already generated stereo signal. More...
 
class  OfflineStereoGenerator
 Offline processed-copy stereo generation with a one-width control. More...
 
class  OfflineTempoAnalyzer
 Complete-source tempo map for automatic offline processors. More...
 
class  OfflineTransientAnalyzer
 Source-bound attack and pulse maps for offline Dynamics. More...
 
class  OnsetDetector
 Causal SuperFlux onset detector with lock-free readout. More...
 
class  Oscillator
 Band-limited oscillator featuring PolyBLEP anti-aliasing and analog-modeled integration. More...
 
class  Oversampling
 Power-of-two oversampling processor with polyphase anti-aliasing. More...
 
class  Panner
 
class  PhaseCorrelation
 Correlation/balance meter and goniometer data source. More...
 
class  Phaser
 Zero-latency, highly optimized allpass-based phaser. More...
 
class  Phasor
 Phase accumulator generating a [0, 1) ramp for oscillators and modulation. More...
 
class  PitchCorrector
 Scale-aware monophonic retune over the framework's YIN detector and phase-vocoder shifter. More...
 
class  PitchDetector
 Thread-safe YIN pitch detector with lock-free readout. More...
 
class  PitchFollower
 Gated, octave-safe, semitone-smoothed pitch tracking source. More...
 
class  PitchShifter
 Real-time phase-vocoder pitch shifter (+-12 semitones, stereo-linked). More...
 
class  ProcessorChain
 Compile-time chain of audio processors. More...
 
class  Resampler
 Windowed-sinc sample rate converter optimized for real-time DSP. More...
 
class  Reverb
 Convolution reverb with IR loading, dry/wet, and pre-delay. More...
 
class  RingBuffer
 Power-of-two circular buffer with compile-time interpolated read access. More...
 
class  RingModulator
 Signal x carrier ring modulation with mix control and zero-latency smoothing. More...
 
class  SampleAndHold
 Holds a sample value for N samples or until externally triggered. More...
 
class  Sampler
 Polyphonic multi-zone sample player. More...
 
class  Saturation
 Professional multi-algorithm saturation processor with analog simulation. More...
 
class  SincInterpolator
 32-tap Kaiser-windowed sinc reader for transparent fractional reads. More...
 
class  SmoothedValue
 Zero-allocation parameter smoother for real-time audio. More...
 
class  SpectralDenoiser
 Learn-a-profile spectral noise reduction (hiss/hum/room-tone). More...
 
class  SpectralFreeze
 Frequency-domain hold with tonal and diffuse phase modes. More...
 
class  SpectralProcessor
 High-performance STFT analysis-modification-synthesis pipeline. More...
 
class  SpectrumAnalyzer
 Real-time FFT spectrum analyser with per-bin smoothing and peak hold. More...
 
class  SpinLock
 A minimal, real-time safe spin lock with a TTAS wait loop. More...
 
class  SpscQueue
 
class  StateReader
 Tolerant reader: missing keys yield defaults, unknown keys are skipped. More...
 
class  StateVariableFilter
 TPT State Variable Filter with simultaneous multi-output. More...
 
class  StateWriter
 Serializes key/value parameters into a versioned blob. More...
 
class  StereoGenerator
 A stereo generator that preserves the delayed original mid signal. More...
 
class  StereoWidth
 High-performance stereo image processor with phase-aligned bass mono. More...
 
class  StretchedSincReader
 Band-limited fractional reader for read rates from 1 to 4. More...
 
class  TapeMachine
 Reel-to-reel tape emulation with physical hysteresis and transport. More...
 
class  TimeStretch
 Real-time and offline time stretching, 0.5x to 2x, pitch unchanged. More...
 
class  TransformerModel
 Physical audio-transformer coloration (flux-domain JA hysteresis). More...
 
class  TransientDesigner
 Zero-allocation, thread-safe transient shaper. More...
 
class  Tremolo
 LFO-driven amplitude modulation with stereo auto-pan option. More...
 
class  TruePeakDetector
 Per-channel 4x-oversampled inter-sample peak estimator. More...
 
class  TubePreamp
 One/two 12AX7 stages with sag and a WDF tone circuit. More...
 
class  Vibrato
 Professional-grade pitch vibrato with LFO FM and parameter smoothing. More...
 
class  WaveshapeTable
 Zero-latency lookup-table waveshaper with RT-safe gain modulation. More...
 
class  WavetableOscillator
 Professional mipmapped wavetable oscillator for bandlimited synthesis. More...
 
class  WavFile
 Complete WAV file reader and writer in pure C++20. More...
 
struct  WindowFunctions
 Static utility generating window functions for DSP analysis/synthesis. More...
 
class  ZeroLatencyConvolver
 Gardner-style non-uniform partitioned convolver (zero latency, flat CPU). More...
 

Concepts

concept  FloatType
 Constrains a type to IEEE floating-point (float or double).
 
concept  AudioProcessor
 A type that can prepare, process audio blocks, and reset state.
 
concept  SampleProcessor
 An AudioProcessor that additionally supports scalar per-sample processing.
 
concept  GeneratorProcessor
 A real-time safe source processor (oscillators, noise, LFOs).
 

Enumerations

enum class  OfflineSoftClipCurve { Sine , Tanh , GoldenRatio }
 Soft curves shared with Clipper, including its sine approximation. More...
 
enum class  OfflineStatus : std::uint8_t {
  Success , NoChange , EmptyInput , InvalidInput ,
  UnsupportedLayout , NonFiniteInput , SourceMismatch , SourceReadFailed ,
  SinkFailed , CallbackFailed , Cancelled , MemoryLimit ,
  AllocationFailure , NumericalFailure , TargetUnreachable
}
 Explicit completion or no-publication outcome of an offline job. More...
 
enum class  OfflinePhase : std::uint8_t { Analyze , Plan , Verify , Render }
 Current kind of work; completed/total restart for each pass, and a phase may recur. More...
 
enum class  InterpMethod { Linear , Cubic , Hermite , Lagrange }
 Interpolation method for fractional-sample reads. More...
 
enum class  MidiEventKind : uint8_t { Channel , SysExF0 , SysExF7 , Meta }
 Semantic kind of a Standard MIDI File event. More...
 

Functions

template<FloatType T>
T decibelsToGain (T dB, T minusInfinityDb=T(-100)) noexcept
 Converts a value in decibels to linear gain.
 
template<FloatType T>
T gainToDecibels (T gain, T minusInfinityDb=T(-100)) noexcept
 Converts a linear gain value to decibels.
 
template<FloatType T>
T mapRange (T value, T inMin, T inMax, T outMin, T outMax) noexcept
 Maps a value from one range to another (linear interpolation).
 
template<FloatType T>
T moveTowards (T from, T to, T maxDelta) noexcept
 Moves a value toward a target by at most a given distance.
 
template<FloatType T>
T fastTanh (T x) noexcept
 Fast tanh approximation using Pade rational function.
 
template<FloatType T>
T fastPow10 (T x) noexcept
 Fast approximation of 10^x using exp2.
 
template<FloatType T>
T fastExp (T x) noexcept
 Fast approximation of e^x via std::exp2 (~2x faster than std::exp on MSVC).
 
template<FloatType T>
T fastTan (T x) noexcept
 Fast approximation of tan(x) using a Pade [5,4] rational approximant.
 
template<FloatType T>
T fastSin (T x) noexcept
 Fast sine approximation (degree-9 odd minimax polynomial).
 
template<FloatType T>
T fastCos (T x) noexcept
 Fast cosine approximation. See fastSin() for accuracy notes (the pi/2 offset costs float about half an ulp more).
 
template<FloatType T>
T fastLog (T x) noexcept
 Fast natural logarithm approximation.
 
template<FloatType T>
T wrapPhase (T phase) noexcept
 Normalises a phase value to the range [0, 2*pi).
 
template<FloatType T>
T interpolateLinear (T y0, T y1, T frac) noexcept
 Linear interpolation between two adjacent samples.
 
template<FloatType T>
T interpolateLinear (const T *buffer, int length, T position) noexcept
 Linear interpolation reading directly from a circular buffer.
 
template<FloatType T>
T interpolateHermite (T y0, T y1, T y2, T y3, T frac) noexcept
 4-point, 3rd-order Hermite interpolation (optimized x-form).
 
template<FloatType T>
T interpolateHermite (const T *buffer, int length, T position) noexcept
 
template<FloatType T>
T interpolateCubic (const T *buffer, int length, T position) noexcept
 Alias of interpolateHermite (Catmull-Rom evaluated in Hermite form). Kept for backward compatibility.
 
template<FloatType T>
T interpolateLagrange (T y0, T y1, T y2, T y3, T frac) noexcept
 4-point Lagrange interpolation from discrete samples.
 
template<FloatType T>
T interpolateLagrange (const T *buffer, int length, T position) noexcept
 
template<FloatType T>
T interpolateAllpass (T currentSample, T previousSample, T frac, T &state) noexcept
 Allpass interpolation (first-order Thiran) for fractional delay.
 
bool offlineSucceeded (OfflineStatus status) noexcept
 True for successful processing, including an explicit identity result.
 
std::string stateToJson (const std::vector< uint8_t > &blob)
 Renders a state blob as a flat JSON object string.
 
std::vector< uint8_t > stateFromJson (const std::string &json)
 Parses the JSON produced by stateToJson() back into a blob.
 
constexpr uint32_t stateId (const char(&tag)[5]) noexcept
 Builds a FOURCC processor id, e.g. dspark::stateId("COMP").
 

Variables

template<FloatType T>
constexpr T pi = std::numbers::pi_v<T>
 Pi (3.14159...) for the given floating-point type.
 
template<FloatType T>
constexpr T twoPi = T(2) * std::numbers::pi_v<T>
 2 * Pi (6.28318...).
 
template<FloatType T>
constexpr T invTwoPi = T(1) / twoPi<T>
 1 / (2 * Pi) (0.15915...). Useful for fast phase divisions.
 
template<FloatType T>
constexpr T halfPi = std::numbers::pi_v<T> / T(2)
 Pi / 2 (1.57079...). Quarter period; sin/cos phase offset.
 
template<FloatType T>
constexpr T sqrt2 = std::numbers::sqrt2_v<T>
 Square root of 2 (1.41421...).
 
template<FloatType T>
constexpr T invSqrt2 = T(1) / std::numbers::sqrt2_v<T>
 1 / square root of 2 (0.70710...). Butterworth Q factor.
 
constexpr std::size_t kCacheLineSize = 64
 

Detailed Description

Main namespace for the DSPark framework.

Enumeration Type Documentation

◆ InterpMethod

enum class dspark::InterpMethod
strong

Interpolation method for fractional-sample reads.

Enumerator
Linear 

2-point linear (fast, lower quality)

Cubic 

4-point Catmull-Rom (good balance)

Hermite 

4-point Hermite (smooth transients, best for modulated delay)

Lagrange 

4-point Lagrange (highest accuracy, static delay)

Definition at line 46 of file RingBuffer.h.

◆ MidiEventKind

enum class dspark::MidiEventKind : uint8_t
strong

Semantic kind of a Standard MIDI File event.

Enumerator
Channel 
SysExF0 
SysExF7 
Meta 

Definition at line 40 of file MidiFile.h.

◆ OfflinePhase

enum class dspark::OfflinePhase : std::uint8_t
strong

Current kind of work; completed/total restart for each pass, and a phase may recur.

Enumerator
Analyze 
Plan 
Verify 
Render 

Definition at line 109 of file OfflineProcessing.h.

◆ OfflineSoftClipCurve

enum class dspark::OfflineSoftClipCurve
strong

Soft curves shared with Clipper, including its sine approximation.

Enumerator
Sine 
Tanh 
GoldenRatio 

Definition at line 30 of file OfflineClip.h.

◆ OfflineStatus

enum class dspark::OfflineStatus : std::uint8_t
strong

Explicit completion or no-publication outcome of an offline job.

Enumerator
Success 
NoChange 
EmptyInput 
InvalidInput 
UnsupportedLayout 
NonFiniteInput 
SourceMismatch 
SourceReadFailed 
SinkFailed 
CallbackFailed 
Cancelled 
MemoryLimit 
AllocationFailure 
NumericalFailure 
TargetUnreachable 

Exact protected PCM prevents the requested processing target.

Definition at line 54 of file OfflineProcessing.h.

Function Documentation

◆ decibelsToGain()

template<FloatType T>
T dspark::decibelsToGain ( T  dB,
T  minusInfinityDb = T(-100) 
)
inlinenoexcept

Converts a value in decibels to linear gain.

Parameters
dBValue in decibels.
minusInfinityDbValues at or below this threshold return 0. Default: -100 dB.
Returns
Linear gain (0 for silence, 1 for unity, >1 for boost).

Definition at line 74 of file DspMath.h.

◆ fastCos()

template<FloatType T>
T dspark::fastCos ( T  x)
inlinenoexcept

Fast cosine approximation. See fastSin() for accuracy notes (the pi/2 offset costs float about half an ulp more).

Parameters
xArgument in radians.
Returns
Approximation of cos(x).

Definition at line 276 of file DspMath.h.

◆ fastExp()

template<FloatType T>
T dspark::fastExp ( T  x)
inlinenoexcept

Fast approximation of e^x via std::exp2 (~2x faster than std::exp on MSVC).

Uses the identity e^x = 2^(x * log2(e)).

Parameters
xExponent. No range clamping is applied.
Returns
Approximation of e^x.

Definition at line 202 of file DspMath.h.

◆ fastLog()

template<FloatType T>
T dspark::fastLog ( T  x)
inlinenoexcept

Fast natural logarithm approximation.

Splits the input into exponent and mantissa via std::frexp, then evaluates the classic 4-term atanh series (Cephes style) for ln of the mantissa, centred on [sqrt(0.5), sqrt(2)). Relative error is below 2e-7: ample for envelope/dB work. Roughly 2-4x faster than std::log.

Parameters
xInput value. Must be > 0 (no guard: matches std::log contract).
Returns
Approximation of ln(x).

Definition at line 293 of file DspMath.h.

◆ fastPow10()

template<FloatType T>
T dspark::fastPow10 ( T  x)
inlinenoexcept

Fast approximation of 10^x using exp2.

Uses the identity 10^x = 2^(x * log2(10)). Useful in dB conversions where exact precision is not critical.

Parameters
xExponent.
Returns
Approximation of 10^x.

Definition at line 183 of file DspMath.h.

◆ fastSin()

template<FloatType T>
T dspark::fastSin ( T  x)
inlinenoexcept

Fast sine approximation (degree-9 odd minimax polynomial).

The coefficients are a Remez minimax fit of sin on [-pi/2, pi/2] under the constraint that the polynomial is exactly 1 at pi/2, so the output never overshoots the unit circle in double. Maximum absolute error is ~3.7e-9 in double (about -168 dB) and float-rounding-limited (~1.8e-7, about -135 dB) in float: a pure sine rendered with it is cleaner than a 24-bit converter. About 3-6x faster than std::sin depending on platform. The input is range-reduced internally (two-term Cody-Waite), so any finite argument within a few thousand periods of zero stays accurate.

Parameters
xArgument in radians.
Returns
Approximation of sin(x).

Definition at line 248 of file DspMath.h.

◆ fastTan()

template<FloatType T>
T dspark::fastTan ( T  x)
inlinenoexcept

Fast approximation of tan(x) using a Pade [5,4] rational approximant.

Accurate to better than 0.01% for |x| <= 1.45 and ~0.1% up to the 1.52 fallback limit. Outside that range, falls back to std::tan to avoid the singularities at +-pi/2 producing absurd results.

Useful for the bilinear-transform tan(pi*f/Fs) term: with this accuracy a 20 kHz cutoff at 44.1 kHz lands within a fraction of a cent of the target. Roughly 3x faster than std::tan on MSVC.

Parameters
xArgument in radians.
Returns
Approximation of tan(x).

Definition at line 222 of file DspMath.h.

◆ fastTanh()

template<FloatType T>
T dspark::fastTanh ( T  x)
inlinenoexcept

Fast tanh approximation using Pade rational function.

Approximately 5x faster than std::tanh. Optimized for SIMD without branching. Input is clamped to [-3, 3] maintaining C0 continuity to prevent aliasing. Max output amplitude is ~0.9954.

Note
The clamp at |x| = 3 is C0 but not C1: the derivative has a small discontinuity there (output is already ~0.9954, so the resulting kink is inaudible in practice). Use std::tanh where exact C1 behaviour matters.
Parameters
xInput value.
Returns
Approximation of tanh(x), smoothly bounded.

Definition at line 161 of file DspMath.h.

◆ gainToDecibels()

template<FloatType T>
T dspark::gainToDecibels ( T  gain,
T  minusInfinityDb = T(-100) 
)
inlinenoexcept

Converts a linear gain value to decibels.

Parameters
gainLinear gain (must be >= 0).
minusInfinityDbReturned for zero or negative gain. Default: -100 dB.
Returns
Value in decibels.

Definition at line 89 of file DspMath.h.

◆ interpolateAllpass()

template<FloatType T>
T dspark::interpolateAllpass ( T  currentSample,
T  previousSample,
T  frac,
T &  state 
)
inlinenoexcept

Allpass interpolation (first-order Thiran) for fractional delay.

Perfectly flat magnitude response at every frequency, unlike polynomial interpolators (which low-pass); the cost is a frequency-dependent phase response and a recursive state.

Warning
Allpass interpolation is IIR (recursive). Do NOT modulate frac quickly (e.g. audio-rate LFOs): the state carries history filtered with the previous coefficient and produces loud clicks. Best for static or slowly changing delays; use interpolateHermite for modulated delay lines.

The filter is stable for any frac > 0, but as frac approaches 0 the pole approaches z = -1 and the interpolator rings for thousands of samples near Nyquist. Canonical usage keeps the fractional delay in [0.5, 1.5): when the fractional part f of the total delay is below 0.5, read one integer sample earlier and pass frac = f + 1 instead.

Parameters
currentSampleThe current input sample (x[n]).
previousSampleThe previous input sample (x[n-1]).
fracFractional delay in samples, relative to x[n]. Stable for any value > 0; see the [0.5, 1.5) mapping above for clean low-frac behaviour.
stateAllpass filter state (y[n-1]). Maintained by the caller; initialise to 0 and keep one state per delay tap per channel.
Returns
Interpolated sample value (y[n]).

Definition at line 279 of file Interpolation.h.

◆ interpolateCubic()

template<FloatType T>
T dspark::interpolateCubic ( const T *  buffer,
int  length,
T  position 
)
inlinenoexcept

Alias of interpolateHermite (Catmull-Rom evaluated in Hermite form). Kept for backward compatibility.

Definition at line 178 of file Interpolation.h.

◆ interpolateHermite() [1/2]

template<FloatType T>
T dspark::interpolateHermite ( const T *  buffer,
int  length,
T  position 
)
inlinenoexcept

Definition at line 151 of file Interpolation.h.

◆ interpolateHermite() [2/2]

template<FloatType T>
T dspark::interpolateHermite ( T  y0,
T  y1,
T  y2,
T  y3,
T  frac 
)
inlinenoexcept

4-point, 3rd-order Hermite interpolation (optimized x-form).

Mathematically identical to Catmull-Rom but evaluated with fewer multiplications than the standard polynomial form.

Parameters
y0Sample at index n-1.
y1Sample at index n.
y2Sample at index n+1.
y3Sample at index n+2.
fracFractional position between y1 and y2 (0.0 to 1.0).
Returns
Interpolated sample.

Definition at line 126 of file Interpolation.h.

◆ interpolateLagrange() [1/2]

template<FloatType T>
T dspark::interpolateLagrange ( const T *  buffer,
int  length,
T  position 
)
inlinenoexcept

Definition at line 230 of file Interpolation.h.

◆ interpolateLagrange() [2/2]

template<FloatType T>
T dspark::interpolateLagrange ( T  y0,
T  y1,
T  y2,
T  y3,
T  frac 
)
inlinenoexcept

4-point Lagrange interpolation from discrete samples.

Reconstructs polynomials up to degree 3 exactly (the divisions of the Lagrange basis are precomputed constants).

Parameters
y0Sample at index n-1.
y1Sample at index n.
y2Sample at index n+1.
y3Sample at index n+2.
fracFractional position between y1 and y2 (0.0 to 1.0).
Returns
Interpolated sample.

Definition at line 196 of file Interpolation.h.

◆ interpolateLinear() [1/2]

template<FloatType T>
T dspark::interpolateLinear ( const T *  buffer,
int  length,
T  position 
)
inlinenoexcept

Linear interpolation reading directly from a circular buffer.

The buffer is treated as circular: reading at position length - 0.5 interpolates between the last and the first sample.

Parameters
bufferPointer to the start of the audio buffer.
lengthSize of the buffer in samples (must be > 0).
positionAbsolute read position.
Returns
Interpolated sample.
Precondition
0 <= position < length. Violations assert in debug builds; release builds clamp to the nearest valid sample (NaN reads position 0).

Definition at line 91 of file Interpolation.h.

◆ interpolateLinear() [2/2]

template<FloatType T>
T dspark::interpolateLinear ( T  y0,
T  y1,
T  frac 
)
inlinenoexcept

Linear interpolation between two adjacent samples.

Parameters
y0Sample at index n.
y1Sample at index n+1.
fracFractional position (0.0 to 1.0).
Returns
Interpolated sample.

Definition at line 72 of file Interpolation.h.

◆ mapRange()

template<FloatType T>
T dspark::mapRange ( T  value,
T  inMin,
T  inMax,
T  outMin,
T  outMax 
)
inlinenoexcept

Maps a value from one range to another (linear interpolation).

Includes a safety check to prevent division by zero if inMin == inMax.

Parameters
valueThe input value to remap.
inMinLower bound of the input range.
inMaxUpper bound of the input range.
outMinLower bound of the output range.
outMaxUpper bound of the output range.
Returns
Remapped value. Returns outMin if input bounds are identical.

Definition at line 114 of file DspMath.h.

◆ moveTowards()

template<FloatType T>
T dspark::moveTowards ( T  from,
T  to,
T  maxDelta 
)
inlinenoexcept

Moves a value toward a target by at most a given distance.

The rate-limiter step: lands exactly on the target once within reach. Evaluated with maxDelta = step * (i + 1) it gives the i-th sample of a rate-limited ramp in closed form (no loop-carried state), which is how the framework's dry/wet ramps keep a minimum duration whatever the block size.

Parameters
fromCurrent value.
toTarget value.
maxDeltaLargest allowed move (non-negative).
Returns
to when |to - from| <= maxDelta, else from moved by maxDelta toward to.

Definition at line 134 of file DspMath.h.

◆ offlineSucceeded()

bool dspark::offlineSucceeded ( OfflineStatus  status)
inlinenoexcept

True for successful processing, including an explicit identity result.

Definition at line 74 of file OfflineProcessing.h.

◆ stateFromJson()

std::vector< uint8_t > dspark::stateFromJson ( const std::string &  json)
inline

Parses the JSON produced by stateToJson() back into a blob.

Accepts exactly that flat subset (id/version/params of numbers and bools); returns an empty vector on malformed input. Number-typed params re-enter as floats; integer-coded modes survive because setState() readers request the type they stored, and stateToJson tags ints without decimals – both int and float lookups are attempted by the float/int read pair below.

Definition at line 645 of file StateBlob.h.

◆ stateId()

constexpr uint32_t dspark::stateId ( const char(&)  tag[5])
constexprnoexcept

Builds a FOURCC processor id, e.g. dspark::stateId("COMP").

Definition at line 651 of file StateBlob.h.

◆ stateToJson()

std::string dspark::stateToJson ( const std::vector< uint8_t > &  blob)
inline

Renders a state blob as a flat JSON object string.

Definition at line 631 of file StateBlob.h.

◆ wrapPhase()

template<FloatType T>
T dspark::wrapPhase ( T  phase)
inlinenoexcept

Normalises a phase value to the range [0, 2*pi).

Optimized for hot paths: avoids std::fmod (slow, hostile to vectorisation) in favour of inverse multiplication and flooring.

Parameters
phasePhase in radians.
Returns
Phase wrapped safely to [0, 2*pi).

Definition at line 326 of file DspMath.h.

Variable Documentation

◆ halfPi

template<FloatType T>
constexpr T dspark::halfPi = std::numbers::pi_v<T> / T(2)
inlineconstexpr

Pi / 2 (1.57079...). Quarter period; sin/cos phase offset.

Definition at line 54 of file DspMath.h.

◆ invSqrt2

template<FloatType T>
constexpr T dspark::invSqrt2 = T(1) / std::numbers::sqrt2_v<T>
inlineconstexpr

1 / square root of 2 (0.70710...). Butterworth Q factor.

Definition at line 60 of file DspMath.h.

◆ invTwoPi

template<FloatType T>
constexpr T dspark::invTwoPi = T(1) / twoPi<T>
inlineconstexpr

1 / (2 * Pi) (0.15915...). Useful for fast phase divisions.

Definition at line 51 of file DspMath.h.

◆ kCacheLineSize

constexpr std::size_t dspark::kCacheLineSize = 64
inlineconstexpr

Definition at line 62 of file SpscQueue.h.

◆ pi

template<FloatType T>
constexpr T dspark::pi = std::numbers::pi_v<T>
inlineconstexpr

Pi (3.14159...) for the given floating-point type.

Definition at line 45 of file DspMath.h.

◆ sqrt2

template<FloatType T>
constexpr T dspark::sqrt2 = std::numbers::sqrt2_v<T>
inlineconstexpr

Square root of 2 (1.41421...).

Definition at line 57 of file DspMath.h.

◆ twoPi

template<FloatType T>
constexpr T dspark::twoPi = T(2) * std::numbers::pi_v<T>
inlineconstexpr

2 * Pi (6.28318...).

Definition at line 48 of file DspMath.h.