Debian Codegraph @

lib-src/libnyquist/nyquist/nyqstk/src/PoleZero.cpp

raw
1 /***************************************************/
2 /*! \class PoleZero
3 \brief STK one-pole, one-zero filter class.
4
5 This protected Filter subclass implements
6 a one-pole, one-zero digital filter. A
7 method is provided for creating an allpass
8 filter with a given coefficient. Another
9 method is provided to create a DC blocking filter.
10
11 by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
12 */
13 /***************************************************/
14
15 #include "PoleZero.h"
16
17 using namespace Nyq;
18
19 PoleZero :: PoleZero() : Filter()
20 {
21 // Default setting for pass-through.
22 std::vector<StkFloat> b(2, 0.0);
23 std::vector<StkFloat> a(2, 0.0);
24 b[0] = 1.0;
25 a[0] = 1.0;
26 Filter::setCoefficients( b, a );
27 }
28
29 PoleZero :: ~PoleZero()
30 {
31 }
32
33 void PoleZero :: clear(void)
34 {
35 Filter::clear();
36 }
37
38 void PoleZero :: setB0(StkFloat b0)
39 {
40 b_[0] = b0;
41 }
42
43 void PoleZero :: setB1(StkFloat b1)
44 {
45 b_[1] = b1;
46 }
47
48 void PoleZero :: setA1(StkFloat a1)
49 {
50 a_[1] = a1;
51 }
52
53 void PoleZero :: setAllpass(StkFloat coefficient)
54 {
55 b_[0] = coefficient;
56 b_[1] = 1.0;
57 a_[0] = 1.0; // just in case
58 a_[1] = coefficient;
59 }
60
61 void PoleZero :: setBlockZero(StkFloat thePole)
62 {
63 b_[0] = 1.0;
64 b_[1] = -1.0;
65 a_[0] = 1.0; // just in case
66 a_[1] = -thePole;
67 }
68
69 void PoleZero :: setGain(StkFloat gain)
70 {
71 Filter::setGain(gain);
72 }
73
74 StkFloat PoleZero :: getGain(void) const
75 {
76 return Filter::getGain();
77 }
78
79 StkFloat PoleZero :: lastOut(void) const
80 {
81 return Filter::lastOut();
82 }
83
84 StkFloat PoleZero :: tick( StkFloat input )
85 {
86 inputs_[0] = gain_ * input;
87 outputs_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] - a_[1] * outputs_[1];
88 inputs_[1] = inputs_[0];
89 outputs_[1] = outputs_[0];
90
91 return outputs_[0];
92 }
93
94 StkFrames& PoleZero :: tick( StkFrames& frames, unsigned int channel )
95 {
96 return Filter::tick( frames, channel );
97 }