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

Zero-latency, highly optimized allpass-based phaser. More...

#include <Phaser.h>

Collaboration diagram for dspark::Phaser< T >:

Classes

struct  FirstOrderAllpass
 

Public Member Functions

 ~Phaser ()=default
 
void prepare (const AudioSpec &spec)
 Prepares the phaser and allocates internal state blocks.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes an audio block in-place.
 
void reset () noexcept
 Clears internal DSP state and history buffers. Call this when transport stops or playback jumps.
 
void setRate (T hz) noexcept
 Sets the speed of the phaser sweep.
 
void setDepth (T amount) noexcept
 Sets how wide the frequency sweep is.
 
void setMix (T dryWet) noexcept
 Balances the unprocessed and processed signal.
 
void setStages (int count) noexcept
 Configures the intensity/color of the phaser via filter stages.
 
void setFeedback (T amount) noexcept
 Injects phase-shifted signal back into the input for resonance.
 
void setStereoSpread (T amount) noexcept
 Sets the stereo phase spread of the sweep LFO.
 
void setCenterFrequency (T hz) noexcept
 Defines the midpoint of the logarithmic frequency sweep.
 
void setFrequencyRange (T minHz, T maxHz) noexcept
 Explicitly defines the sweep boundaries.
 
void setLfoWaveform (typename Oscillator< T >::Waveform wf) noexcept
 Changes the geometric shape of the LFO modulation.
 
int getStages () const noexcept
 Retrieves the active stage count.
 
getRate () const noexcept
 Retrieves the current sweep rate.
 
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).
 

Static Public Attributes

static constexpr int kMaxStages = 12
 

Protected Attributes

AudioSpec spec_ {}
 
std::atomic< T > rate_ { T(0.5) }
 
std::atomic< T > depth_ { T(0.8) }
 
std::atomic< T > mix_ { T(0.5) }
 
std::atomic< T > feedback_ { T(0) }
 
std::atomic< T > minFreq_ { T(200) }
 
std::atomic< T > maxFreq_ { T(6000) }
 
std::atomic< int > numStages_ { 4 }
 
std::atomic< typename Oscillator< T >::Waveform > lfoWaveform_ { Oscillator<T>::Waveform::Sine }
 
std::atomic< T > stereoSpread_ { T(0) }
 
bool prepared_ { false }
 
currentDepth_ { T(0.8) }
 
currentFb_ { T(0) }
 
smoothCoef_ { T(0.01) }
 
lastSpread_ { T(-1) }
 
int lastStages_ { kMaxStages }
 
std::array< FirstOrderAllpass, kMaxStagesstages_ {}
 
std::array< T, kMaxChannelsfbState_ {}
 
Oscillator< T > lfo_
 
Oscillator< T > lfoR_
 
DryWetMixer< T > mixer_
 

Static Protected Attributes

static constexpr int kMaxChannels = 16
 

Detailed Description

template<FloatType T>
class dspark::Phaser< T >

Zero-latency, highly optimized allpass-based phaser.

Employs parameter smoothing to prevent zipper noise and utilizes fast math approximations for real-time performance.

Template Parameters
TSample type (must satisfy FloatType concept, e.g., float or double).

Definition at line 66 of file Phaser.h.

Constructor & Destructor Documentation

◆ ~Phaser()

template<FloatType T>
dspark::Phaser< T >::~Phaser ( )
default

Member Function Documentation

◆ getRate()

template<FloatType T>
T dspark::Phaser< T >::getRate ( ) const
inlinenoexcept

Retrieves the current sweep rate.

Returns
Rate in Hz.

Definition at line 379 of file Phaser.h.

◆ getStages()

template<FloatType T>
int dspark::Phaser< T >::getStages ( ) const
inlinenoexcept

Retrieves the active stage count.

Returns
Number of stages.

Definition at line 376 of file Phaser.h.

◆ getState()

template<FloatType T>
std::vector< uint8_t > dspark::Phaser< T >::getState ( ) const
inline

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

Definition at line 383 of file Phaser.h.

◆ prepare()

template<FloatType T>
void dspark::Phaser< T >::prepare ( const AudioSpec spec)
inline

Prepares the phaser and allocates internal state blocks.

