DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::Delay< SampleType > Class Template Referencefinal

#include <Delay.h>

Classes

struct  ChannelState
 

Public Types

enum class  SmootherType {
  None , Linear , Exponential , OnePole ,
  MultiPole2 , Asymmetric , SlewLimiter , StateVariable ,
  Butterworth , CriticallyDamped
}
 
enum class  FeedbackMode { Clean , Analog }
 Feedback path colour. More...
 

Public Member Functions

void setFeedbackMode (FeedbackMode mode) noexcept
 Selects clean or analog feedback regeneration. Thread-safe.
 
FeedbackMode getFeedbackMode () const noexcept
 Returns the active feedback mode.
 
void prepare (const AudioSpec &spec, double maxDelaySeconds)
 Prepares the delay structures and allocates memory. Must be called before processing.
 
void prepareMs (const AudioSpec &spec, double maxDelayMs)
 Prepares the delay with a maximum capacity in milliseconds.
 
void reset () noexcept
 Clears the delay buffers and resets all filter and feedback states.
 
void setSmoother (SmootherType type) noexcept
 Sets the smoothing algorithm used for delay time changes.
 
void setSmoothingTime (float ms) noexcept
 Sets the smoothing transition time.
 
void setDelaySamples (SampleType samples) noexcept
 Sets the delay time in samples.
 
void setDelayMs (SampleType ms) noexcept
 Sets the delay time in milliseconds.
 
void setDelaySeconds (SampleType secs) noexcept
 Sets the delay time in seconds.
 
SampleType getCurrentDelaySamples () const noexcept
 Returns the current target delay time in samples.
 
void setFeedback (SampleType gain) noexcept
 Sets the global feedback amount.
 
void setFeedbackLpHz (SampleType freq) noexcept
 Sets the cutoff frequency for the feedback low-pass filter (0 to disable). Non-finite values are ignored.
 
void setFeedbackHpHz (SampleType freq) noexcept
 Sets the cutoff frequency for the feedback high-pass filter (0 to disable). Non-finite values are ignored.
 
SampleType processSample (int ch, SampleType input) noexcept
 Processes a single sample for a specific channel.
 
void processBlock (AudioBufferView< SampleType > buffer, SampleType delayMs, SampleType feedback=0, SampleType lpHz=0, SampleType hpHz=0) noexcept
 Processes a multi-channel block in-place.
 
void processChannel (AudioBufferView< SampleType > buffer, int ch, SampleType delayMs, SampleType feedback=0, SampleType lpHz=0, SampleType hpHz=0) noexcept
 Processes a single channel block in-place. Safe to call sequentially for different channels.
 
void pushDryToWet (AudioBufferView< const SampleType > dry) noexcept
 Copies a dry buffer into the internal wet buffer.
 
void pushDryToWet (AudioBufferView< SampleType > dry) noexcept
 Copies a dry buffer into the internal wet buffer.
 
void processWet (SampleType delayMs, SampleType feedback=0, SampleType lpHz=0, SampleType hpHz=0) noexcept
 Processes the wet buffer in place with current settings. Processes exactly the samples of the most recent pushDryToWet() call: running the full capacity regardless of the pushed length would advance the delay line past the real stream on short blocks, skewing every subsequent echo's timing.
 
void processPingPong (SampleType delayMs, SampleType feedback=0, SampleType lpHz=0, SampleType hpHz=0) noexcept
 Processes a true ping-pong delay (L feeds R, R feeds L) on the samples of the most recent pushDryToWet() call.
 
void mixWetToDry (AudioBufferView< SampleType > dry, SampleType mix) noexcept
 Mixes the processed wet buffer back into the provided dry buffer.
 
AudioBufferView< SampleType > getWetView () noexcept
 Exposes the internal wet buffer view.
 
int getMaxDelaySamples () const noexcept
 Returns maximum capacity in samples.
 
std::vector< uint8_t > getState () const
 Serializes the parameter state (setup/UI threads; allocates).
 
bool setState (const uint8_t *data, size_t size)
 Restores parameters from a blob (tolerant; rejects foreign ids).
 
void advanceWriteIndex (int ch) noexcept
 Advances the write index for a specific channel.
 

Static Protected Attributes

static constexpr int kMaxChannels = 16
 

Detailed Description

template<typename SampleType>
class dspark::Delay< SampleType >

Definition at line 46 of file Delay.h.

Member Enumeration Documentation

◆ FeedbackMode

template<typename SampleType >
enum class dspark::Delay::FeedbackMode
strong

Feedback path colour.

Enumerator
Clean 

Pristine digital regeneration: no per-pass saturation, the decay time matches the feedback gain exactly. A hard safety clamp at +-2.0 guards against runaway (|fb| >= 1).

Analog 

Tape/BBD-style tanh soft saturation on every pass (default, matches the original DSPark behaviour). Slightly shortens the decay versus the nominal feedback and adds warmth.

Definition at line 56 of file Delay.h.

◆ SmootherType

