MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin::dsp::filters::LPF< SampleType > Class Template Reference

A direct form i first order single pole lowpass filter. More...

#include <marvin_LPF.h>

Public Member Functions

void initialise (double sampleRate) noexcept
 
void setCutoff (SampleType cutoff) noexcept
 
void setCoeff (SampleType newCoeff) noexcept
 
SampleType operator() (SampleType x) noexcept
 
void reset () noexcept
 

Detailed Description

template<FloatType SampleType>
class marvin::dsp::filters::LPF< SampleType >

A direct form i first order single pole lowpass filter.

Member Function Documentation

◆ initialise()

template<FloatType SampleType>
void marvin::dsp::filters::LPF< SampleType >::initialise ( double sampleRate)
noexcept

Initialise the LPF's sample rate. If using setCutoff to set the coefficient, make sure to call this function before any calls to it!

Parameters
sampleRateThe sample rate the filter should run at.

◆ operator()()

template<FloatType SampleType>
SampleType marvin::dsp::filters::LPF< SampleType >::operator() ( SampleType x)
nodiscardnoexcept

Filters a single sample. The lowpass is in the form y[n] = ax[n] + (1-a)y[n-1] where a is the coeff.

Parameters
xThe sample to filter.
Returns
The filtered sample.

◆ reset()

template<FloatType SampleType>
void marvin::dsp::filters::LPF< SampleType >::reset ( )
noexcept

Resets the internal state of the filter (including zero-ing y[n-1])

◆ setCoeff()

template<FloatType SampleType>
void marvin::dsp::filters::LPF< SampleType >::setCoeff ( SampleType newCoeff)
noexcept

Directly sets the coefficient the filter should use internally - see setCutoff for its relationship to cutoff.
As the internal coeff variable is not atomic, ensure this function is either called on the audio thread, or that the audio thread is not running when this function is called.

Parameters
newCoeffThe coeff the LPF should use.

◆ setCutoff()

template<FloatType SampleType>
void marvin::dsp::filters::LPF< SampleType >::setCutoff ( SampleType cutoff)
noexcept

Sets the desired -3dB cutoff frequency for the filter. Make sure to call initialise before calling this function. Internally, ends up calling setCoeff with the calculated coeff, from the formula

w = f_c / f_s
y = 1 - cos(w_c)
coeff = -y + sqrt(y^2 + 2y)

which is explained in more detail here: https://dsp.stackexchange.com/questions/54086/single-pole-iir-low-pass-filter-which-is-the-correct-formula-for-the-decay-coe
As the internal coeff variable is not atomic, this function needs to be either called on the audio thread, or called when the audio thread is not running.

Parameters
cutoffThe cutoff frequency the LPF should use.

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