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

Namespaces

namespace  continuous_clip
 
namespace  fft
 
namespace  mp3
 
namespace  native_clip_coefficients
 
namespace  offline_clip
 
namespace  offline_sinc
 
namespace  stereo_color_banks
 
namespace  stereo_color_coefficients
 
namespace  truepeak
 

Classes

class  AccountedAllocator
 
class  Adaa2
 Per-stream second-order ADAA state. More...
 
struct  AdaaExciter
 
struct  AdaaHardClip
 
struct  AdaaPoint
 
struct  AdaaRationalKnee
 
struct  AdaaSecondDifference
 
struct  AdaaSine
 
struct  AdaaSinePolynomial
 
struct  AdaaSinePolynomialTerms
 
struct  AdaaTanh
 
struct  AdaaTape
 
class  AdaaTapeTable
 
struct  AllocationAccount
 
class  BitcrusherAlgorithm
 
class  ContinuousStereoColor
 
class  ConvolutionRate
 
class  CurveAlgorithm
 
struct  DcBlockState
 Previous input and output of the one-pole DC blocker. More...
 
class  DownsampleAlgorithm
 
class  DryPhase
 Gives the dry side of a mix the phase that a high-pass leaves in the wet side, and none of its magnitude. More...
 
class  ExciterAlgorithm
 
class  HardClipAlgorithm
 
class  KernelConvolver
 A part of a DetailFilter: minimum-phase kernels designed as a SpectralFilter designs its own (detail::MinimumPhase), at the window and padding given, convolved in partitions of a block (a quarter of that window, up to the whole of it). More...
 
struct  LadderCoeffs
 Coefficients derived from g and the resonance. More...
 
struct  LadderInputCoeffs
 Coefficients of ladderStepInput(), derived by makeLadderInputCoeffs(). More...
 
struct  LadderInputLane
 One channel's registers while ladderStepInput() runs a sample. More...
 
struct  LadderInputState
 State of ladderStepInput(), in double whatever the sample type is. More...
 
struct  LadderStageCoeffs
 Coefficients of ladderStepStages(), derived by makeLadderStageCoeffs(). More...
 
class  MinimumPhase
 The minimum-phase kernel of a log magnitude, by its real cepstrum: what SpectralFilter and DetailFilter design their kernels with. More...
 
class  MultiStageAlgorithm
 
class  OfflineAttenuation
 
struct  OfflineBeatEngine
 
class  OfflineBlock
 
class  OfflineBoundaryFeasibility
 
class  OfflineBoxSmoother
 
struct  OfflineClipCalibration
 
struct  OfflineClipMeasurement
 
struct  OfflineClipOptions
 
class  OfflineClipProcessor
 
class  OfflineConvolutionWindow
 
class  OfflineEndpointWeights
 
class  OfflineExclusions
 
struct  OfflineFailure
 
class  OfflineGainProduct
 
struct  OfflineGainRenderSettings
 
class  OfflineGainSource
 
class  OfflineHilbertMap
 
class  OfflineMemoryPool
 
class  OfflineProductCombination
 
class  OfflineProductWorkspace
 
class  OfflinePunchEnvelope
 
struct  OfflineScratchDeleter
 
class  OfflineSession
 
struct  OfflineSinkTransaction
 
struct  OfflineSoftClipOptions
 
struct  OfflineSourceSummary
 
class  OfflineStereoStream
 
class  OnsetNovelty
 Shared whitening, spectral/complex flux and SuperFlux feature history. More...
 
class  OnsetPeakPicker
 Allocation-free symmetric novelty peak picker with an explicit frame clock. More...
 
class  OnsetSpectrum
 Reusable periodic-Hann real spectrum, without feature history. More...
 
class  OversampledStereoColor
 
class  PhaseVocoderEngine
 Identity-phase-locked STFT analysis/synthesis core (internal). More...
 
class  RetimedDcBlock
 
class  ReverbBankPublisher
 
struct  ReverbPublisherNoopHooks
 
class  SampleReader
 One voice's position in a zone and its band-limited read. More...
 
struct  SampleZoneData
 One validated zone, its audio copied and its loop crossfade baked. More...
 
class  SaturationAlgorithm
 
class  ScaledSumSquares
 Scaled sum of squares; caller validates finite input and counts values. More...
 
class  StereoColor
 
class  StudioVocoder
 Streaming phase-gradient vocoder with a strike-anchored time map. More...
 
class  TanhAlgorithm
 
class  TapeAlgorithm
 
struct  TptSvfOutput
 Lowpass and constant-skirt-gain bandpass outputs. More...
 
struct  TptSvfState
 Equivalent-current memories of the two trapezoidal integrators. More...
 
class  TransformerAlgorithm
 
struct  TruePeakLoops
 
class  TubeAlgorithm
 
class  WavefolderAlgorithm
 
struct  WavetableFrame
 
struct  WavetableRows
 One block's level pair, as WavetableBank's block readers see it. More...
 

Typedefs

template<typename T >
using OfflineScratchArray = std::unique_ptr< T[], OfflineScratchDeleter< T > >
 
using OfflineBeatMemory = OfflineMemoryPool
 

Enumerations

enum class  ClipperCurve {
  Hard , Tanh , Sine , GoldenRatio ,
  SymmetricKnee , AsymmetricKnee
}
 
enum class  LadderTap {
  LP6 , LP12 , LP18 , LP24 ,
  BP12 , HP24
}
 Output tap mix of the four-stage cascade. More...
 

Functions

double advanceBoxAverage (double incoming, double outgoing, double &sum, double inverseLength) noexcept
 
