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

Multi-voice chorus/flanger with true stereo spread and smooth parameter handling. More...

#include <Chorus.h>

Collaboration diagram for dspark::Chorus< T >:

Public Member Functions

 ~Chorus ()=default
 
void prepare (const AudioSpec &spec)
 Prepares the chorus for processing, allocating delay lines.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes an audio block in-place.
 
void reset () noexcept
 Resets delay lines and LFO phases.
 
void setRate (T hz) noexcept
 Sets the LFO modulation rate.
 
void setDepthMs (T ms) noexcept
 Sets the LFO modulation depth in milliseconds.
 
void setMix (T dryWet) noexcept
 Sets the wet/dry mix ratio.
 
void setVoices (int count) noexcept
 Sets the number of active voices per channel.
 
void setFeedback (T amount) noexcept
 Sets the feedback gain.
 
void setCenterDelay (T ms) noexcept
 Sets the base delay time.
 
void setStereoSpread (T amount) noexcept
 Sets the stereo spread amount.
 
void setAutoDepth (bool enabled) noexcept
 Couples depth to rate automatically to prevent pitch artifacts at high speeds.
 
void setModWaveform (typename Oscillator< T >::Waveform wf) noexcept
 Sets the oscillator waveform for all voices.
 
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 kMaxVoices = 4
 
static constexpr int kMaxChannels = 16
 

Protected Member Functions

void updateLfoPhases () noexcept
 Recalculates LFO phases for all channels and voices based on stereo spread.
 

Protected Attributes

AudioSpec spec_ {}
 
int maxDelaySamples_ { 0 }
 
std::atomic< T > rate_ { T(1) }
 
std::atomic< T > depthMs_ { T(3.5) }
 
std::atomic< T > mix_ { T(0.5) }
 
std::atomic< T > feedback_ { T(0) }
 
std::atomic< T > centerDelayMs_ { T(7) }
 
std::atomic< T > stereoSpread_ { T(0.5) }
 
std::atomic< int > numVoices_ { 2 }
 
std::atomic< bool > autoDepth_ { false }
 
lastSpread_ { T(0.5) }
 
std::atomic< typename Oscillator< T >::Waveform > lfoWaveform_ { Oscillator<T>::Waveform::Sine }
 
std::atomic< bool > lfoPhaseDirty_ { false }
 
std::atomic< bool > waveformDirty_ { false }
 
smoothedCenterSamples_ { T(0) }
 
smoothedDepthSamples_ { T(0) }
 
std::array< RingBuffer< T >, kMaxChannelsdelayLines_ {}
 
std::array< std::array< Oscillator< T >, kMaxVoices >, kMaxChannelslfos_ {}
 
std::array< T, kMaxChannelsfbState_ {}
 
DryWetMixer< T > mixer_
 

Detailed Description

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

Multi-voice chorus/flanger with true stereo spread and smooth parameter handling.

Template Parameters
TSample type (float or double).

Definition at line 59 of file Chorus.h.

Constructor & Destructor Documentation

◆ ~Chorus()

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

Member Function Documentation

◆ getState()

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

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

Definition at line 358 of file Chorus.h.

◆ prepare()

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

Prepares the chorus for processing, allocating delay lines.

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

Parameters
specAudio environment specification (sample rate, channels).

Definition at line 77 of file Chorus.h.

◆ processBlock()

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

Processes an audio block in-place.

Channels beyond the prepared count pass through untouched.

Parameters
bufferAudio buffer view to process (planar layout expected).

Definition at line 117 of file Chorus.h.

◆ reset()

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

Resets delay lines and LFO phases.

Definition at line 248 of file Chorus.h.

◆ setAutoDepth()

template<FloatType T>
void dspark::Chorus< T >::setAutoDepth ( bool  enabled)
inlinenoexcept

Couples depth to rate automatically to prevent pitch artifacts at high speeds.

Parameters
enabledTrue to activate automatic depth attenuation.

Definition at line 337 of file Chorus.h.

◆ setCenterDelay()

template<FloatType T>
void dspark::Chorus< T >::setCenterDelay ( ms)
inlinenoexcept

Sets the base delay time.

Parameters
msTime in milliseconds [0.1 - 30.0]. Non-finite values are ignored.

Definition at line 317 of file Chorus.h.

◆ setDepthMs()

template<FloatType T>
void dspark::Chorus< T >::setDepthMs ( ms)
inlinenoexcept

Sets the LFO modulation depth in milliseconds.

Parameters
msDepth in milliseconds [0.0 - 20.0]. Non-finite values are ignored.

Definition at line 275 of file Chorus.h.

◆ setFeedback()

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

Sets the feedback gain.

Parameters
amountFeedback from -0.99 to 0.99. Negative values yield flanger effects. Non-finite values are ignored.

Definition at line 307 of file Chorus.h.

◆ setMix()

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

Sets the wet/dry mix ratio.

Parameters
dryWetRatio from 0.0 (fully dry) to 1.0 (fully wet). Non-finite values are ignored.