An invalid spec (non-positive or non-finite fields) is a no-op that keeps the previous state.

Parameters
specHardware audio specifications (sample rate, block size).

Definition at line 83 of file Phaser.h.

◆ processBlock()

template<FloatType T>
void dspark::Phaser< T >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes an audio block in-place.

Parameters
bufferThe AudioBufferView containing channels to process.

Definition at line 109 of file Phaser.h.

◆ reset()

template<FloatType T>
void dspark::Phaser< T >::reset ( )
inlinenoexcept

Clears internal DSP state and history buffers. Call this when transport stops or playback jumps.

Definition at line 231 of file Phaser.h.

◆ setCenterFrequency()

template<FloatType T>
void dspark::Phaser< T >::setCenterFrequency ( hz)
inlinenoexcept

Defines the midpoint of the logarithmic frequency sweep.

Keeps the current sweep RATIO and recenters it geometrically. Callable before prepare() (a 20 kHz ceiling stands in for Nyquist until the rate is known; the per-sample cutoff clamp covers later rate changes anyway).

Parameters
hzCenter frequency in Hertz (non-positive or non-finite values are ignored).

Definition at line 332 of file Phaser.h.

◆ setDepth()

template<FloatType T>
void dspark::Phaser< T >::setDepth ( amount)
inlinenoexcept

Sets how wide the frequency sweep is.

Parameters
amountRange: [0.0 (static), 1.0 (full spectrum)]. Non-finite values are ignored.

Definition at line 267 of file Phaser.h.

◆ setFeedback()

template<FloatType T>
void dspark::Phaser< T >::setFeedback ( amount)
inlinenoexcept

Injects phase-shifted signal back into the input for resonance.

Parameters
amountFeedback gain. Range: [-0.99, 0.99]. Negative values alter the vocal formant shape. Non-finite values are ignored.

Definition at line 300 of file Phaser.h.

◆ setFrequencyRange()

template<FloatType T>
void dspark::Phaser< T >::setFrequencyRange ( minHz,
maxHz 
)
inlinenoexcept

Explicitly defines the sweep boundaries.

Parameters
minHzLower limit of the allpass cutoff sweep.
maxHzUpper limit of the allpass cutoff sweep. Non-finite values are ignored.

Definition at line 353 of file Phaser.h.

◆ setLfoWaveform()

template<FloatType T>
void dspark::Phaser< T >::setLfoWaveform ( typename Oscillator< T >::Waveform  wf)
inlinenoexcept

Changes the geometric shape of the LFO modulation.

Parameters
wfTarget waveform (e.g., Sine, Triangle; wild enum values clamp).

Definition at line 367 of file Phaser.h.

◆ setMix()

template<FloatType T>
void dspark::Phaser< T >::setMix ( dryWet)
inlinenoexcept

Balances the unprocessed and processed signal.

Parameters
dryWetRange: [0.0 (fully dry), 1.0 (fully wet)]. Non-finite values are ignored.

Definition at line 278 of file Phaser.h.

◆ setRate()

template<FloatType T>
void dspark::Phaser< T >::setRate ( hz)
inlinenoexcept

Sets the speed of the phaser sweep.

Parameters
hzLFO frequency in Hertz. Range: [0.01, 20.0]. Non-finite values are ignored.

Definition at line 256 of file Phaser.h.

◆ setStages()

template<FloatType T>
void dspark::Phaser< T >::setStages ( int  count)
inlinenoexcept

Configures the intensity/color of the phaser via filter stages.

Parameters
countNumber of allpass stages. Range: [1, 12]. Evens (2,4,6) are standard.

Definition at line 290 of file Phaser.h.

◆ setState()

template<FloatType T>
bool dspark::Phaser< T >::setState ( const uint8_t *  data,
size_t  size 
)
inline

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

Definition at line 400 of file Phaser.h.

◆ setStereoSpread()

template<FloatType T>
void dspark::Phaser< T >::setStereoSpread ( amount)
inlinenoexcept

Sets the stereo phase spread of the sweep LFO.

Offsets the right channel's LFO phase against the left, like classic hardware stereo phasers. 0 = mono-coherent sweep (both channels move together), 1 = fully opposed (180-degree) sweep.

Parameters
amountSpread amount [0.0, 1.0]. Applied on the audio thread. Non-finite values are ignored.