template<ClipperCurve Curve, FloatType T>
constexpr T clipperSmallSignalSlope () noexcept
 Exact small-signal slope of the implemented stateless curve.
 
template<ClipperCurve Curve, FloatType T>
std::array< T, 2 > clipperLinearLimits (T ceiling) noexcept
 Exact linear-region endpoints of a rational clipping curve.
 
template<ClipperCurve Curve, FloatType T>
T clipperShape (T sample, T ceiling) noexcept
 Shared transfer functions; no state or implicit antialiasing.
 
double dcBlockStep (double pole, DcBlockState &state, double input) noexcept
 Applies (1 - z^-1) / (1 - pole * z^-1), with a pole in [0, 1).
 
template<FloatType T>
LadderCoeffs< T > makeLadderCoeffs (T g, T res) noexcept
 Derives the ladder coefficients.
 
template<LadderTap Tap, FloatType T>
T ladderStep (T input, std::array< T, 4 > &z, const LadderCoeffs< T > &c, T drive) noexcept
 Advances the four TPT one-pole stages and the resolved feedback loop by one sample.
 
template<FloatType T>
LadderStageCoeffs makeLadderStageCoeffs (T g, T res, T drive) noexcept
 Derives the coefficients of the per-stage saturating ladder.
 
double ladderTanh (double a) noexcept
 tanh(a) by its [9/8] continued-fraction convergent, clamped to +-1 where the convergent reaches 1 (|a| = 6.297).
 
double ladderTanhRatio (double a) noexcept
 ladderTanh(a) / a, finite at a = 0 (where it is 1).
 
template<LadderTap Tap, FloatType T>
T ladderStepStages (T input, std::array< T, 4 > &z, const LadderStageCoeffs &c) noexcept
 Advances the per-stage saturating ladder by one sample.
 
void ladderTanhParts (double a2, double &num, double &den) noexcept
 The two polynomials of ladderTanh() in a^2 (tanh(a) = a num / den), each summed as two halves so that both are ready four operations after a^2.
 
void ladderInputRefresh (LadderInputState &h, const LadderInputCoeffs &c) noexcept
 Recomputes the carried sums after the states or the coefficients changed.
 
template<FloatType T>
LadderInputCoeffs makeLadderInputCoeffs (double cutoffRatio, T res, T drive) noexcept
 Derives the coefficients of the input-saturating ladder.
 
template<LadderTap Tap, FloatType T>
DSPARK_LADDER_INLINE T ladderStepInput (T input, LadderInputState &h, const LadderInputCoeffs &c) noexcept
 Advances the input-saturating ladder by one sample.
 
template<LadderTap Tap, FloatType T>
DSPARK_LADDER_INLINE void ladderStepInputPair (T &a, T &b, LadderInputState &ha, LadderInputState &hb, const LadderInputCoeffs &c) noexcept
 ladderStepInput() on two channels at once, sub-step by sub-step.
 
double logCosh (double x) noexcept
 Stable log(cosh(x)), shared by the tanh antiderivative kernels.
 
double integralLogCoshTail (double a) noexcept
 
double integralLogCosh (double x) noexcept
 
double offlineClipPeakErrorDb (double peak, double target) noexcept
 
bool offlineClipTargetMet (double peak, double target, double errorDb) noexcept
 
template<class Render >
OfflineClipCalibration offlineCalibrateClip (double initialCeiling, double target, Render render)
 
template<class Result , FloatType T, class Report , class CursorFactory >
Result offlineRenderGain (OfflineAudioSource< T > &source, const OfflineAudioSpec &spec, const OfflineFingerprint &expectedFingerprint, double inputPeak, bool valid, bool changed, const Report &report, OfflineAudioSink< T > &sink, const OfflineJobOptions &options, CursorFactory makeCursor, OfflineGainRenderSettings settings={})
 
template<class LeftReader , class RightReader , class Consumer >
void offlineBandlimitedProduct (OfflineSession &job, std::int64_t frames, LeftReader left, RightReader right, Consumer consume, int block=0)
 
template<FloatType T>
double offlineRepresentablePeakGain (double inputPeak, double gain) noexcept
 
template<FloatType T, class Consume >
OfflineSourceSummary offlineScanSource (OfflineAudioSource< T > &source, const OfflineAudioSpec &spec, OfflineBlock< T > &scratch, const OfflineSession &job, OfflinePhase phase, Consume consume)
 
template<FloatType T, class Consume >
void offlineScanMagnitude (OfflineAudioSource< T > &source, const OfflineAudioSpec &spec, const OfflineFingerprint &expectedFingerprint, double inputPeak, OfflineBlock< T > &scratch, const OfflineSession &job, Consume consume)
 
template<class Function >
void offlineCallSink (Function &&function)
 
template<class Processor , FloatType T, int MaxChannels, class Options >
Processor::Result offlineRun (const Processor &processor, const AudioBuffer< T, MaxChannels > &input, AudioBuffer< T, MaxChannels > &output, double sampleRate, const Options &options, const OfflineJobOptions &job)
 
template<FloatType T>
T rationalKneeMagnitude (T magnitude, T knee, T ceiling) noexcept
 Positive magnitude of the original Clipper rational soft knee.
 
double rationalKneeShape (double input, double positiveKnee, double negativeKnee) noexcept
 Unit-ceiling curve with independent positive and negative knees.
 
double rationalKneeIntegral (double input, double positiveKnee, double negativeKnee) noexcept
 Antiderivative of the unit-ceiling curve, with F(0) = 0.
 
template<FloatType T>
bool buildSampleZone (const SampleZoneSpec< T > &z, SampleZoneData< T > &d)
 Validates and copies a zone, clamping its loop and baking the loop crossfade. False (and d unspecified) for a zone with no audio, an invalid rate or an empty key or velocity range.
 
