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

FIR filter using direct-form convolution with a mirrored delay line. More...

#include <FIRFilter.h>

Public Member Functions

 FIRFilter ()=default
 
 ~FIRFilter ()=default
 
void prepare (int maxTaps, int numChannels)
 Pre-allocates memory and initializes the delay lines.
 
void setCoefficients (std::span< const T > coeffs) noexcept
 Sets the filter coefficients asynchronously.
 
void reset () noexcept
 Resets all delay lines to zero, clearing the filter's memory.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes a full audio buffer in-place.
 
processSample (T input, int channel) noexcept
 Processes a single sample through the FIR filter.
 
int getLatency () const noexcept
 Returns the filter's group delay (latency) in samples.
 

Detailed Description

template<typename T>
class dspark::FIRFilter< T >

FIR filter using direct-form convolution with a mirrored delay line.

Implements a lock-free coefficient publish (seqlock) for safe asynchronous updates from the control thread without reallocating memory on the audio thread; the convolution itself runs through simd::dotProduct.

Note
Buffers use the default heap alignment; the SIMD kernels use unaligned loads, which cost the same as aligned on modern CPUs.
Template Parameters
TSample type (float or double).

Definition at line 299 of file FIRFilter.h.

Constructor & Destructor Documentation

◆ FIRFilter()

template<typename T >
dspark::FIRFilter< T >::FIRFilter ( )
default

◆ ~FIRFilter()

template<typename T >
dspark::FIRFilter< T >::~FIRFilter ( )
default

Member Function Documentation

◆ getLatency()

template<typename T >
int dspark::FIRFilter< T >::getLatency ( ) const
inlinenoexcept

Returns the filter's group delay (latency) in samples.

Returns
Latency based on the most recently PUBLISHED tap count (the audio thread may adopt it one block later).

Definition at line 471 of file FIRFilter.h.

◆ prepare()

template<typename T >
void dspark::FIRFilter< T >::prepare ( int  maxTaps,
int  numChannels 
)
inline

Pre-allocates memory and initializes the delay lines.

Note
MUST be called offline (e.g., in prepareToPlay) before any processing.
Parameters
maxTapsMaximum number of filter coefficients supported.
numChannelsNumber of concurrent audio channels to process.

Definition at line 312 of file FIRFilter.h.

◆ processBlock()

template<typename T >
void dspark::FIRFilter< T >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes a full audio buffer in-place.

Loads atomic state once per block to avoid intra-block tearing and pipeline stalls.

Parameters
bufferAudio buffer view to process.

Definition at line 383 of file FIRFilter.h.

◆ processSample()

template<typename T >
T dspark::FIRFilter< T >::processSample ( input,
int  channel 
)
inlinenoexcept

Processes a single sample through the FIR filter.

Warning
Use processBlock instead when possible to avoid atomic load overhead on a per-sample basis.
Parameters
inputInput sample.
channelChannel index.
Returns
Filtered output sample.

Definition at line 433 of file FIRFilter.h.

◆ reset()

template<typename T >
void dspark::FIRFilter< T >::reset ( )
inlinenoexcept

Resets all delay lines to zero, clearing the filter's memory.

Definition at line 369 of file FIRFilter.h.

◆ setCoefficients()

template<typename T >
void dspark::FIRFilter< T >::setCoefficients ( std::span< const T >  coeffs)
inlinenoexcept

Sets the filter coefficients asynchronously.

Coefficients are stored reversed for direct SIMD dot-product alignment.

Parameters
coeffsSpan of coefficients. Size must be <= maxTaps passed to prepare().
Note
Thread-safe single-producer publish via a seqlock. The audio thread copies the staged set into its private buffer atomically, so neither a (ptr, count) mismatch nor a mid-block overwrite can occur.

Definition at line 348 of file FIRFilter.h.


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