Definition at line 316 of file Phaser.h.

Member Data Documentation

◆ currentDepth_

template<FloatType T>
T dspark::Phaser< T >::currentDepth_ { T(0.8) }
protected

Definition at line 435 of file Phaser.h.

◆ currentFb_

template<FloatType T>
T dspark::Phaser< T >::currentFb_ { T(0) }
protected

Definition at line 436 of file Phaser.h.

◆ depth_

template<FloatType T>
std::atomic<T> dspark::Phaser< T >::depth_ { T(0.8) }
protected

Definition at line 424 of file Phaser.h.

◆ fbState_

template<FloatType T>
std::array<T, kMaxChannels> dspark::Phaser< T >::fbState_ {}
protected

Definition at line 449 of file Phaser.h.

◆ feedback_

template<FloatType T>
std::atomic<T> dspark::Phaser< T >::feedback_ { T(0) }
protected

Definition at line 426 of file Phaser.h.

◆ kMaxChannels

template<FloatType T>
constexpr int dspark::Phaser< T >::kMaxChannels = 16
staticconstexprprotected

Definition at line 418 of file Phaser.h.

◆ kMaxStages

template<FloatType T>
constexpr int dspark::Phaser< T >::kMaxStages = 12
staticconstexpr

Definition at line 71 of file Phaser.h.

◆ lastSpread_

template<FloatType T>
T dspark::Phaser< T >::lastSpread_ { T(-1) }
protected

Definition at line 438 of file Phaser.h.

◆ lastStages_

template<FloatType T>
int dspark::Phaser< T >::lastStages_ { kMaxStages }
protected

Definition at line 439 of file Phaser.h.

◆ lfo_

template<FloatType T>
Oscillator<T> dspark::Phaser< T >::lfo_
protected

Definition at line 450 of file Phaser.h.

◆ lfoR_

template<FloatType T>
Oscillator<T> dspark::Phaser< T >::lfoR_
protected

Definition at line 451 of file Phaser.h.

◆ lfoWaveform_

template<FloatType T>
std::atomic<typename Oscillator<T>::Waveform> dspark::Phaser< T >::lfoWaveform_ { Oscillator<T>::Waveform::Sine }
protected

Definition at line 430 of file Phaser.h.

◆ maxFreq_

template<FloatType T>
std::atomic<T> dspark::Phaser< T >::maxFreq_ { T(6000) }
protected

Definition at line 428 of file Phaser.h.

◆ minFreq_

template<FloatType T>
std::atomic<T> dspark::Phaser< T >::minFreq_ { T(200) }
protected

Definition at line 427 of file Phaser.h.

◆ mix_

template<FloatType T>
std::atomic<T> dspark::Phaser< T >::mix_ { T(0.5) }
protected

Definition at line 425 of file Phaser.h.

◆ mixer_

template<FloatType T>
DryWetMixer<T> dspark::Phaser< T >::mixer_
protected

Definition at line 452 of file Phaser.h.

◆ numStages_

template<FloatType T>
std::atomic<int> dspark::Phaser< T >::numStages_ { 4 }
protected

Definition at line 429 of file Phaser.h.

◆ prepared_

template<FloatType T>
bool dspark::Phaser< T >::prepared_ { false }
protected

Definition at line 434 of file Phaser.h.

◆ rate_

template<FloatType T>
std::atomic<T> dspark::Phaser< T >::rate_ { T(0.5) }
protected

Definition at line 423 of file Phaser.h.

◆ smoothCoef_

template<FloatType T>
T dspark::Phaser< T >::smoothCoef_ { T(0.01) }
protected

Definition at line 437 of file Phaser.h.

◆ spec_

template<FloatType T>
AudioSpec dspark::Phaser< T >::spec_ {}
protected

Definition at line 420 of file Phaser.h.

◆ stages_

template<FloatType T>
std::array<FirstOrderAllpass, kMaxStages> dspark::Phaser< T >::stages_ {}
protected

Definition at line 448 of file Phaser.h.

◆ stereoSpread_

template<FloatType T>
std::atomic<T> dspark::Phaser< T >::stereoSpread_ { T(0) }
protected

Definition at line 431 of file Phaser.h.


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