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

Pre-allocated, SIMD-friendly dry/wet blender for real-time audio. More...

#include <DryWetMixer.h>

Public Types

enum class  MixRule { Linear , EqualPower }
 Defines the mathematical curve used for mixing. More...
 

Public Member Functions

 DryWetMixer () noexcept=default
 
 DryWetMixer (DryWetMixer &&other) noexcept
 
DryWetMixeroperator= (DryWetMixer &&other) noexcept
 
 DryWetMixer (const DryWetMixer &)=delete
 
DryWetMixeroperator= (const DryWetMixer &)=delete
 
void prepare (const AudioSpec &spec)
 Allocates the internal dry buffer for the given audio spec.
 
void reset () noexcept
 Resets the internal buffer and smoothing states to zero.
 
void setMixRule (MixRule rule) noexcept
 Sets the mathematical curve to use during the mix phase.
 
void setLatencyCompensation (int samples)
 Delays the captured dry signal to compensate for an effect's internal latency (e.g. an oversampler's FIR group delay).
 
int getLatencyCompensation () const noexcept
 Returns the configured dry-path latency compensation in samples.
 
void pushDry (const AudioBufferView< const T > &input) noexcept
 Captures a snapshot of the dry (unprocessed) signal.
 
void mixWet (AudioBufferView< T > wetBuffer, T targetMix) noexcept
 Blends the stored dry signal with the current (wet) buffer in-place.
 
const T * getDryChannel (int ch) const noexcept
 Retrieves a read-only pointer to the captured dry channel data.
 
int getDryNumChannels () const noexcept
 Returns the internal capacity of channels in the dry buffer.
 
int getDryCapturedSamples () const noexcept
 Returns the number of samples valid from the last pushDry() call.
 

Detailed Description

template<typename T, int MaxChannels = 16>
class dspark::DryWetMixer< T, MaxChannels >

Pre-allocated, SIMD-friendly dry/wet blender for real-time audio.

Template Parameters
TSample type (float or double).
MaxChannelsMaximum number of channels (compile-time bound).

Definition at line 71 of file DryWetMixer.h.

Member Enumeration Documentation

◆ MixRule

template<typename T , int MaxChannels = 16>
enum class dspark::DryWetMixer::MixRule
strong

Defines the mathematical curve used for mixing.

Enumerator
Linear 

Linear crossfade. Best for highly correlated signals (EQ, saturation).

EqualPower 

Constant power crossfade. Best for uncorrelated signals (Reverb, Delay).

Definition at line 75 of file DryWetMixer.h.

Constructor & Destructor Documentation

◆ DryWetMixer() [1/3]

template<typename T , int MaxChannels = 16>
dspark::DryWetMixer< T, MaxChannels >::DryWetMixer ( )
defaultnoexcept

◆ DryWetMixer() [2/3]

template<typename T , int MaxChannels = 16>
dspark::DryWetMixer< T, MaxChannels >::DryWetMixer ( DryWetMixer< T, MaxChannels > &&  other)
inlinenoexcept

Definition at line 88 of file DryWetMixer.h.

◆ DryWetMixer() [3/3]

template<typename T , int MaxChannels = 16>
dspark::DryWetMixer< T, MaxChannels >::DryWetMixer ( const DryWetMixer< T, MaxChannels > &  )
delete

Member Function Documentation

◆ getDryCapturedSamples()

template<typename T , int MaxChannels = 16>
int dspark::DryWetMixer< T, MaxChannels >::getDryCapturedSamples ( ) const
inlinenoexcept

Returns the number of samples valid from the last pushDry() call.

Definition at line 344 of file DryWetMixer.h.

◆ getDryChannel()

template<typename T , int MaxChannels = 16>
const T * dspark::DryWetMixer< T, MaxChannels >::getDryChannel ( int  ch) const
inlinenoexcept

Retrieves a read-only pointer to the captured dry channel data.

Parameters
chChannel index (0-based).
Returns
Pointer to dry samples, or nullptr if out of bounds.

Definition at line 334 of file DryWetMixer.h.

◆ getDryNumChannels()

template<typename T , int MaxChannels = 16>
int dspark::DryWetMixer< T, MaxChannels >::getDryNumChannels ( ) const
inlinenoexcept

