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

Artifact-free, SIMD-friendly crossfader for two audio signals. More...

#include <Crossfade.h>

Public Types

enum class  Curve { Linear , EqualPower , SCurve }
 Defines the amplitude response of the crossfade transition. More...
 

Public Member Functions

 Crossfade ()=default
 
 ~Crossfade ()=default
 
void setCurve (Curve curve) noexcept
 Sets the crossfade curve type. Thread-safe. Can be called from the GUI thread.
 
void setPosition (T position) noexcept
 Sets the target crossfade blend position.
 
getPosition () const noexcept
 Retrieves the last requested position.
 
process (T a, T b) noexcept
 Crossfades between two individual samples.
 
void process (const T *inputA, const T *inputB, T *output, int numSamples) noexcept
 Crossfades two audio buffers into an output buffer with automatic parameter smoothing.
 
void processAutomated (const T *inputA, const T *inputB, const T *positions, T *output, int numSamples) noexcept
 Processes crossfading using a per-sample automation buffer.
 
getGainA () const noexcept
 Gets the current internal gain multiplier for signal A.
 
getGainB () const noexcept
 Gets the current internal gain multiplier for signal B.
 

Detailed Description

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

Artifact-free, SIMD-friendly crossfader for two audio signals.

Marked as final to explicitly prohibit inheritance and avoid vtable overhead, adhering to the framework's zero virtual dispatch policy in DSP nodes.

Template Parameters
TSample type (float or double). Requires std::is_floating_point_v<T>.

Definition at line 45 of file Crossfade.h.

Member Enumeration Documentation

◆ Curve

template<FloatType T>
enum class dspark::Crossfade::Curve
strong

Defines the amplitude response of the crossfade transition.

Enumerator
Linear 

Linear interpolation. Constant amplitude, drops power at center.

EqualPower 

Equal power interpolation (hardware SQRT). Constant power, no volume drop.

SCurve 

Smoothstep interpolation. Slower progression at extremes.

Definition at line 49 of file Crossfade.h.

Constructor & Destructor Documentation

◆ Crossfade()

template<FloatType T>
dspark::Crossfade< T >::Crossfade ( )
default

◆ ~Crossfade()

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

Member Function Documentation

◆ getGainA()

template<FloatType T>
T dspark::Crossfade< T >::getGainA ( ) const
inlinenoexcept

Gets the current internal gain multiplier for signal A.

Definition at line 202 of file Crossfade.h.

◆ getGainB()

template<FloatType T>
T dspark::Crossfade< T >::getGainB ( ) const
inlinenoexcept

Gets the current internal gain multiplier for signal B.

Definition at line 205 of file Crossfade.h.

◆ getPosition()

template<FloatType T>
T dspark::Crossfade< T >::getPosition ( ) const
inlinenoexcept

Retrieves the last requested position.

Returns
Current requested blend position [0, 1].

Definition at line 91 of file Crossfade.h.

◆ process() [1/2]

template<FloatType T>
void dspark::Crossfade< T >::process ( const T *  inputA,
const T *  inputB,
T *  output,
int  numSamples 
)
inlinenoexcept

Crossfades two audio buffers into an output buffer with automatic parameter smoothing.

If the parameter has changed since the last block, this method automatically applies a linear ramp to the gains across the block to prevent zipper noise. Otherwise, it executes a highly optimized, autovectorization-friendly static gain loop.

Parameters
inputAPointer to the first input buffer array. Must not be null.
inputBPointer to the second input buffer array. Must not be null.
outputPointer to the output buffer array. Must not be null.
numSamplesNumber of samples to process. Must be > 0.

Definition at line 125 of file Crossfade.h.

◆ process() [2/2]

template<FloatType T>
T dspark::Crossfade< T >::process ( a,
b 
)
inlinenoexcept

Crossfades between two individual samples.

Warning
This method updates internal gain states immediately. It does NOT provide parameter smoothing. Use the block-based process for artifact-free parameter changes. Must only be called from the audio thread.
Parameters
aInput sample A (Dry/Left).
bInput sample B (Wet/Right).
Returns
Blended output sample.

Definition at line 107 of file Crossfade.h.

◆ processAutomated()

template<FloatType T>
void dspark::Crossfade< T >::processAutomated ( const T *  inputA,
const T *  inputB,
const T *  positions,
T *  output,
int  numSamples 
)
inlinenoexcept

Processes crossfading using a per-sample automation buffer.

Extremely CPU intensive if used with heavy curves. EqualPower uses hardware SQRT to maintain real-time viability under per-sample automation.

Parameters
inputAPointer to the first input buffer.
inputBPointer to the second input buffer.
positionsArray of target positions [0, 1] per sample.
outputPointer to the output buffer.
numSamplesNumber of samples to process.

Definition at line 174 of file Crossfade.h.

◆ setCurve()

template<FloatType T>
void dspark::Crossfade< T >::setCurve ( Curve  curve)
inlinenoexcept

Sets the crossfade curve type. Thread-safe. Can be called from the GUI thread.

Parameters
curveThe desired crossfade curve. Out-of-range values (a wild cast) are clamped into the enum range.

Definition at line 65 of file Crossfade.h.

◆ setPosition()

template<FloatType T>
void dspark::Crossfade< T >::setPosition ( position)
inlinenoexcept

Sets the target crossfade blend position.

Thread-safe. Updates are smoothed automatically over the next processed audio block to eliminate zipper noise and clicks.

Parameters
positionTarget blend: 0.0 = 100% A, 1.0 = 100% B. Automatically clamped [0, 1]; non-finite values are ignored.

Definition at line 81 of file Crossfade.h.


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