Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::signal::FirFilterT< SampleType > Class Template Reference

FIR filter with arbitrary coefficients. More...

#include <fir_filter.hpp>

Public Member Functions

 FirFilterT ()=default
void set_coefficients (std::vector< SampleType > coeffs)
 Set filter coefficients. The number of taps equals coefficients.size().
int order () const
 Get current coefficient count (filter order + 1).
const std::vector< SampleType > & coefficients () const noexcept
 The taps in time order (h[0] multiplies the newest input).
SampleType process (SampleType input)
 Process a single sample.
void process (SampleType *data, int num_samples)
 Process a buffer of samples in-place.
void process (const SampleType *input, SampleType *output, int num_samples)
 Process a buffer into a separate output buffer without an intermediate copy.
void reset ()
 Reset the internal delay buffer to zero.

Static Public Member Functions

static std::vector< SampleType > lowpass (int num_taps, SampleType cutoff_hz, SampleType sample_rate)
 Generate lowpass FIR coefficients using windowed-sinc method.
static std::vector< SampleType > highpass (int num_taps, SampleType cutoff_hz, SampleType sample_rate)
 Generate highpass FIR coefficients using spectral inversion.

Static Public Attributes

static constexpr std::size_t kBlockCapacity = 512
 Samples appended between history compactions.
static constexpr std::size_t kInlineTaps = 8
 Per-sample calls with at most this many taps sum inline instead of calling the dot kernel, whose call overhead would dominate.

Detailed Description

template<typename SampleType = float>
class pulp::signal::FirFilterT< SampleType >

FIR filter with arbitrary coefficients.

History is kept linear (oldest to newest, contiguous) rather than in a wrapping ring, so every output is one contiguous dot product and a block of outputs is one pulp::simd::correlate() call, which the SIMD backends vectorize across outputs. Appending past the end of the history buffer moves the last taps - 1 samples back to the front, once per kBlockCapacity samples.

Numerics: taps accumulate oldest-first in the backend's order, so output matches a textbook sequential sum to rounding, not to the bit.

RT contract: set_coefficients() allocates and must run off the audio thread. process() and reset() allocate no memory after coefficients are installed.

fir.set_coefficients({0.25f, 0.5f, 0.25f}); // 3-tap averaging
float out = fir.process(in);
SampleType process(SampleType input)
Process a single sample.
Definition fir_filter.hpp:69
void set_coefficients(std::vector< SampleType > coeffs)
Set filter coefficients. The number of taps equals coefficients.size().
Definition fir_filter.hpp:52
FirFilterT< float > FirFilter
Definition fir_filter.hpp:190

Constructor & Destructor Documentation

◆ FirFilterT()

template<typename SampleType = float>
pulp::signal::FirFilterT< SampleType >::FirFilterT ( )
default

Member Function Documentation

◆ coefficients()

template<typename SampleType = float>
const std::vector< SampleType > & pulp::signal::FirFilterT< SampleType >::coefficients ( ) const
inlinenoexcept

The taps in time order (h[0] multiplies the newest input).

◆ highpass()

template<typename SampleType = float>
std::vector< SampleType > pulp::signal::FirFilterT< SampleType >::highpass ( int num_taps,
SampleType cutoff_hz,
SampleType sample_rate )
inlinestatic

Generate highpass FIR coefficients using spectral inversion.

◆ lowpass()

template<typename SampleType = float>
std::vector< SampleType > pulp::signal::FirFilterT< SampleType >::lowpass ( int num_taps,
SampleType cutoff_hz,
SampleType sample_rate )
inlinestatic

Generate lowpass FIR coefficients using windowed-sinc method.

Parameters
num_tapsNumber of filter taps (odd recommended).
cutoff_hzCutoff frequency in Hz.
sample_rateSample rate in Hz.

◆ order()

template<typename SampleType = float>
int pulp::signal::FirFilterT< SampleType >::order ( ) const
inline

Get current coefficient count (filter order + 1).

◆ process() [1/3]

template<typename SampleType = float>
void pulp::signal::FirFilterT< SampleType >::process ( const SampleType * input,
SampleType * output,
int num_samples )
inline

Process a buffer into a separate output buffer without an intermediate copy.

Both buffers must contain num_samples elements and may alias exactly; partial overlap is not supported. Each input slice is copied into the history before its outputs are written, so exact aliasing is the in-place case. With no coefficients the filter passes input through, as the per-sample overload does.

◆ process() [2/3]

template<typename SampleType = float>
void pulp::signal::FirFilterT< SampleType >::process ( SampleType * data,
int num_samples )
inline

Process a buffer of samples in-place.

◆ process() [3/3]

template<typename SampleType = float>
SampleType pulp::signal::FirFilterT< SampleType >::process ( SampleType input)
inline

Process a single sample.

◆ reset()

template<typename SampleType = float>
void pulp::signal::FirFilterT< SampleType >::reset ( )
inline

Reset the internal delay buffer to zero.

◆ set_coefficients()

template<typename SampleType = float>
void pulp::signal::FirFilterT< SampleType >::set_coefficients ( std::vector< SampleType > coeffs)
inline

Set filter coefficients. The number of taps equals coefficients.size().

Member Data Documentation

◆ kBlockCapacity

template<typename SampleType = float>
std::size_t pulp::signal::FirFilterT< SampleType >::kBlockCapacity = 512
staticconstexpr

Samples appended between history compactions.

A block longer than this is processed in slices of at most this many outputs.

◆ kInlineTaps

template<typename SampleType = float>
std::size_t pulp::signal::FirFilterT< SampleType >::kInlineTaps = 8
staticconstexpr

Per-sample calls with at most this many taps sum inline instead of calling the dot kernel, whose call overhead would dominate.


The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/signal/include/pulp/signal/fir_filter.hpp