Definition at line 286 of file Chorus.h.

◆ setModWaveform()

template<FloatType T>
void dspark::Chorus< T >::setModWaveform ( typename Oscillator< T >::Waveform  wf)
inlinenoexcept

Sets the oscillator waveform for all voices.

Warning
Using Saw or Square waves for delay modulation without additional lowpass filtering will cause audible clicks. Sine or Triangle are recommended.
Parameters
wfThe desired waveform type (wild enum values clamp).

Definition at line 345 of file Chorus.h.

◆ setRate()

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

Sets the LFO modulation rate.

Parameters
hzFrequency in Hertz [0.01 - 20.0]. Non-finite values are ignored.

Definition at line 265 of file Chorus.h.

◆ setState()

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

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

Definition at line 375 of file Chorus.h.

◆ setStereoSpread()

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

Sets the stereo spread amount.

Parameters
amountOffset ratio from 0.0 to 1.0. Non-finite values are ignored.

Definition at line 327 of file Chorus.h.

◆ setVoices()

template<FloatType T>
void dspark::Chorus< T >::setVoices ( int  count)
inlinenoexcept

Sets the number of active voices per channel.

Parameters
countVoices from 1 to 4.

Definition at line 296 of file Chorus.h.

◆ updateLfoPhases()

template<FloatType T>
void dspark::Chorus< T >::updateLfoPhases ( )
inlineprotectednoexcept

Recalculates LFO phases for all channels and voices based on stereo spread.

Definition at line 397 of file Chorus.h.

Member Data Documentation

◆ autoDepth_

template<FloatType T>
std::atomic<bool> dspark::Chorus< T >::autoDepth_ { false }
protected

Definition at line 430 of file Chorus.h.

◆ centerDelayMs_

template<FloatType T>
std::atomic<T> dspark::Chorus< T >::centerDelayMs_ { T(7) }
protected

Definition at line 427 of file Chorus.h.

◆ delayLines_

template<FloatType T>
std::array<RingBuffer<T>, kMaxChannels> dspark::Chorus< T >::delayLines_ {}
protected

Definition at line 442 of file Chorus.h.

◆ depthMs_

template<FloatType T>
std::atomic<T> dspark::Chorus< T >::depthMs_ { T(3.5) }
protected

Definition at line 424 of file Chorus.h.

◆ fbState_

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

Definition at line 445 of file Chorus.h.

◆ feedback_

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

Definition at line 426 of file Chorus.h.

◆ kMaxChannels

template<FloatType T>
constexpr int dspark::Chorus< T >::kMaxChannels = 16
staticconstexpr

Definition at line 65 of file Chorus.h.

◆ kMaxVoices

template<FloatType T>
constexpr int dspark::Chorus< T >::kMaxVoices = 4
staticconstexpr

Definition at line 64 of file Chorus.h.

◆ lastSpread_

template<FloatType T>
T dspark::Chorus< T >::lastSpread_ { T(0.5) }
protected

Definition at line 432 of file Chorus.h.

◆ lfoPhaseDirty_

template<FloatType T>
std::atomic<bool> dspark::Chorus< T >::lfoPhaseDirty_ { false }
protected

Definition at line 434 of file Chorus.h.

◆ lfos_

template<FloatType T>
std::array<std::array<Oscillator<T>, kMaxVoices>, kMaxChannels> dspark::Chorus< T >::lfos_ {}
protected

Definition at line 444 of file Chorus.h.

◆ lfoWaveform_

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

Definition at line 433 of file Chorus.h.

◆ maxDelaySamples_

template<FloatType T>
int dspark::Chorus< T >::maxDelaySamples_ { 0 }
protected

Definition at line 420 of file Chorus.h.

◆ mix_

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

Definition at line 425 of file Chorus.h.

◆ mixer_

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

Definition at line 447 of file Chorus.h.

◆ numVoices_

template<FloatType T>
std::atomic<int> dspark::Chorus< T >::numVoices_ { 2 }
protected

Definition at line 429 of file Chorus.h.

◆ rate_

template<FloatType T>
std::atomic<T> dspark::Chorus< T >::rate_ { T(1) }
protected

Definition at line 423 of file Chorus.h.

◆ smoothedCenterSamples_

template<FloatType T>
T dspark::Chorus< T >::smoothedCenterSamples_ { T(0) }
protected

Definition at line 438 of file Chorus.h.

◆ smoothedDepthSamples_

template<FloatType T>
T dspark::Chorus< T >::smoothedDepthSamples_ { T(0) }
protected

Definition at line 439 of file Chorus.h.

◆ spec_

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

Definition at line 419 of file Chorus.h.

◆ stereoSpread_

template<FloatType T>
std::atomic<T> dspark::Chorus< T >::stereoSpread_ { T(0.5) }
protected

Definition at line 428 of file Chorus.h.

◆ waveformDirty_

template<FloatType T>
std::atomic<bool> dspark::Chorus< T >::waveformDirty_ { false }
protected

Definition at line 435 of file Chorus.h.


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