void sampleZonePanGains (double pan, int channels, double gain, double &left, double &right, double &mono) noexcept
 Output gains of a zone at gain: a mono zone pans with constant power (unity at centre), a multichannel one balances its first two channels. mono is the gain for a single output channel.
 
template<FloatType T>
T sampleGatherReduce (const T *lane) noexcept
 The final reduction of the eight partial sums.
 
template<int C, FloatType T>
void sampleGatherNarrow (const T *r0, const T *r1, T g, const T *x0, const T *x1, int taps, T *out) noexcept
 Unit-scale gather of C (1 or 2) channels: the weights are the rows r0 and r1 blended by g, tap by tap, and each channel's sum is formed in the order of kSampleGatherLanes.
 
template<FloatType T>
TptSvfOutput< T > tptSvfStep (T input, TptSvfState< T > &state, T a1, T a2, T a3) noexcept
 Advances the expanded Simper TPT recurrence by one sample.
 
double hilbertIdealImpulse (std::int64_t index) noexcept
 
void offlineFail (OfflineStatus status)
 
OfflineStatus offlineExceptionStatus () noexcept
 
std::size_t offlineBytes (std::uint64_t count, std::size_t size)
 
OfflineJobOptions offlineRemaining (const OfflineJobOptions &job, std::size_t used)
 
void offlineValidateSpec (const OfflineAudioSpec &spec, int maximumChannels=16)
 
template<FloatType T>
void offlineRead (OfflineAudioSource< T > &source, const OfflineAudioSpec &expected, std::int64_t first, AudioBufferView< T > block)
 
template<FloatType T>
void offlineHash (OfflineFingerprint &state, T sample) noexcept
 
void appendStateJsonString (std::string &out, const std::string &s)
 Appends a JSON string literal, escaping the characters JSON forbids. Keys follow the [A-Za-z0-9._] convention (so this normally emits verbatim), but the convention is not enforced on the writer or reader, and untrusted blobs can carry arbitrary key bytes; escaping keeps the emitted JSON valid and non-injectable in every case.
 
void appendStateJsonNumber (std::string &out, float v)
 Locale-independent float rendering ("%.9g" with a forced dot). Non-finite payloads (NaN/Inf – e.g. a corrupt blob or a bugged parameter) are emitted as JSON-legal 0 so the output always parses and round-trips.
 
const char * parseStateJsonNumber (const char *s, const char *end, double &out) noexcept
 Locale-independent number parse over [s, end); nullptr on failure.
 
std::string stateToJsonImpl (const std::vector< uint8_t > &blob, int depth)
 
std::vector< uint8_t > stateFromJsonImpl (const std::string &json, int depth)
 
template<int Count, typename T >
void designSincPhase (T *out, double beta, double frac) noexcept
 
template<typename T >
T refineVertex (T a, T b, T c, T m) noexcept
 
template<typename T >
T gridReading (const T *s, const T *q, const T *h, const T *t, int i) noexcept
 
template<typename T >
T eighthCrests (const T *a, const T *e, int u, T m) noexcept
 
template<typename T >
void raiseToEighthSamples (const T *a, const T *e, T *peak, int first, int n) noexcept
 
WavetableFrame wavetableFrame (double position, int numFrames) noexcept
 

Variables

constexpr double kLadderStagesMaxGain = 6.313751514675041
 Largest prewarped integrator gain of the per-stage model: tan(0.45 pi), a cutoff of 0.45 * fs.
 
constexpr int kLadderStagesMaxIterations = 16
 Newton step cap of ladderStepStages() (the worst case measured is 10).
 
constexpr double kLadderStagesStateStartGain = 0.15
 Integrator gain below which ladderStepStages() falls back to the integrator states instead of the fixed-pivot solve (cutoff about 0.047 * fs) when the linear prediction is not used.
 
constexpr double kLadderStagesLinearStartLimit = 2.0
 Largest stage level of the linear prediction, in knee widths, at which ladderStepStages() starts Newton from that prediction (above kLadderStagesStateStartGain).
 
constexpr int kLadderInputSubsteps = 4
 Sub-steps per sample of the input-saturating ladder.
 
constexpr double kLadderTanhLimit = 6.297019181717114
 Where ladderTanh()'s rational function reaches 1, and that squared.
 
constexpr double kLadderTanhLimit2 = kLadderTanhLimit * kLadderTanhLimit
 
constexpr int kSampleGatherLanes = 8
 
template<FloatType T>
constexpr std::array< T, 5 > fastSinPolynomial
 
constexpr int kMaxStateJsonDepth = 32
 
constexpr std::array< double, 18 > kWavetableNiemitalo
 
constexpr int kWavetableOneLevel = 0
 Level layouts of a block: one level, two levels on one grid, two grids.
 
constexpr int kWavetableSameGrid = 1
 
constexpr int kWavetableTwoGrids = 2
 

Typedef Documentation

◆ OfflineBeatMemory

Definition at line 23 of file OfflineBeatEngine.h.

◆ OfflineScratchArray

template<typename T >
using dspark::detail::OfflineScratchArray = typedef std::unique_ptr<T[], OfflineScratchDeleter<T> >

Definition at line 312 of file OfflineProcessing.h.

Enumeration Type Documentation

◆ ClipperCurve

enum class dspark::detail::ClipperCurve
strong
Enumerator
Hard 
Tanh 
Sine 
GoldenRatio 
SymmetricKnee 
AsymmetricKnee 

Definition at line 23 of file ClipperShape.h.

