1 /***************************************************/
2 /*! \class OneZero
3     \brief STK one-zero filter class.
4 
5     This protected Filter subclass implements
6     a one-zero digital filter.  A method is
7     provided for setting the zero position
8     along the real axis of the z-plane while
9     maintaining a constant filter gain.
10 
11     by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
12 */
13 /***************************************************/
14 
15 #include "OneZero.h"
16 
17 using namespace Nyq;
18 
OneZero()19 OneZero :: OneZero() : Filter()
20 {
21   std::vector<StkFloat> b(2, 0.5);
22   std::vector<StkFloat> a(1, 1.0);
23   Filter::setCoefficients( b, a );
24 }
25 
OneZero(StkFloat theZero)26 OneZero :: OneZero(StkFloat theZero) : Filter()
27 {
28   std::vector<StkFloat> b(2);
29   std::vector<StkFloat> a(1, 1.0);
30 
31   // Normalize coefficients for unity gain.
32   if (theZero > 0.0)
33     b[0] = 1.0 / ((StkFloat) 1.0 + theZero);
34   else
35     b[0] = 1.0 / ((StkFloat) 1.0 - theZero);
36 
37   b[1] = -theZero * b[0];
38   Filter::setCoefficients( b, a );
39 }
40 
~OneZero(void)41 OneZero :: ~OneZero(void)
42 {
43 }
44 
clear(void)45 void OneZero :: clear(void)
46 {
47   Filter::clear();
48 }
49 
setB0(StkFloat b0)50 void OneZero :: setB0(StkFloat b0)
51 {
52   b_[0] = b0;
53 }
54 
setB1(StkFloat b1)55 void OneZero :: setB1(StkFloat b1)
56 {
57   b_[1] = b1;
58 }
59 
setZero(StkFloat theZero)60 void OneZero :: setZero(StkFloat theZero)
61 {
62   // Normalize coefficients for unity gain.
63   if (theZero > 0.0)
64     b_[0] = 1.0 / ((StkFloat) 1.0 + theZero);
65   else
66     b_[0] = 1.0 / ((StkFloat) 1.0 - theZero);
67 
68   b_[1] = -theZero * b_[0];
69 }
70 
setGain(StkFloat gain)71 void OneZero :: setGain(StkFloat gain)
72 {
73   Filter::setGain(gain);
74 }
75 
getGain(void) const76 StkFloat OneZero :: getGain(void) const
77 {
78   return Filter::getGain();
79 }
80 
lastOut(void) const81 StkFloat OneZero :: lastOut(void) const
82 {
83   return Filter::lastOut();
84 }
85 
tick(StkFloat input)86 StkFloat OneZero :: tick( StkFloat input )
87 {
88   inputs_[0] = gain_ * input;
89   outputs_[0] = b_[1] * inputs_[1] + b_[0] * inputs_[0];
90   inputs_[1] = inputs_[0];
91 
92   return outputs_[0];
93 }
94 
tick(StkFrames & frames,unsigned int channel)95 StkFrames& OneZero :: tick( StkFrames& frames, unsigned int channel )
96 {
97   return Filter::tick( frames, channel );
98 }
99