Signalsmith Audio's DSP Library  1.7.0
Useful C++ classes/templates for audio effects
Loading...
Searching...
No Matches
signalsmith::envelopes::BoxStackFilter< Sample > Class Template Reference

#include <envelopes.h>

Detailed Description

template<typename Sample = double>
class signalsmith::envelopes::BoxStackFilter< Sample >

FIR filter made from a stack of BoxFilters.

This filter has a non-negative impulse (monotonic step response), making it useful for smoothing positive-only values. It provides an optimal set of box-lengths, chosen to minimise peaks in the stop-band:

Impulse responses for various stack sizes at length N=1000

Since the underlying box-averages must have integer width, the peaks are slightly higher for shorter lengths with higher numbers of layers:

Frequency responses for various stack sizes at length N=30

Static Methods

static std::vector< double > optimalRatios (int layerCount)
 Returns an optimal set of length ratios (heuristic for larger depths)
 
static constexpr double layersToBandwidth (int layers)
 Approximate (optimal) bandwidth for a given number of layers.
 
static constexpr double layersToPeakDb (int layers)
 Approximate (optimal) peak in the stop-band.
 

Methods

 BoxStackFilter (int maxSize, int layers=4)
 
void resize (int maxSize, int layerCount)
 Sets size using an optimal (heuristic at larger sizes) set of length ratios.
 
template<class List>
auto resize (int maxSize, List ratios) -> decltype(void(std::begin(ratios)), void(std::end(ratios)))
 Sets the maximum (and current) impulse response length and explicit length ratios.
 
void resize (int maxSize, std::initializer_list< double > ratios)
 
void set (int size)
 Sets the impulse response length (does not reset if sizemaxSize)
 
void reset (Sample fill=Sample())
 Resets the filter.
 
Sample operator() (Sample v)
 

Method Details

◆ layersToBandwidth()

template<typename Sample = double>
static constexpr double signalsmith::envelopes::BoxStackFilter< Sample >::layersToBandwidth ( int layers)
inlinestaticconstexpr

Approximate (optimal) bandwidth for a given number of layers.

Approximate main lobe width (bandwidth)

◆ layersToPeakDb()

template<typename Sample = double>
static constexpr double signalsmith::envelopes::BoxStackFilter< Sample >::layersToPeakDb ( int layers)
inlinestaticconstexpr

Approximate (optimal) peak in the stop-band.

Heuristic stop-band peak

◆ optimalRatios()

template<typename Sample = double>
static std::vector< double > signalsmith::envelopes::BoxStackFilter< Sample >::optimalRatios ( int layerCount)
inlinestatic

Returns an optimal set of length ratios (heuristic for larger depths)

◆ reset()

template<typename Sample = double>
void signalsmith::envelopes::BoxStackFilter< Sample >::reset ( Sample fill = Sample())
inline

Resets the filter.

◆ resize() [1/2]

template<typename Sample = double>
void signalsmith::envelopes::BoxStackFilter< Sample >::resize ( int maxSize,
int layerCount )
inline

Sets size using an optimal (heuristic at larger sizes) set of length ratios.

◆ resize() [2/2]

template<typename Sample = double>
template<class List>
auto signalsmith::envelopes::BoxStackFilter< Sample >::resize ( int maxSize,
List ratios ) -> decltype(void(std::begin(ratios)), void(std::end(ratios)))
inline

Sets the maximum (and current) impulse response length and explicit length ratios.

◆ set()

template<typename Sample = double>
void signalsmith::envelopes::BoxStackFilter< Sample >::set ( int size)
inline

Sets the impulse response length (does not reset if sizemaxSize)