◆ LadderTap

enum class dspark::detail::LadderTap
strong

Output tap mix of the four-stage cascade.

Enumerator
LP6 
LP12 
LP18 
LP24 
BP12 
HP24 

Definition at line 27 of file LadderZdf.h.

Function Documentation

◆ advanceBoxAverage()

double dspark::detail::advanceBoxAverage ( double  incoming,
double  outgoing,
double &  sum,
double  inverseLength 
)
inlinenoexcept

Definition at line 12 of file BoxAverage.h.

◆ appendStateJsonNumber()

void dspark::detail::appendStateJsonNumber ( std::string &  out,
float  v 
)
inline

Locale-independent float rendering ("%.9g" with a forced dot). Non-finite payloads (NaN/Inf – e.g. a corrupt blob or a bugged parameter) are emitted as JSON-legal 0 so the output always parses and round-trips.

Definition at line 333 of file StateBlob.h.

◆ appendStateJsonString()

void dspark::detail::appendStateJsonString ( std::string &  out,
const std::string &  s 
)
inline

Appends a JSON string literal, escaping the characters JSON forbids. Keys follow the [A-Za-z0-9._] convention (so this normally emits verbatim), but the convention is not enforced on the writer or reader, and untrusted blobs can carry arbitrary key bytes; escaping keeps the emitted JSON valid and non-injectable in every case.

Definition at line 299 of file StateBlob.h.

◆ buildSampleZone()

template<FloatType T>
bool dspark::detail::buildSampleZone ( const SampleZoneSpec< T > &  z,
SampleZoneData< T > &  d 
)

Validates and copies a zone, clamping its loop and baking the loop crossfade. False (and d unspecified) for a zone with no audio, an invalid rate or an empty key or velocity range.

Definition at line 73 of file SampleReader.h.

◆ clipperLinearLimits()

template<ClipperCurve Curve, FloatType T>
std::array< T, 2 > dspark::detail::clipperLinearLimits ( T  ceiling)
inlinenoexcept

Exact linear-region endpoints of a rational clipping curve.

Definition at line 45 of file ClipperShape.h.

◆ clipperShape()

template<ClipperCurve Curve, FloatType T>
T dspark::detail::clipperShape ( T  sample,
T  ceiling 
)
inlinenoexcept

Shared transfer functions; no state or implicit antialiasing.

Definition at line 62 of file ClipperShape.h.

◆ clipperSmallSignalSlope()

template<ClipperCurve Curve, FloatType T>
constexpr T dspark::detail::clipperSmallSignalSlope ( )
constexprnoexcept

Exact small-signal slope of the implemented stateless curve.

Definition at line 35 of file ClipperShape.h.

◆ dcBlockStep()

double dspark::detail::dcBlockStep ( double  pole,
DcBlockState &  state,
double  input 
)
inlinenoexcept

Applies (1 - z^-1) / (1 - pole * z^-1), with a pole in [0, 1).

Definition at line 24 of file DcBlock.h.

◆ designSincPhase()

template<int Count, typename T >
void dspark::detail::designSincPhase ( T *  out,
double  beta,
double  frac 
)
inlinenoexcept

Definition at line 289 of file TruePeakDetector.h.

◆ eighthCrests()

template<typename T >
T dspark::detail::eighthCrests ( const T *  a,
const T *  e,
int  u,
T  m 
)
inlinenoexcept

Definition at line 363 of file TruePeakDetector.h.

◆ gridReading()

template<typename T >
T dspark::detail::gridReading ( const T *  s,
const T *  q,
const T *  h,
const T *  t,
int  i 
)
inlinenoexcept

Definition at line 345 of file TruePeakDetector.h.

◆ hilbertIdealImpulse()

double dspark::detail::hilbertIdealImpulse ( std::int64_t  index)
inlinenoexcept

Definition at line 41 of file Hilbert.h.

◆ integralLogCosh()

double dspark::detail::integralLogCosh ( double  x)
inlinenoexcept

Integral of log(cosh(x)), with value zero at the origin. A Chebyshev polynomial handles |x| < 1 without cancellation. The outer branch integrates the exponentially convergent log1p expansion; its omitted dilogarithm tail is below 5e-18 at |x| >= 1.

Definition at line 48 of file LogCosh.h.

◆ integralLogCoshTail()

double dspark::detail::integralLogCoshTail ( double  a)
inlinenoexcept

For a >= 1: integralLogCosh(a) - (a^2/2 - a ln 2 + pi^2/24), the exponentially small part 0.5 Li2(-e^{-2a}) (|value| < 0.07). The dilogarithm series is cut after 16 terms, below 5e-18 at a >= 1.

Definition at line 34 of file LogCosh.h.

◆ ladderInputRefresh()

void dspark::detail::ladderInputRefresh ( LadderInputState &  h,
const LadderInputCoeffs &  c 
)
inlinenoexcept

Recomputes the carried sums after the states or the coefficients changed.

Definition at line 443 of file LadderZdf.h.

◆ ladderStep()

template<LadderTap Tap, FloatType T>
T dspark::detail::ladderStep ( T  input,
std::array< T, 4 > &  z,
const LadderCoeffs< T > &  c,
T  drive 
)
inlinenoexcept

Advances the four TPT one-pole stages and the resolved feedback loop by one sample.

Parameters
inputCurrent input sample.
zIntegrator states, updated in place.
cCoefficients from makeLadderCoeffs().
driveFeedback saturation: values above 1 pass the estimated feedback through a bounded tanh, at or below 1 it is linear.

Definition at line 71 of file LadderZdf.h.

◆ ladderStepInput()