template<typename SampleType >
enum class dspark::Delay::SmootherType
strong
Enumerator
None 
Linear 
Exponential 
OnePole 
MultiPole2 
Asymmetric 
SlewLimiter 
StateVariable 
Butterworth 
CriticallyDamped 

Definition at line 49 of file Delay.h.

Member Function Documentation

◆ advanceWriteIndex()

template<typename SampleType >
void dspark::Delay< SampleType >::advanceWriteIndex ( int  ch)
inlinenoexcept

Advances the write index for a specific channel.

Parameters
chChannel index to advance. Out-of-range indices are ignored (an unchecked index would write past the index array).

Definition at line 528 of file Delay.h.

◆ getCurrentDelaySamples()

template<typename SampleType >
SampleType dspark::Delay< SampleType >::getCurrentDelaySamples ( ) const
inlinenoexcept

Returns the current target delay time in samples.

Definition at line 200 of file Delay.h.

◆ getFeedbackMode()

template<typename SampleType >
FeedbackMode dspark::Delay< SampleType >::getFeedbackMode ( ) const
inlinenoexcept

Returns the active feedback mode.

Definition at line 73 of file Delay.h.

◆ getMaxDelaySamples()

template<typename SampleType >
int dspark::Delay< SampleType >::getMaxDelaySamples ( ) const
inlinenoexcept

Returns maximum capacity in samples.

Definition at line 465 of file Delay.h.

◆ getState()

template<typename SampleType >
std::vector< uint8_t > dspark::Delay< SampleType >::getState ( ) const
inline

Serializes the parameter state (setup/UI threads; allocates).

Definition at line 469 of file Delay.h.

◆ getWetView()

template<typename SampleType >
AudioBufferView< SampleType > dspark::Delay< SampleType >::getWetView ( )
inlinenoexcept

Exposes the internal wet buffer view.

Definition at line 462 of file Delay.h.

◆ mixWetToDry()

template<typename SampleType >
void dspark::Delay< SampleType >::mixWetToDry ( AudioBufferView< SampleType >  dry,
SampleType  mix 
)
inlinenoexcept

Mixes the processed wet buffer back into the provided dry buffer.

Parameters
dryBuffer containing the dry signal.
mixMix ratio (0.0 = 100% dry, 1.0 = 100% wet). A non-finite value resolves to 0 (dry).

Definition at line 429 of file Delay.h.

◆ prepare()

template<typename SampleType >
void dspark::Delay< SampleType >::prepare ( const AudioSpec spec,
double  maxDelaySeconds 
)
inline

Prepares the delay structures and allocates memory. Must be called before processing.

Parameters
specThe audio specification (sample rate, block size, etc.). An invalid spec (non-positive or NaN fields) is ignored.
maxDelaySecondsThe maximum theoretical delay time required. Negative or NaN values are ignored; the capacity is capped at 2^29 samples.

Definition at line 88 of file Delay.h.

◆ prepareMs()

template<typename SampleType >
void dspark::Delay< SampleType >::prepareMs ( const AudioSpec spec,
double  maxDelayMs 
)
inline

Prepares the delay with a maximum capacity in milliseconds.

Parameters
specThe audio specification.
maxDelayMsMaximum delay capacity in milliseconds.

Definition at line 129 of file Delay.h.

◆ processBlock()

template<typename SampleType >
void dspark::Delay< SampleType >::processBlock ( AudioBufferView< SampleType >  buffer,
SampleType  delayMs,
SampleType  feedback = 0,
SampleType  lpHz = 0,
SampleType  hpHz = 0 
)
inlinenoexcept

Processes a multi-channel block in-place.

Note
The per-call parameters are published to the same state the individual setters write, so every call overwrites previously set values (including the defaults of the omitted arguments).
Parameters
bufferThe audio buffer to process.
delayMsDelay time in milliseconds.
feedbackFeedback gain multiplier.
lpHzLow-pass filter cutoff in Hz.
hpHzHigh-pass filter cutoff in Hz.

Definition at line 273 of file Delay.h.

◆ processChannel()

template<typename SampleType >
void dspark::Delay< SampleType >::processChannel ( AudioBufferView< SampleType >  buffer,
int  ch,
SampleType  delayMs,
SampleType  feedback = 0,
SampleType  lpHz = 0,
SampleType  hpHz = 0 
)
inlinenoexcept

Processes a single channel block in-place. Safe to call sequentially for different channels.

Definition at line 311 of file Delay.h.

◆ processPingPong()

template<typename SampleType >
void dspark::Delay< SampleType >::processPingPong ( SampleType  delayMs,
SampleType  feedback = 0,
SampleType  lpHz = 0,
SampleType  hpHz = 0 
)
inlinenoexcept

Processes a true ping-pong delay (L feeds R, R feeds L) on the samples of the most recent pushDryToWet() call.

The cross-feed obeys the active FeedbackMode exactly like the straight feedback path: tanh soft saturation in Analog mode, a +-2.0 safety clamp in Clean mode (without it, |feedback| >= 1 grew without bound).

