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

#include <Panner.h>

Collaboration diagram for dspark::Panner< T >:

Public Types

enum class  Algorithm {
  EqualPower , Binaural , MidPan , SidePan ,
  Haas , Spectral
}
 Available panning algorithms. More...
 

Public Member Functions

 ~Panner ()=default
 
void prepare (const AudioSpec &spec)
 Initializes internal delays, filters, and smoothers.
 
void setAlgorithm (Algorithm algo) noexcept
 Sets the active panning algorithm safely from any thread.
 
void setPan (T position) noexcept
 Sets the target pan position (automatable, smoothed).
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes an audio block in-place. Real-time safe.
 
void reset () noexcept
 Clears delay lines and filter states to prevent ghost echoes.
 
void setBinauralMaxITD (float ms) noexcept
 
void setHaasMaxDelay (float ms) noexcept
 
void setSpectralFrequency (float hz) noexcept
 
void setSpectralMaxGain (float dB) noexcept
 
void setSmoothingTime (float ms) noexcept
 Sets the pan smoothing time. Thread-safe; applied at the top of the next processBlock() (previously it only took effect on the next prepare(), silently).
 
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).
 

Protected Member Functions

void applyEqualPower (AudioBufferView< T > buffer, float) noexcept
 
void applyCombinedBinaural (AudioBufferView< T > buffer, float panTarget) noexcept
 
void applyMidPan (AudioBufferView< T > buffer, float) noexcept
 
void applySidePan (AudioBufferView< T > buffer, float) noexcept
 
void applyHaas (AudioBufferView< T > buffer, float panTarget) noexcept
 
void applySpectral (AudioBufferView< T > buffer, float panTarget) noexcept
 
void updateSpectralFilters (T targetPan) noexcept
 

Protected Attributes

double sampleRate_ = 48000.0
 
std::atomic< Algorithmalgorithm_ { Algorithm::EqualPower }
 
std::atomic< T > pan_ { T(0) }
 
Delay< T > delayL_
 
Delay< T > delayR_
 
Smoothers::LinearSmoother panSmoother_
 
Biquad< T, 1 > spectralL_
 
Biquad< T, 1 > spectralR_
 
std::atomic< float > smoothingTime_ { 50.0f }
 
std::atomic< bool > smoothingDirty_ { false }
 Pan smoother re-config pending.
 
std::atomic< float > binauralMaxITD_ { 0.66f }
 
std::atomic< float > haasMaxDelay_ { 30.0f }
 
std::atomic< float > spectralFreq_ { 4000.0f }
 
std::atomic< float > spectralMaxGain_ { 6.0f }
 

Detailed Description

template<typename T = float>
class dspark::Panner< T >

Definition at line 49 of file Panner.h.

Member Enumeration Documentation

◆ Algorithm

template<typename T = float>
enum class dspark::Panner::Algorithm
strong

Available panning algorithms.

Enumerator
EqualPower 

Standard -3 dB constant-power pan.

Binaural 

Cross-feeding + ITD delay.

MidPan 

Pans only the centre (mid) image.

SidePan 

Pans only the stereo (side) image.

Haas 

Precedence effect via inter-channel delay.

Spectral 

Frequency-dependent panning via high-shelf.

Definition at line 56 of file Panner.h.

Constructor & Destructor Documentation

◆ ~Panner()

template<typename T = float>
dspark::Panner< T >::~Panner ( )
default

Member Function Documentation

◆ applyCombinedBinaural()

template<typename T = float>
void dspark::Panner< T >::applyCombinedBinaural ( AudioBufferView< T >  buffer,
float  panTarget 
)
inlineprotectednoexcept

Definition at line 277 of file Panner.h.

◆ applyEqualPower()

template<typename T = float>
void dspark::Panner< T >::applyEqualPower ( AudioBufferView< T >  buffer,
float   
)
inlineprotectednoexcept

Definition at line 245 of file Panner.h.

◆ applyHaas()

template<typename T = float>
void dspark::Panner< T >::applyHaas ( AudioBufferView< T >  buffer,
float  panTarget 
)
inlineprotectednoexcept

Definition at line 386 of file Panner.h.

◆ applyMidPan()

template<typename T = float>
void dspark::Panner< T >::applyMidPan ( AudioBufferView< T >  buffer,
float   
)
inlineprotectednoexcept

Definition at line 334 of file Panner.h.

◆ applySidePan()

template<typename T = float>
void dspark::Panner< T >::applySidePan ( AudioBufferView< T >  buffer,
float   
)
inlineprotectednoexcept

Definition at line 361 of file Panner.h.

◆ applySpectral()

template<typename T = float>
void dspark::Panner< T >::applySpectral ( AudioBufferView< T >  buffer,
float  panTarget 
)
inlineprotectednoexcept

Definition at line 415 of file Panner.h.

◆ getState()

template<typename T = float>
std::vector< uint8_t > dspark::Panner< T >::getState ( ) const
inline

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

Definition at line 216 of file Panner.h.

◆ prepare()

template<typename T = float>
void dspark::Panner< T >::prepare ( const AudioSpec spec)
inline

Initializes internal delays, filters, and smoothers.

Parameters
specThe audio specification (sample rate, block size). An invalid spec (non-positive or NaN fields) is ignored.

Definition at line 71 of file Panner.h.

◆ processBlock()

