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

Linkwitz-Riley crossover with 2-12 bands, LR12/LR24/LR48. More...

#include <CrossoverFilter.h>

Public Types

enum class  FilterMode { MinimumPhase , LinearPhase }
 Filter processing mode. More...
 

Public Member Functions

 CrossoverFilter ()
 
void prepare (const AudioSpec &spec)
 Prepares the crossover for processing.
 
int processBlock (AudioBufferView< T > input, AudioBufferView< T > *bandOutputs, int numOutputBands) noexcept
 Splits input into separate band outputs.
 
void setNumBands (int n) noexcept
 Sets the number of output bands (2..MaxBands).
 
void setCrossoverFrequency (int index, T freqHz) noexcept
 Sets a crossover frequency. Automatically maintains sorting.
 
void setOrder (int order) noexcept
 Sets the crossover slope: 12, 24 or 48 (dB/oct). Other values are ignored.
 
void setFilterMode (FilterMode mode) noexcept
 Sets the processing mode. A live switch resets filter state (transient).
 
int getNumBands () const noexcept
 
int getOrder () const noexcept
 
FilterMode getFilterMode () const noexcept
 
getCrossoverFrequency (int index) const noexcept
 Returns the target frequency of split point index.
 
int getLatency () const noexcept
 Returns latency in samples (0 for IIR, FIR group delay for linear-phase).
 
void reset () noexcept
 
std::vector< uint8_t > getState () const
 Serializes the split topology (setup/UI threads; allocates).
 
bool setState (const uint8_t *data, size_t size)
 Restores the split topology from a blob.
 

Detailed Description

template<FloatType T, int MaxBands = 12>
class dspark::CrossoverFilter< T, MaxBands >

Linkwitz-Riley crossover with 2-12 bands, LR12/LR24/LR48.

Template Parameters
TSample type (float or double).
MaxBandsMaximum number of output bands (compile-time, default 12).

Definition at line 76 of file CrossoverFilter.h.

Member Enumeration Documentation

◆ FilterMode

template<FloatType T, int MaxBands = 12>
enum class dspark::CrossoverFilter::FilterMode
strong

Filter processing mode.

Enumerator
MinimumPhase 

IIR biquads with allpass phase correction (zero latency).

LinearPhase 

FFT-based FIR crossover (introduces latency, zero phase distortion, introduces pre-ringing).

Definition at line 80 of file CrossoverFilter.h.

Constructor & Destructor Documentation

◆ CrossoverFilter()

template<FloatType T, int MaxBands = 12>
dspark::CrossoverFilter< T, MaxBands >::CrossoverFilter ( )
inline

Definition at line 86 of file CrossoverFilter.h.

Member Function Documentation

◆ getCrossoverFrequency()

template<FloatType T, int MaxBands = 12>
T dspark::CrossoverFilter< T, MaxBands >::getCrossoverFrequency ( int  index) const
inlinenoexcept

Returns the target frequency of split point index.

Definition at line 355 of file CrossoverFilter.h.

◆ getFilterMode()

template<FloatType T, int MaxBands = 12>
FilterMode dspark::CrossoverFilter< T, MaxBands >::getFilterMode ( ) const
inlinenoexcept

Definition at line 352 of file CrossoverFilter.h.

◆ getLatency()

template<FloatType T, int MaxBands = 12>
int dspark::CrossoverFilter< T, MaxBands >::getLatency ( ) const
inlinenoexcept

Returns latency in samples (0 for IIR, FIR group delay for linear-phase).

Reports the linear-phase latency only when the engine actually exists (see prepare()); if linear-phase mode fell back to IIR, this returns 0.

Definition at line 367 of file CrossoverFilter.h.

◆ getNumBands()

template<FloatType T, int MaxBands = 12>
int dspark::CrossoverFilter< T, MaxBands >::getNumBands ( ) const
inlinenoexcept

Definition at line 350 of file CrossoverFilter.h.

◆ getOrder()

template<FloatType T, int MaxBands = 12>
int dspark::CrossoverFilter< T, MaxBands >::getOrder ( ) const
inlinenoexcept

Definition at line 351 of file CrossoverFilter.h.