Definition at line 373 of file Delay.h.

◆ processSample()

template<typename SampleType >
SampleType dspark::Delay< SampleType >::processSample ( int  ch,
SampleType  input 
)
inlinenoexcept

Processes a single sample for a specific channel.

Parameters
chChannel index.
inputInput sample.
Returns
Processed delayed sample (wet only).

Definition at line 240 of file Delay.h.

◆ processWet()

template<typename SampleType >
void dspark::Delay< SampleType >::processWet ( SampleType  delayMs,
SampleType  feedback = 0,
SampleType  lpHz = 0,
SampleType  hpHz = 0 
)
inlinenoexcept

Processes the wet buffer in place with current settings. Processes exactly the samples of the most recent pushDryToWet() call: running the full capacity regardless of the pushed length would advance the delay line past the real stream on short blocks, skewing every subsequent echo's timing.

Definition at line 360 of file Delay.h.

◆ pushDryToWet() [1/2]

template<typename SampleType >
void dspark::Delay< SampleType >::pushDryToWet ( AudioBufferView< const SampleType >  dry)
inlinenoexcept

Copies a dry buffer into the internal wet buffer.

Definition at line 344 of file Delay.h.

◆ pushDryToWet() [2/2]

template<typename SampleType >
void dspark::Delay< SampleType >::pushDryToWet ( AudioBufferView< SampleType >  dry)
inlinenoexcept

Copies a dry buffer into the internal wet buffer.

Definition at line 350 of file Delay.h.

◆ reset()

template<typename SampleType >
void dspark::Delay< SampleType >::reset ( )
inlinenoexcept

Clears the delay buffers and resets all filter and feedback states.

Definition at line 137 of file Delay.h.

◆ setDelayMs()

template<typename SampleType >
void dspark::Delay< SampleType >::setDelayMs ( SampleType  ms)
inlinenoexcept

Sets the delay time in milliseconds.

Definition at line 194 of file Delay.h.

◆ setDelaySamples()

template<typename SampleType >
void dspark::Delay< SampleType >::setDelaySamples ( SampleType  samples)
inlinenoexcept

Sets the delay time in samples.

Parameters
samplesTarget delay time (can be fractional). Non-finite values are ignored (a NaN here would poison the read position and, through the feedback path, the whole buffer).

Definition at line 180 of file Delay.h.

◆ setDelaySeconds()

template<typename SampleType >
void dspark::Delay< SampleType >::setDelaySeconds ( SampleType  secs)
inlinenoexcept

Sets the delay time in seconds.

Definition at line 197 of file Delay.h.

◆ setFeedback()

template<typename SampleType >
void dspark::Delay< SampleType >::setFeedback ( SampleType  gain)
inlinenoexcept

Sets the global feedback amount.

Parameters
gainFeedback gain multiplier [-1.0, 1.0]. Will be saturated internally if exceeded. Non-finite values are ignored (a NaN would recirculate through the delay buffer forever).

Definition at line 208 of file Delay.h.

◆ setFeedbackHpHz()

template<typename SampleType >
void dspark::Delay< SampleType >::setFeedbackHpHz ( SampleType  freq)
inlinenoexcept

Sets the cutoff frequency for the feedback high-pass filter (0 to disable). Non-finite values are ignored.

Definition at line 225 of file Delay.h.

◆ setFeedbackLpHz()

template<typename SampleType >
void dspark::Delay< SampleType >::setFeedbackLpHz ( SampleType  freq)
inlinenoexcept

Sets the cutoff frequency for the feedback low-pass filter (0 to disable). Non-finite values are ignored.

Definition at line 216 of file Delay.h.

◆ setFeedbackMode()

template<typename SampleType >
void dspark::Delay< SampleType >::setFeedbackMode ( FeedbackMode  mode)
inlinenoexcept

Selects clean or analog feedback regeneration. Thread-safe.

Definition at line 67 of file Delay.h.

◆ setSmoother()

template<typename SampleType >
void dspark::Delay< SampleType >::setSmoother ( SmootherType  type)
inlinenoexcept

Sets the smoothing algorithm used for delay time changes.

Parameters
typeThe desired SmootherType.

Definition at line 155 of file Delay.h.

◆ setSmoothingTime()

template<typename SampleType >
void dspark::Delay< SampleType >::setSmoothingTime ( float  ms)
inlinenoexcept

Sets the smoothing transition time.

Parameters
msTime in milliseconds. Non-finite values are ignored.

Definition at line 165 of file Delay.h.

◆ setState()

template<typename SampleType >
bool dspark::Delay< SampleType >::setState ( const uint8_t *  data,
size_t  size 
)
inline

Restores parameters from a blob (tolerant; rejects foreign ids).

Definition at line 483 of file Delay.h.

Member Data Documentation

◆ kMaxChannels

template<typename SampleType >
constexpr int dspark::Delay< SampleType >::kMaxChannels = 16
staticconstexprprotected

Definition at line 502 of file Delay.h.


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