CUGL 1.3
Cornell University Game Library
CUTwoZeroFIR.h
1 //
2 // CUTwoZeroFIR.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This class is represents a two-zero FIR filter. For second-degree filters,
6 // it is significantly more performant than FIRFilter.
7 //
8 // This class supports vector optimizations for SSE and Neon 64. In timed
9 // simulations, these optimizations provide at least a 3-4x performance
10 // increase (and in isolated cases, much higher). Our implementation is
11 // limited to 128-bit words as 256-bit (e.g. AVX) and higher show no
12 // significant increase in performance.
13 //
14 // For performance reasons, this class does not have a (virtualized) subclass
15 // relationship with other IIR or FIR filters. However, the signature of the
16 // the calculation and coefficient methods has been standardized so that it
17 // can support templated polymorphism.
18 //
19 // This class is NOT THREAD SAFE. This is by design, for performance reasons.
20 // External locking may be required when the filter is shared between multiple
21 // threads (such as between an audio thread and the main thread).
22 //
23 // CUGL MIT License:
24 // This software is provided 'as-is', without any express or implied
25 // warranty. In no event will the authors be held liable for any damages
26 // arising from the use of this software.
27 //
28 // Permission is granted to anyone to use this software for any purpose,
29 // including commercial applications, and to alter it and redistribute it
30 // freely, subject to the following restrictions:
31 //
32 // 1. The origin of this software must not be misrepresented; you must not
33 // claim that you wrote the original software. If you use this software
34 // in a product, an acknowledgment in the product documentation would be
35 // appreciated but is not required.
36 //
37 // 2. Altered source versions must be plainly marked as such, and must not
38 // be misrepresented as being the original software.
39 //
40 // 3. This notice may not be removed or altered from any source distribution.
41 //
42 // Author: Walker White
43 // Version: 6/11/18
44 //
45 #ifndef __CU_TWO_ZERO_FIR_H__
46 #define __CU_TWO_ZERO_FIR_H__
47 
48 #include <cugl/math/dsp/CUIIRFilter.h>
49 #include <cugl/math/CUMathBase.h>
50 #include <cugl/util/CUAligned.h>
51 #include <cstring>
52 #include <vector>
53 
54 namespace cugl {
55  namespace dsp {
56 
91 class TwoZeroFIR {
92 private:
94  unsigned _channels;
96  float _b0, _b1, _b2;
99 
105  void reset();
106 
107 #pragma mark SPECIALIZED FILTERS
108 
137  void stride(float gain, float* input, float* output, size_t size, unsigned channel);
138 
161  void single(float gain, float* input, float* output, size_t size);
162 
186  void dual(float gain, float* input, float* output, size_t size);
187 
214  void trio(float gain, float* input, float* output, size_t size);
215 
239  void quad(float gain, float* input, float* output, size_t size);
240 
264  void quart(float gain, float* input, float* output, size_t size);
265 
266 public:
268  static bool VECTORIZE;
269 
270 #pragma mark Constructors
271 
274  TwoZeroFIR();
275 
281  TwoZeroFIR(unsigned channels);
282 
297  TwoZeroFIR(unsigned channels, float b0, float b1, float b2);
298 
304  TwoZeroFIR(const TwoZeroFIR& copy);
305 
311  TwoZeroFIR(TwoZeroFIR&& filter);
312 
316  ~TwoZeroFIR();
317 
318 #pragma mark IIR Signature
319 
327  unsigned getChannels() const { return _channels; }
328 
337  void setChannels(unsigned channels);
338 
356  void setCoeff(const std::vector<float> &bvals, const std::vector<float> &avals);
357 
369  const std::vector<float> getBCoeff() const;
370 
382  const std::vector<float> getACoeff() const;
383 
384 #pragma mark Specialized Attributes
385 
398  void setBCoeff(float b0, float b1, float b2);
399 
427  void setNotch( float frequency, float radius );
428 
435  void setZeroes(float zero1, float zero2);
436 
437 #pragma mark Filter Methods
438 
454  void step(float gain, float* input, float* output);
455 
475  void calculate(float gain, float* input, float* output, size_t size);
476 
480  void clear();
481 
490  size_t flush(float* output);
491 };
492  }
493 }
494 #endif /* __CU_TWO_ZERO_FIR_H__ */
cugl::dsp::TwoZeroFIR::getACoeff
const std::vector< float > getACoeff() const
cugl::dsp::TwoZeroFIR::TwoZeroFIR
TwoZeroFIR()
cugl::dsp::TwoZeroFIR::getBCoeff
const std::vector< float > getBCoeff() const
cugl::dsp::TwoZeroFIR::setCoeff
void setCoeff(const std::vector< float > &bvals, const std::vector< float > &avals)
cugl::dsp::TwoZeroFIR::clear
void clear()
cugl::dsp::TwoZeroFIR::setBCoeff
void setBCoeff(float b0, float b1, float b2)
cugl::dsp::TwoZeroFIR::getChannels
unsigned getChannels() const
Definition: CUTwoZeroFIR.h:327
cugl::Aligned< float >
cugl::dsp::TwoZeroFIR
Definition: CUTwoZeroFIR.h:91
cugl::dsp::TwoZeroFIR::setNotch
void setNotch(float frequency, float radius)
cugl::dsp::TwoZeroFIR::setChannels
void setChannels(unsigned channels)
cugl::dsp::TwoZeroFIR::VECTORIZE
static bool VECTORIZE
Definition: CUTwoZeroFIR.h:268
cugl::dsp::TwoZeroFIR::step
void step(float gain, float *input, float *output)
cugl::dsp::TwoZeroFIR::~TwoZeroFIR
~TwoZeroFIR()
cugl::dsp::TwoZeroFIR::setZeroes
void setZeroes(float zero1, float zero2)
cugl::dsp::TwoZeroFIR::flush
size_t flush(float *output)
cugl::dsp::TwoZeroFIR::calculate
void calculate(float gain, float *input, float *output, size_t size)