◆ getState()

template<FloatType T, int MaxBands = 12>
std::vector< uint8_t > dspark::CrossoverFilter< T, MaxBands >::getState ( ) const
inline

Serializes the split topology (setup/UI threads; allocates).

Definition at line 388 of file CrossoverFilter.h.

◆ prepare()

template<FloatType T, int MaxBands = 12>
void dspark::CrossoverFilter< T, MaxBands >::prepare ( const AudioSpec spec)
inline

Prepares the crossover for processing.

Configured split frequencies, band count, order and mode are preserved across prepare() calls (configure-then-prepare is fully supported). The linear-phase engine is always allocated (so a later mode switch works) unless maxBlockSize exceeds 2^18, in which case linear-phase mode falls back to the IIR path and getLatency() reports 0.

Parameters
specAudio environment (sample rate, block size, channels). Invalid specs are ignored (previous state is kept).

Definition at line 105 of file CrossoverFilter.h.

◆ processBlock()

template<FloatType T, int MaxBands = 12>
int dspark::CrossoverFilter< T, MaxBands >::processBlock ( AudioBufferView< T >  input,
AudioBufferView< T > *  bandOutputs,
int  numOutputBands 
)
inlinenoexcept

Splits input into separate band outputs.

The processed span is clamped to the prepared maxBlockSize and to the shortest output view. Input channels beyond the prepared/16-channel limit are passed through on band 0 (remaining bands silent) so the band sum still reconstructs the input.

Parameters
inputInput audio buffer.
bandOutputsArray of AudioBufferView, one per band.
numOutputBandsNumber of output bands (must match getNumBands(); fewer bands re-purpose the first splits only in IIR mode and is not a supported configuration).
Returns
The number of bands actually written THIS block (0 when nothing was written: unprepared, degenerate span, or null outputs). Callers that sum the bands back together should trust this value rather than a separately read getNumBands(): the band count is an atomic that a concurrent setNumBands() may move between the two reads, and views beyond the returned count are untouched.

Definition at line 205 of file CrossoverFilter.h.

◆ reset()

template<FloatType T, int MaxBands = 12>
void dspark::CrossoverFilter< T, MaxBands >::reset ( )
inlinenoexcept

Definition at line 373 of file CrossoverFilter.h.

◆ setCrossoverFrequency()

template<FloatType T, int MaxBands = 12>
void dspark::CrossoverFilter< T, MaxBands >::setCrossoverFrequency ( int  index,
freqHz 
)
inlinenoexcept

Sets a crossover frequency. Automatically maintains sorting.

Non-finite frequencies are ignored; values are floored to 1 Hz here and clamped to [20, 0.499 * sampleRate] at design time.

Definition at line 286 of file CrossoverFilter.h.

◆ setFilterMode()

template<FloatType T, int MaxBands = 12>
void dspark::CrossoverFilter< T, MaxBands >::setFilterMode ( FilterMode  mode)
inlinenoexcept

Sets the processing mode. A live switch resets filter state (transient).

Definition at line 340 of file CrossoverFilter.h.

◆ setNumBands()

template<FloatType T, int MaxBands = 12>
void dspark::CrossoverFilter< T, MaxBands >::setNumBands ( int  n)
inlinenoexcept

Sets the number of output bands (2..MaxBands).

Note
Changing the band count re-initialises ALL split frequencies to log-spaced defaults (100 Hz .. 10 kHz); reapply custom frequencies afterwards. A live topology change is applied instantly (click).

Definition at line 272 of file CrossoverFilter.h.

◆ setOrder()

template<FloatType T, int MaxBands = 12>
void dspark::CrossoverFilter< T, MaxBands >::setOrder ( int  order)
inlinenoexcept

Sets the crossover slope: 12, 24 or 48 (dB/oct). Other values are ignored.

Definition at line 329 of file CrossoverFilter.h.

◆ setState()

template<FloatType T, int MaxBands = 12>
bool dspark::CrossoverFilter< T, MaxBands >::setState ( const uint8_t *  data,
size_t  size 
)
inline

Restores the split topology from a blob.

Definition at line 405 of file CrossoverFilter.h.


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