CUGL 2.3
Cornell University Game Library

#include <CUPoleZeroIIR.h>
Public Member Functions  
PoleZeroFIR ()  
PoleZeroFIR (unsigned channels)  
PoleZeroFIR (unsigned channels, float b0, float b1, float a1)  
PoleZeroFIR (const PoleZeroFIR ©)  
PoleZeroFIR (PoleZeroFIR &&filter)  
~PoleZeroFIR ()  
unsigned  getChannels () const 
void  setChannels (unsigned channels) 
void  setCoeff (const std::vector< float > &bvals, const std::vector< float > &avals) 
const std::vector< float >  getBCoeff () const 
const std::vector< float >  getACoeff () const 
void  setBCoeff (float b0, float b1) 
void  setACoeff (float a1) 
void  setHighpass (float frequency) 
void  setAllpass (float coefficient) 
void  setBlockZero (float pole=0.99f) 
void  step (float gain, float *input, float *output) 
void  calculate (float gain, float *input, float *output, size_t size) 
void  clear () 
size_t  flush (float *output) 
Static Public Attributes  
static bool  VECTORIZE 
This class implements a onezero digital filter.
This filter is the preferred way to create a firstorder highpass filter, and so we provide the method setHighpass
for setting the highpass frequency. In addition, there are methods for creating an allpass filter, as well as a DC blocking filter.
Frequencies are specified in "normalized" format. A normalized frequency is frequency/sample rate. For example, a 7 kHz frequency with a 44100 Hz sample rate has a normalized value 7000/44100 = 0.15873. However, filters are not intended to be model classes, and so it does not save the defining frequency.
This class supports vector optimizations for SSE and Neon 64. In timed simulations, these optimizations provide at least a 34x performance increase (and for 4 or 8 channel audio, much higher). These optimizations make use of the matrix precomputation outlined in "Implementation of Recursive Digital Filters into Vector SIMD DSP Architectures".
https://pdfs.semanticscholar.org/d150/a3f75dc033916f14029cd9101a8ea1d050bb.pdf
The algorithm in this paper performs extremely well in our tests, and even outperforms Apple's Acceleration library. However, our implementation is limited to 128bit words as 256bit (e.g. AVX) and higher show no significant increase in performance.
For performance reasons, this class does not have a (virtualized) subclass relationship with other IIR or FIR filters. However, the signature of the the calculation and coefficient methods has been standardized so that it can support templated polymorphism.
This class is not thread safe. External locking may be required when the filter is shared between multiple threads (such as between an audio thread and the main thread).
cugl::dsp::PoleZeroFIR::PoleZeroFIR  (  ) 
Creates a zeroorder passthrough filter for a single channel.
cugl::dsp::PoleZeroFIR::PoleZeroFIR  (  unsigned  channels  ) 
Creates a zeroorder passthrough filter for the given number of channels.
channels  The number of channels 
cugl::dsp::PoleZeroFIR::PoleZeroFIR  (  unsigned  channels, 
float  b0,  
float  b1,  
float  a1  
) 
Creates a FIR filter with the given coefficients and number of channels.
This filter implements the standard difference equation:
y[n] = b[0]*x[n] + b[1]*x[n1]  a[1]*y[n1]
where y is the output and x in the input.
channels  The number of channels 
b0  The upper zeroorder coefficient 
b1  The upper firstorder coefficient 
a1  The lower firstorder coefficient 
cugl::dsp::PoleZeroFIR::PoleZeroFIR  (  const PoleZeroFIR &  copy  ) 
Creates a copy of the FIR filter.
copy  The filter to copy 
cugl::dsp::PoleZeroFIR::PoleZeroFIR  (  PoleZeroFIR &&  filter  ) 
Creates a FIR filter with the resources of the original.
filter  The filter to acquire 
cugl::dsp::PoleZeroFIR::~PoleZeroFIR  (  ) 
Destroys the filter, releasing all resources.
void cugl::dsp::PoleZeroFIR::calculate  (  float  gain, 
float *  input,  
float *  output,  
size_t  size  
) 
Performs a filter of interleaved input data.
The output is written to the given output array, which should be the same size as the input array. The size is the number of frames, not samples. Hence the arrays must be size times the number of channels in size.
To provide real time processing, the output is delayed by the number of acoefficients. Delayed results are buffered to be used the next time the filter is used (though they may be extracted with the flush
method). The gain parameter is applied at the filter input, but does not affect the filter coefficients.
gain  The input gain factor 
input  The array of input samples 
output  The array to write the sample output 
size  The input size in frames 
void cugl::dsp::PoleZeroFIR::clear  (  ) 
Clears the filter buffer of any delayed outputs or cached inputs
size_t cugl::dsp::PoleZeroFIR::flush  (  float *  output  ) 
Flushes any delayed outputs to the provided array
The array size should be the number of channels. This method will also clear the buffer.
const std::vector< float > cugl::dsp::PoleZeroFIR::getACoeff  (  )  const 
Returns the lower coefficients for this IIR filter.
This filter implements the standard difference equation:
a[0]*y[n] = b[0]*x[n]+...+b[nb]*x[nnb]a[1]*y[n1]...a[na]*y[nna]
where y is the output and x in the input.
const std::vector< float > cugl::dsp::PoleZeroFIR::getBCoeff  (  )  const 
Returns the upper coefficients for this IIR filter.
This filter implements the standard difference equation:
a[0]*y[n] = b[0]*x[n]+...+b[nb]*x[nnb]a[1]*y[n1]...a[na]*y[nna]
where y is the output and x in the input.