template<LadderTap Tap, FloatType T>
DSPARK_LADDER_INLINE T dspark::detail::ladderStepInput ( T  input,
LadderInputState &  h,
const LadderInputCoeffs &  c 
)
noexcept

Advances the input-saturating ladder by one sample.

Linear trapezoidal stages with one saturator on the loop input,

dy_i/dt = wc * (y_{i-1} - y_i),  y_0 = phi(x - k * y_4),
phi(v)  = tanh(drive * v) / drive,

run in kLadderInputSubsteps sub-steps per sample: the input is interpolated linearly across them and the output is their mean, each with its level correction. The loop is closed without delay in every sub-step. With the cascade written y_4 = G^4 w + S (S from the states), the loop input u solves u + k G^4 phi(u) = x - k S. k G^4 stays below 0.036 at every setting (the sub-steps keep G small), so one Newton step from the explicit value r = x - k S leaves the square of that: phi(u) = t / (1 + k G^4 (1 - t^2)), t = tanh(drive r). The arithmetic is double whatever T is; the tanh is ladderTanh()'s rational function.

What a sample costs is the path from one loop drive to the next, so that path is kept to the saturator and one subtraction: the feedback sum a sub-step leaves behind is formed as cAhead . s, from the states it started from, plus kappa times its saturator output, and the stages themselves advance off that path. The function is always inlined: a block loop then keeps the state in registers and loads the coefficients once.

Parameters
inputCurrent input sample.
hState of the channel, updated in place. Its carried sums must match its integrators and c (ladderInputRefresh() after either changed outside this function).
cCoefficients from makeLadderInputCoeffs().

Definition at line 644 of file LadderZdf.h.

◆ ladderStepInputPair()

template<LadderTap Tap, FloatType T>
DSPARK_LADDER_INLINE void dspark::detail::ladderStepInputPair ( T &  a,
T &  b,
LadderInputState &  ha,
LadderInputState &  hb,
const LadderInputCoeffs &  c 
)
noexcept

ladderStepInput() on two channels at once, sub-step by sub-step.

The two solves are independent, so taking their sub-steps in turn lets their dependency chains overlap. Each channel's arithmetic is that of ladderStepInput(): the outputs are the same.

Parameters
aFirst channel's sample, replaced by its output.
bSecond channel's sample, replaced by its output.
haFirst channel's state.
hbSecond channel's state.
cCoefficients from makeLadderInputCoeffs().

Definition at line 666 of file LadderZdf.h.

◆ ladderStepStages()

template<LadderTap Tap, FloatType T>
T dspark::detail::ladderStepStages ( T  input,
std::array< T, 4 > &  z,
const LadderStageCoeffs &  c 
)
inlinenoexcept

Advances the per-stage saturating ladder by one sample.

