DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
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.
 
int getLatency () const noexcept
 Latency in samples: the 4-sample common base delay of the Binaural and Haas paths (centred image), 0 for the others.
 
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: a change settles (to 96%) in this many ms along a critically damped curve. Thread-safe; applied at the top of the next processBlock().
 
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) noexcept
 
void updateSpectralFilters (T targetPan) noexcept
 

Static Protected Member Functions

static float panTimeConstantMs (float smoothingMs) noexcept
 

Protected Attributes

double sampleRate_ = 48000.0
 
std::atomic< Algorithm > algorithm_ { Algorithm::EqualPower }
 
std::atomic< T > pan_ { T(0) }
 
Delay< T > delayL_
 
Delay< T > delayR_
 
Smoothers::CriticallyDampedSmoother 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 }
 
float spectralPan_ = std::numeric_limits<float>::quiet_NaN()
 
float spectralFreqUsed_ = 0.0f
 
float spectralGainUsed_ = 0.0f
 

Static Protected Attributes

static constexpr int kBaseDelaySamples = 4
 Binaural/Haas common delay.
 

Detailed Description

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

Definition at line 55 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 62 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 301 of file Panner.h.

◆ applyEqualPower()

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

Definition at line 269 of file Panner.h.

◆ applyHaas()

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

Definition at line 410 of file Panner.h.

◆ applyMidPan()

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

Definition at line 358 of file Panner.h.

◆ applySidePan()

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

Definition at line 385 of file Panner.h.

◆ applySpectral()

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

Definition at line 439 of file Panner.h.

◆ getLatency()

template<typename T = float>
int dspark::Panner< T >::getLatency ( ) const
inlinenoexcept

Latency in samples: the 4-sample common base delay of the Binaural and Haas paths (centred image), 0 for the others.

Definition at line 193 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 239 of file Panner.h.

◆ panTimeConstantMs()

template<typename T = float>
static float dspark::Panner< T >::panTimeConstantMs ( float  smoothingMs)
inlinestaticprotectednoexcept

Time constant of the critically damped smoother for a smoothing time: 1 - (1 + t/tau) e^(-t/tau) reaches 96% at t = 5 tau.

Definition at line 500 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 77 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 140 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 180 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 114 of file Panner.h.

◆ setBinauralMaxITD()

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

Definition at line 204 of file Panner.h.

◆ setHaasMaxDelay()

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

Definition at line 209 of file Panner.h.

◆ setPan()

template<typename T = float>
void dspark::Panner< T >::setPan ( T  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 126 of file Panner.h.

◆ setSmoothingTime()

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

Sets the pan smoothing time: a change settles (to 96%) in this many ms along a critically damped curve. Thread-safe; applied at the top of the next processBlock().

Definition at line 228 of file Panner.h.

◆ setSpectralFrequency()

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

Definition at line 214 of file Panner.h.

◆ setSpectralMaxGain()

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

Definition at line 219 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 254 of file Panner.h.

◆ updateSpectralFilters()

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

Definition at line 465 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 488 of file Panner.h.

◆ binauralMaxITD_

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

Definition at line 505 of file Panner.h.

◆ delayL_

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

Definition at line 492 of file Panner.h.

◆ delayR_

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

Definition at line 492 of file Panner.h.

◆ haasMaxDelay_

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

Definition at line 506 of file Panner.h.

◆ kBaseDelaySamples

template<typename T = float>
constexpr int dspark::Panner< T >::kBaseDelaySamples = 4
staticconstexprprotected

Binaural/Haas common delay.

Definition at line 489 of file Panner.h.

◆ pan_

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

Definition at line 490 of file Panner.h.

◆ panSmoother_

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

Definition at line 497 of file Panner.h.

◆ sampleRate_

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

Definition at line 487 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 504 of file Panner.h.

◆ smoothingTime_

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

Definition at line 503 of file Panner.h.

◆ spectralFreq_

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

Definition at line 507 of file Panner.h.

◆ spectralFreqUsed_

template<typename T = float>
float dspark::Panner< T >::spectralFreqUsed_ = 0.0f
protected

Definition at line 512 of file Panner.h.

◆ spectralGainUsed_

template<typename T = float>
float dspark::Panner< T >::spectralGainUsed_ = 0.0f
protected

Definition at line 513 of file Panner.h.

◆ spectralL_

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

Definition at line 501 of file Panner.h.

◆ spectralMaxGain_

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

Definition at line 508 of file Panner.h.

◆ spectralPan_

template<typename T = float>
float dspark::Panner< T >::spectralPan_ = std::numeric_limits<float>::quiet_NaN()
protected

Definition at line 511 of file Panner.h.

◆ spectralR_

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

Definition at line 501 of file Panner.h.


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