inline 
Returns the number of channels for this filter
The data buffers depend on the number of channels. Changing this value will reset the data buffers to 0.
void cugl::dsp::PoleZeroFIR::setACoeff  (  float  a1  ) 
Sets the lower coefficient.
Setting this leaves the upper coefficients unchanged.
a1  The lower firstorder coefficient 
void cugl::dsp::PoleZeroFIR::setAllpass  (  float  coefficient  ) 
Sets the filter to be a firstorder allpass with the given coefficient.
The allpass filter has unity gain at all frequencies. The coefficient magnitude must be less than one to maintain filter stability.
coefficient  The allpass coefficient 
void cugl::dsp::PoleZeroFIR::setBCoeff  (  float  b0, 
float  b1  
) 
Sets the upper coefficients.
Setting this leaves the lower coefficient unchanged.
b0  The upper zeroorder coefficient 
b1  The upper firstorder coefficient 
void cugl::dsp::PoleZeroFIR::setBlockZero  (  float  pole = 0.99f  ) 
Sets the filter to be a DC blocking filter with the given pole position.
This method sets the given pole position, together with a zero at z=1, to create a DC blocking filter. The argument magnitude should be close to (but less than) one to minimize lowfrequency attenuation.
pole  The filter pole 
void cugl::dsp::PoleZeroFIR::setChannels  (  unsigned  channels  ) 
Sets the number of channels for this filter
The data buffers depend on the number of channels. Changing this value will reset the data buffers to 0.
channels  The number of channels for this filter 
void cugl::dsp::PoleZeroFIR::setCoeff  (  const std::vector< float > &  bvals, 
const std::vector< float > &  avals  
) 
Sets the coefficients for this IIR filter.
This filter implements the standard difference equation:
a[0]*y[n] = b[0]*x[n] + ... + b[nb]*x[nnb]
where y is the output and x in the input. If a[0] is not equal to 1, the filter coeffcients are normalized by a[0]. All other acoefficients are ignored (they are only present for signature standardization). Similarly, all bcoefficients after the second are ignored. If any coefficients are missing, they are replaced with 1 for b[0] and a[0], and 0 otherwise.
bvals  The upper coefficients 
avals  The lower coefficients 
void cugl::dsp::PoleZeroFIR::setHighpass  (  float  frequency  ) 
Sets the filter to be a firstorder highpass for the given frequency
The resulting filter is typically considered the simplest effective highpass filter. However, filters are not intended to be model classes, and so it does not save the defining frequency.
The frequency is specified in "normalized" format. A normalized frequency is frequency/sample rate. For example, a 7 kHz frequency with a 44100 Hz sample rate has a normalized value 7000/44100 = 0.15873.
frequency  The normalized cutoff frequency 
void cugl::dsp::PoleZeroFIR::step  (  float  gain, 
float *  input,  
float *  output  
) 
Performs a filter of single frame of data.
The output is written to the given output array, which should be the same size as the input array. The size should be the number of channels.
To provide real time processing, the output is delayed by the number of acoefficients. Delayed results are buffered to be used the next time the filter is used (though they may be extracted with the flush
method). The gain parameter is applied at the filter input, but does not affect the filter coefficients.
gain  The input gain factor 
input  The input frame 
output  The frame to receive the output 

static 
Whether to use a vectorization algorithm (Access not thread safe)