Returns the internal capacity of channels in the dry buffer.

Definition at line 341 of file DryWetMixer.h.

◆ getLatencyCompensation()

template<typename T , int MaxChannels = 16>
int dspark::DryWetMixer< T, MaxChannels >::getLatencyCompensation ( ) const
inlinenoexcept

Returns the configured dry-path latency compensation in samples.

Definition at line 180 of file DryWetMixer.h.

◆ mixWet()

template<typename T , int MaxChannels = 16>
void dspark::DryWetMixer< T, MaxChannels >::mixWet ( AudioBufferView< T >  wetBuffer,
targetMix 
)
inlinenoexcept

Blends the stored dry signal with the current (wet) buffer in-place.

Automatically applies sample-accurate linear interpolation to the mix proportion to prevent zipper noise when the parameter changes.

Only the region covered by the last pushDry() snapshot is blended: without a captured snapshot (e.g. right after reset()) this is a no-op and the buffer stays fully wet. Channels beyond the prepared channel count also pass through untouched.

Parameters
wetBufferThe processed buffer (modified in-place).
targetMixTarget mix amount: 0.0 = fully dry, 1.0 = fully wet.

Definition at line 247 of file DryWetMixer.h.

◆ operator=() [1/2]

template<typename T , int MaxChannels = 16>
DryWetMixer & dspark::DryWetMixer< T, MaxChannels >::operator= ( const DryWetMixer< T, MaxChannels > &  )
delete

◆ operator=() [2/2]

template<typename T , int MaxChannels = 16>
DryWetMixer & dspark::DryWetMixer< T, MaxChannels >::operator= ( DryWetMixer< T, MaxChannels > &&  other)
inlinenoexcept

Definition at line 98 of file DryWetMixer.h.

◆ prepare()

template<typename T , int MaxChannels = 16>
void dspark::DryWetMixer< T, MaxChannels >::prepare ( const AudioSpec spec)
inline

Allocates the internal dry buffer for the given audio spec.

Parameters
specAudio environment specification.

Definition at line 119 of file DryWetMixer.h.

◆ pushDry()

template<typename T , int MaxChannels = 16>
void dspark::DryWetMixer< T, MaxChannels >::pushDry ( const AudioBufferView< const T > &  input)
inlinenoexcept

Captures a snapshot of the dry (unprocessed) signal.

Channels beyond the prepared channel count are ignored; a shorter input than the prepared block size shortens the valid snapshot (and therefore the region the next mixWet() call blends).

Parameters
inputThe unprocessed audio buffer. Accepts const or mutable views implicitly (AudioBufferView converts T to const T).

Definition at line 192 of file DryWetMixer.h.

◆ reset()

template<typename T , int MaxChannels = 16>
void dspark::DryWetMixer< T, MaxChannels >::reset ( )
inlinenoexcept

Resets the internal buffer and smoothing states to zero.

Definition at line 136 of file DryWetMixer.h.

◆ setLatencyCompensation()

template<typename T , int MaxChannels = 16>
void dspark::DryWetMixer< T, MaxChannels >::setLatencyCompensation ( int  samples)
inline

Delays the captured dry signal to compensate for an effect's internal latency (e.g. an oversampler's FIR group delay).

When the wet path introduces samples of delay, the dry copy must be delayed by the same amount; otherwise blending dry+wet (mix < 1, Delta or adaptive modes) produces comb filtering. Pass 0 to disable (default).

Note
NOT Real-Time Safe. Allocates the internal delay history. Call from the setup thread (typically right after prepare()).
Parameters
samplesLatency in samples at this mixer's sample rate (>= 0).

Definition at line 170 of file DryWetMixer.h.

◆ setMixRule()

template<typename T , int MaxChannels = 16>
void dspark::DryWetMixer< T, MaxChannels >::setMixRule ( MixRule  rule)
inlinenoexcept

Sets the mathematical curve to use during the mix phase.

Atomic: callable from any thread. mixWet() reads the rule once per block, so a change lands at the next block boundary.

Parameters
ruleThe chosen MixRule (Linear or EqualPower).

Definition at line 153 of file DryWetMixer.h.


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