Solves the trapezoidal (TPT) discretization of the transistor-ladder model (Huovilainen 2004; D'Angelo and Valimaki 2013)

dy_i/dt = wc * [phi(y_{i-1}) - phi(y_i)],  y_0 = x - k * y_4,
phi(v)  = tanh(drive * v) / drive,

where every stage saturates and the feedback loop is delay-free. The four implicit stage equations y_i = s_i + g * (phi(y_{i-1}) - phi(y_i)) are solved jointly, as in Zavalishin's TPT treatment of nonlinear zero-delay loops:

  1. Start. Below kLadderStagesStateStartGain the states themselves. Above it, the drive-free ladder solved exactly (the linear prediction, no division) while every stage of it stays within kLadderStagesLinearStartLimit knee widths, otherwise a fixed-pivot linear solve (each phi replaced by v * phi(s)/s at the integrator states), a stable starting point at any gain.
  2. Newton iterations on the four equations. The Jacobian is bidiagonal plus the feedback corner, so each step is an O(4) elimination, and the closing pivot is always >= 1 (no singularity at any setting). Each step is clipped to one knee width (1 / drive): undamped Newton cycles between the two saturation branches once g exceeds about 1.

The solve runs in double whatever T is. It stops when the largest update falls below c.tol knee widths, after at most kLadderStagesMaxIterations steps: measured with the float tolerance over noise, sine and saw inputs at 44.1 to 96 kHz, cutoff 0.004 to 0.45 * fs, resonance 0 to 1.15 and drive 0.3 to 10, a mean of 2.2 steps counting a fixed-pivot start as one (2.7 with the fixed-pivot start at every gain above the state-start limit), 4.1 Newton steps at the worst setting, and at most 7 (the cap is never reached). In the linear limit (drive -> 0) it reduces to ladderStep() without drive. Output taps are those of ladderStep().

Parameters
inputCurrent input sample.
zIntegrator states, updated in place.
cCoefficients from makeLadderStageCoeffs().

Definition at line 278 of file LadderZdf.h.

◆ ladderTanh()

double dspark::detail::ladderTanh ( double  a)
inlinenoexcept

tanh(a) by its [9/8] continued-fraction convergent, clamped to +-1 where the convergent reaches 1 (|a| = 6.297).

Absolute error below 6.8e-6 everywhere; the clamp leaves a slope step of 2.5e-5. The numerator and denominator are also used by ladderTanhRatio().

Definition at line 182 of file LadderZdf.h.

◆ ladderTanhParts()

void dspark::detail::ladderTanhParts ( double  a2,
double &  num,
double &  den 
)
inlinenoexcept

The two polynomials of ladderTanh() in a^2 (tanh(a) = a num / den), each summed as two halves so that both are ready four operations after a^2.

Definition at line 402 of file LadderZdf.h.

◆ ladderTanhRatio()

double dspark::detail::ladderTanhRatio ( double  a)
inlinenoexcept

ladderTanh(a) / a, finite at a = 0 (where it is 1).

Definition at line 194 of file LadderZdf.h.

◆ logCosh()

double dspark::detail::logCosh ( double  x)
inlinenoexcept

Stable log(cosh(x)), shared by the tanh antiderivative kernels.

Definition at line 18 of file LogCosh.h.

◆ makeLadderCoeffs()

template<FloatType T>
LadderCoeffs< T > dspark::detail::makeLadderCoeffs ( T  g,
T  res 
)
inlinenoexcept

Derives the ladder coefficients.

Parameters
gPrewarped integrator gain, tan(pi * fc / fs).
resResonance 0..1; 1 is the self-oscillation boundary (k = 4).

Definition at line 48 of file LadderZdf.h.

◆ makeLadderInputCoeffs()

template<FloatType T>
LadderInputCoeffs dspark::detail::makeLadderInputCoeffs ( double  cutoffRatio,
T  res,
T  drive 
)
inlinenoexcept

Derives the coefficients of the input-saturating ladder.

The integrators are prewarped at the sub-step rate, so the cutoff is exact and the response below it is that of a ladder at (4 fs / pi) tan(pi fc / (4 fs)): within 0.2% of fc at 0.1 fs and 4.4% at 0.45 fs.

Parameters
cutoffRatioCutoff as a fraction of the sample rate; held within (0, 0.499].
resResonance; 1 is the self-oscillation boundary (k = 4).
driveLevel scale of the saturator (> 0): the loop input saturates as tanh(drive * v) / drive.

Definition at line 465 of file LadderZdf.h.

◆ makeLadderStageCoeffs()

template<FloatType T>
LadderStageCoeffs dspark::detail::makeLadderStageCoeffs ( T  g,
T  res,
T  drive 
)
inlinenoexcept

Derives the coefficients of the per-stage saturating ladder.

Parameters
gPrewarped integrator gain, tan(pi * fc / fs); clamped to kLadderStagesMaxGain.
resResonance; 1 is the self-oscillation boundary (k = 4).
driveLevel scale of the stage nonlinearity (> 0): a stage saturates as tanh(drive * v) / drive.

Definition at line 153 of file LadderZdf.h.

◆ offlineBandlimitedProduct()

template<class LeftReader , class RightReader , class Consumer >
void dspark::detail::offlineBandlimitedProduct ( OfflineSession &  job,
std::int64_t  frames,
LeftReader  left,
RightReader  right,
Consumer  consume,
int  block = 0 
)
inline

Definition at line 460 of file OfflineProduct.h.

◆ offlineBytes()

std::size_t dspark::detail::offlineBytes ( std::uint64_t  count,
std::size_t  size 
)
inline

Definition at line 289 of file OfflineProcessing.h.

◆ offlineCalibrateClip()

template<class Render >
OfflineClipCalibration dspark::detail::offlineCalibrateClip ( double  initialCeiling,
double  target,
Render  render 
)

Definition at line 82 of file OfflineClip.h.

◆ offlineCallSink()

template<class Function >
void dspark::detail::offlineCallSink ( Function &&  function)
inline

Definition at line 186 of file OfflineWorker.h.

◆ offlineClipPeakErrorDb()

double dspark::detail::offlineClipPeakErrorDb ( double  peak,
double  target 
)
inlinenoexcept

Definition at line 62 of file OfflineClip.h.

◆ offlineClipTargetMet()

bool dspark::detail::offlineClipTargetMet ( double  peak,
double  target,
double  errorDb 
)
inlinenoexcept

Definition at line 70 of file OfflineClip.h.

◆ offlineExceptionStatus()

OfflineStatus dspark::detail::offlineExceptionStatus ( )
inlinenoexcept

Definition at line 269 of file OfflineProcessing.h.

◆ offlineFail()

void dspark::detail::offlineFail ( OfflineStatus  status)
inline

Definition at line 262 of file OfflineProcessing.h.

◆ offlineHash()

template<FloatType T>
void dspark::detail::offlineHash ( OfflineFingerprint &  state,
T  sample 
)
inlinenoexcept

Definition at line 537 of file OfflineProcessing.h.

◆ offlineRead()

template<FloatType T>
void dspark::detail::offlineRead ( OfflineAudioSource< T > &  source,
const OfflineAudioSpec &  expected,
std::int64_t  first,
AudioBufferView< T >  block 
)
inline

Definition at line 517 of file OfflineProcessing.h.

◆ offlineRemaining()

OfflineJobOptions dspark::detail::offlineRemaining ( const OfflineJobOptions &  job,
std::size_t  used 
)
inline

Definition at line 469 of file OfflineProcessing.h.

◆ offlineRenderGain()

template<class Result , FloatType T, class Report , class CursorFactory >
Result dspark::detail::offlineRenderGain ( OfflineAudioSource< T > &  source,
const OfflineAudioSpec &  spec,
const OfflineFingerprint &  expectedFingerprint,
double  inputPeak,
bool  valid,
bool  changed,
const Report &  report,
OfflineAudioSink< T > &  sink,
const OfflineJobOptions &  options,
CursorFactory  makeCursor,
OfflineGainRenderSettings  settings = {} 
)

Definition at line 124 of file OfflineGain.h.

◆ offlineRepresentablePeakGain()

template<FloatType T>
double dspark::detail::offlineRepresentablePeakGain ( double  inputPeak,
double  gain 
)
inlinenoexcept

Definition at line 26 of file OfflineWorker.h.

◆ offlineRun()

template<class Processor , FloatType T, int MaxChannels, class Options >
Processor::Result dspark::detail::offlineRun ( const Processor &  processor,
const AudioBuffer< T, MaxChannels > &  input,
AudioBuffer< T, MaxChannels > &  output,
double  sampleRate,
const Options &  options,
const OfflineJobOptions &  job 
)

Definition at line 206 of file OfflineWorker.h.

◆ offlineScanMagnitude()

template<FloatType T, class Consume >
void dspark::detail::offlineScanMagnitude ( OfflineAudioSource< T > &  source,
const OfflineAudioSpec &  spec,
const OfflineFingerprint &  expectedFingerprint,
double  inputPeak,
OfflineBlock< T > &  scratch,
const OfflineSession &  job,
Consume  consume 
)
inline

Definition at line 82 of file OfflineWorker.h.

◆ offlineScanSource()

template<FloatType T, class Consume >
OfflineSourceSummary dspark::detail::offlineScanSource ( OfflineAudioSource< T > &  source,
const OfflineAudioSpec &  spec,
OfflineBlock< T > &  scratch,
const OfflineSession &  job,
OfflinePhase  phase,
Consume  consume 
)
inline

Definition at line 45 of file OfflineWorker.h.

◆ offlineValidateSpec()

void dspark::detail::offlineValidateSpec ( const OfflineAudioSpec &  spec,
int  maximumChannels = 16 
)
inline

Definition at line 479 of file OfflineProcessing.h.

◆ parseStateJsonNumber()

const char * dspark::detail::parseStateJsonNumber ( const char *  s,
const char *  end,
double &  out 
)
inlinenoexcept

Locale-independent number parse over [s, end); nullptr on failure.

Definition at line 344 of file StateBlob.h.

◆ raiseToEighthSamples()

template<typename T >
void dspark::detail::raiseToEighthSamples ( const T *  a,
const T *  e,
T *  peak,
int  first,
int  n 
)
inlinenoexcept

Definition at line 375 of file TruePeakDetector.h.

◆ rationalKneeIntegral()

double dspark::detail::rationalKneeIntegral ( double  input,
double  positiveKnee,
double  negativeKnee 
)
inlinenoexcept

Antiderivative of the unit-ceiling curve, with F(0) = 0.

Definition at line 39 of file RationalKnee.h.

◆ rationalKneeMagnitude()

template<FloatType T>
T dspark::detail::rationalKneeMagnitude ( T  magnitude,
T  knee,
T  ceiling 
)
inlinenoexcept

Positive magnitude of the original Clipper rational soft knee.

Definition at line 21 of file RationalKnee.h.

◆ rationalKneeShape()

double dspark::detail::rationalKneeShape ( double  input,
double  positiveKnee,
double  negativeKnee 
)
inlinenoexcept

Unit-ceiling curve with independent positive and negative knees.

Definition at line 31 of file RationalKnee.h.

◆ refineVertex()

template<typename T >
T dspark::detail::refineVertex ( T  a,
T  b,
T  c,
T  m 
)
inlinenoexcept

Definition at line 326 of file TruePeakDetector.h.

◆ sampleGatherNarrow()

template<int C, FloatType T>
void dspark::detail::sampleGatherNarrow ( const T *  r0,
const T *  r1,
T  g,
const T *  x0,
const T *  x1,
int  taps,
T *  out 
)
inlinenoexcept

Unit-scale gather of C (1 or 2) channels: the weights are the rows r0 and r1 blended by g, tap by tap, and each channel's sum is formed in the order of kSampleGatherLanes.

Parameters
r0First weight row, taps coefficients.
r1Second weight row, taps coefficients.
gBlend from r0 toward r1: the weight is r0 + g * (r1 - r0).
x0First channel's samples, taps of them.
x1Second channel's samples, taps of them (unused for C = 1).
tapsKernel length, a multiple of kSampleGatherLanes.
outOne sum per channel.

Definition at line 185 of file SampleReader.h.

◆ sampleGatherReduce()

template<FloatType T>
T dspark::detail::sampleGatherReduce ( const T *  lane)
inlinenoexcept

The final reduction of the eight partial sums.

Definition at line 167 of file SampleReader.h.

◆ sampleZonePanGains()

void dspark::detail::sampleZonePanGains ( double  pan,
int  channels,
double  gain,
double &  left,
double &  right,
double &  mono 
)
inlinenoexcept

Output gains of a zone at gain: a mono zone pans with constant power (unity at centre), a multichannel one balances its first two channels. mono is the gain for a single output channel.

Definition at line 143 of file SampleReader.h.

◆ stateFromJsonImpl()

std::vector< uint8_t > dspark::detail::stateFromJsonImpl ( const std::string &  json,
int  depth 
)
inline

Definition at line 441 of file StateBlob.h.

◆ stateToJsonImpl()

std::string dspark::detail::stateToJsonImpl ( const std::vector< uint8_t > &  blob,
int  depth 
)
inline

Definition at line 401 of file StateBlob.h.

◆ tptSvfStep()

template<FloatType T>
TptSvfOutput< T > dspark::detail::tptSvfStep ( T  input,
TptSvfState< T > &  state,
T  a1,
T  a2,
T  a3 
)
inlinenoexcept

Advances the expanded Simper TPT recurrence by one sample.

Parameters
inputCurrent input sample.
stateIntegrator memories, updated in place.
a11 / (1 + g * (g + k)), where g = tan(pi * f / fs) and k = 1 / Q.
a2g * a1.
a3g * a2.
Note
Keeps the operation order of StateVariableFilter, including its state update. See https://cytomic.com/files/dsp/SvfLinearTrapOptimised2.pdf .

Definition at line 43 of file TptSvf.h.

◆ wavetableFrame()

WavetableFrame dspark::detail::wavetableFrame ( double  position,
int  numFrames 
)
inlinenoexcept

Definition at line 119 of file WavetableBank.h.

Variable Documentation

◆ fastSinPolynomial

template<FloatType T>
constexpr std::array<T, 5> dspark::detail::fastSinPolynomial
inlineconstexpr
Initial value:
{
T(0.99999997408724855), T(-0.16666646026660671), T(0.0083328727116396326),
T(-0.00019799239565814083), T(2.5871610835732768e-6)}

Definition at line 38 of file DspMath.h.

◆ kLadderInputSubsteps

constexpr int dspark::detail::kLadderInputSubsteps = 4
inlineconstexpr

Sub-steps per sample of the input-saturating ladder.

Definition at line 391 of file LadderZdf.h.

◆ kLadderStagesLinearStartLimit

constexpr double dspark::detail::kLadderStagesLinearStartLimit = 2.0
inlineconstexpr

Largest stage level of the linear prediction, in knee widths, at which ladderStepStages() starts Newton from that prediction (above kLadderStagesStateStartGain).

The prediction is the drive-free ladder solved exactly (a dozen operations, no division): close to the root wherever the stages are not deep in saturation, and often closer than the fixed-pivot solve, which costs about one Newton step. With the float tolerance over noise, sines and a saw at 44.1 to 96 kHz, cutoff 0.004 to 0.45 * fs, resonance 0 to 1.15 and drive 0.3 to 10, the mean cost falls from 2.7 to 2.2 steps (a fixed-pivot start counted as one), and from 2.9 to 2.0 for sines at a 15 kHz cutoff with drive 3. Beyond the limit the fixed-pivot start takes over.

Definition at line 234 of file LadderZdf.h.

◆ kLadderStagesMaxGain

constexpr double dspark::detail::kLadderStagesMaxGain = 6.313751514675041
inlineconstexpr

Largest prewarped integrator gain of the per-stage model: tan(0.45 pi), a cutoff of 0.45 * fs.

Above it the exact trapezoidal solution of the saturating stages stops being an audio signal: at a cutoff of 0.499 * fs (gain 280) its states grew to 90 and its output to 8.6 times full scale on full-scale noise, while at 0.45 * fs they stay below 6 and 1.6.

Definition at line 133 of file LadderZdf.h.

◆ kLadderStagesMaxIterations

constexpr int dspark::detail::kLadderStagesMaxIterations = 16
inlineconstexpr

Newton step cap of ladderStepStages() (the worst case measured is 10).

Definition at line 206 of file LadderZdf.h.

◆ kLadderStagesStateStartGain

constexpr double dspark::detail::kLadderStagesStateStartGain = 0.15
inlineconstexpr

Integrator gain below which ladderStepStages() falls back to the integrator states instead of the fixed-pivot solve (cutoff about 0.047 * fs) when the linear prediction is not used.

At a low gain each stage moves little in one sample, so the states are already a close start and the fixed-pivot solve (five tanh ratios and five divisions, about one Newton step of work) does not pay for itself. Above it the fixed-pivot start saves more than it costs.

Definition at line 218 of file LadderZdf.h.

◆ kLadderTanhLimit

constexpr double dspark::detail::kLadderTanhLimit = 6.297019181717114
inlineconstexpr

Where ladderTanh()'s rational function reaches 1, and that squared.

Definition at line 394 of file LadderZdf.h.

◆ kLadderTanhLimit2

constexpr double dspark::detail::kLadderTanhLimit2 = kLadderTanhLimit * kLadderTanhLimit
inlineconstexpr

Definition at line 395 of file LadderZdf.h.

◆ kMaxStateJsonDepth

constexpr int dspark::detail::kMaxStateJsonDepth = 32
constexpr

Nesting cap for the JSON round-trip: real processor states nest 2-3 levels; a crafted input must not be able to overflow the stack.

Definition at line 292 of file StateBlob.h.

◆ kSampleGatherLanes

constexpr int dspark::detail::kSampleGatherLanes = 8
inlineconstexpr

Lanes of the unit-scale gather's partial sums: tap t adds into sum t % 8, and the eight sums meet as ((s0 + s4) + (s1 + s5)) + ((s2 + s6) + (s3 + s7)).

Definition at line 163 of file SampleReader.h.

◆ kWavetableNiemitalo

constexpr std::array<double, 18> dspark::detail::kWavetableNiemitalo
inlineconstexpr
Initial value:
= {
0.41496902959240894, 0.08343081932889224, 0.00160015038681571,
0.31625515004859783, 0.21197848565176958, 0.00956166668408054,
-0.203271896548875371, 0.17989908432249280, 0.02337283412161328,
-0.20209241069835732, 0.01760734419526000, 0.02985927012435252,
0.04100948858761910, -0.06147760875085254, 0.02046802954581191,
0.06607747864416924, -0.03255079211953620, 0.00628989632244913 }

Niemitalo's 4x 6-point coefficients, three per polynomial coefficient c0..c5, in the order WavetableBank's interpolator uses them.

Definition at line 90 of file WavetableBank.h.

◆ kWavetableOneLevel

constexpr int dspark::detail::kWavetableOneLevel = 0
inlineconstexpr

Level layouts of a block: one level, two levels on one grid, two grids.

Definition at line 133 of file WavetableBank.h.

◆ kWavetableSameGrid

constexpr int dspark::detail::kWavetableSameGrid = 1

Definition at line 133 of file WavetableBank.h.

◆ kWavetableTwoGrids

constexpr int dspark::detail::kWavetableTwoGrids = 2

Definition at line 133 of file WavetableBank.h.