template<typename T = float>
void dspark::Panner< T >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes an audio block in-place. Real-time safe.

Parameters
bufferStereo audio buffer. Modifies the data directly. Buffers with fewer than 2 channels are left untouched.

Definition at line 127 of file Panner.h.

◆ reset()

template<typename T = float>
void dspark::Panner< T >::reset ( )
inlinenoexcept

Clears delay lines and filter states to prevent ghost echoes.

Definition at line 167 of file Panner.h.

◆ setAlgorithm()

template<typename T = float>
void dspark::Panner< T >::setAlgorithm ( Algorithm  algo)
inlinenoexcept

Sets the active panning algorithm safely from any thread.

Note
Switching is instant (no crossfade). The delay lines and spectral filters keep their state across switches; call reset() if a stale tail from the previous algorithm would be audible.
Parameters
algoThe algorithm enum to use. Out-of-range values are clamped.

Definition at line 101 of file Panner.h.

◆ setBinauralMaxITD()

template<typename T = float>
void dspark::Panner< T >::setBinauralMaxITD ( float  ms)
inlinenoexcept

Definition at line 181 of file Panner.h.

◆ setHaasMaxDelay()

template<typename T = float>
void dspark::Panner< T >::setHaasMaxDelay ( float  ms)
inlinenoexcept

Definition at line 186 of file Panner.h.

◆ setPan()

template<typename T = float>
void dspark::Panner< T >::setPan ( position)
inlinenoexcept

Sets the target pan position (automatable, smoothed).

Parameters
positionTarget pan from -1.0 (left) to +1.0 (right). Non-finite values are ignored.

Definition at line 113 of file Panner.h.

◆ setSmoothingTime()

template<typename T = float>
void dspark::Panner< T >::setSmoothingTime ( float  ms)
inlinenoexcept

Sets the pan smoothing time. Thread-safe; applied at the top of the next processBlock() (previously it only took effect on the next prepare(), silently).

Definition at line 205 of file Panner.h.

◆ setSpectralFrequency()

template<typename T = float>
void dspark::Panner< T >::setSpectralFrequency ( float  hz)
inlinenoexcept

Definition at line 191 of file Panner.h.

◆ setSpectralMaxGain()

template<typename T = float>
void dspark::Panner< T >::setSpectralMaxGain ( float  dB)
inlinenoexcept

Definition at line 196 of file Panner.h.

◆ setState()

template<typename T = float>
bool dspark::Panner< T >::setState ( const uint8_t *  data,
size_t  size 
)
inline

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

Definition at line 230 of file Panner.h.

◆ updateSpectralFilters()

template<typename T = float>
void dspark::Panner< T >::updateSpectralFilters ( targetPan)
inlineprotectednoexcept

Definition at line 435 of file Panner.h.

Member Data Documentation

◆ algorithm_

template<typename T = float>
std::atomic<Algorithm> dspark::Panner< T >::algorithm_ { Algorithm::EqualPower }
protected

Definition at line 450 of file Panner.h.

◆ binauralMaxITD_

template<typename T = float>
std::atomic<float> dspark::Panner< T >::binauralMaxITD_ { 0.66f }
protected

Definition at line 459 of file Panner.h.

◆ delayL_

template<typename T = float>
Delay<T> dspark::Panner< T >::delayL_
protected

Definition at line 453 of file Panner.h.

◆ delayR_

template<typename T = float>
Delay<T> dspark::Panner< T >::delayR_
protected

Definition at line 453 of file Panner.h.

◆ haasMaxDelay_

template<typename T = float>
std::atomic<float> dspark::Panner< T >::haasMaxDelay_ { 30.0f }
protected

Definition at line 460 of file Panner.h.

◆ pan_

template<typename T = float>
std::atomic<T> dspark::Panner< T >::pan_ { T(0) }
protected

Definition at line 451 of file Panner.h.

◆ panSmoother_

template<typename T = float>
Smoothers::LinearSmoother dspark::Panner< T >::panSmoother_
protected

Definition at line 454 of file Panner.h.

◆ sampleRate_

template<typename T = float>
double dspark::Panner< T >::sampleRate_ = 48000.0
protected

Definition at line 449 of file Panner.h.

◆ smoothingDirty_

template<typename T = float>
std::atomic<bool> dspark::Panner< T >::smoothingDirty_ { false }
protected

Pan smoother re-config pending.

Definition at line 458 of file Panner.h.

◆ smoothingTime_

template<typename T = float>
std::atomic<float> dspark::Panner< T >::smoothingTime_ { 50.0f }
protected

Definition at line 457 of file Panner.h.

◆ spectralFreq_

template<typename T = float>
std::atomic<float> dspark::Panner< T >::spectralFreq_ { 4000.0f }
protected

Definition at line 461 of file Panner.h.

◆ spectralL_

template<typename T = float>
Biquad<T, 1> dspark::Panner< T >::spectralL_
protected

Definition at line 455 of file Panner.h.

◆ spectralMaxGain_

template<typename T = float>
std::atomic<float> dspark::Panner< T >::spectralMaxGain_ { 6.0f }
protected

Definition at line 462 of file Panner.h.

◆ spectralR_

template<typename T = float>
Biquad<T, 1> dspark::Panner< T >::spectralR_
protected

Definition at line 455 of file Panner.h.


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