Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


TwoZero.h
1 #ifndef STK_TWOZERO_H
2 #define STK_TWOZERO_H
3 
4 #include "Filter.h"
5 
6 namespace stk {
7 
8 /***************************************************/
18 /***************************************************/
19 
20 class TwoZero : public Filter
21 {
22  public:
24  TwoZero();
25 
27  ~TwoZero();
28 
30  void ignoreSampleRateChange( bool ignore = true ) { ignoreSampleRateChange_ = ignore; };
31 
33  void setB0( StkFloat b0 ) { b_[0] = b0; };
34 
36  void setB1( StkFloat b1 ) { b_[1] = b1; };
37 
39  void setB2( StkFloat b2 ) { b_[2] = b2; };
40 
42  void setCoefficients( StkFloat b0, StkFloat b1, StkFloat b2, bool clearState = false );
43 
45 
57  void setNotch( StkFloat frequency, StkFloat radius );
58 
60  StkFloat lastOut( void ) const { return lastFrame_[0]; };
61 
63  StkFloat tick( StkFloat input );
64 
66 
74  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
75 
77 
85  StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
86 
87  protected:
88 
89  void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
90 };
91 
92 inline StkFloat TwoZero :: tick( StkFloat input )
93 {
94  inputs_[0] = gain_ * input;
95  lastFrame_[0] = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0];
96  inputs_[2] = inputs_[1];
97  inputs_[1] = inputs_[0];
98 
99  return lastFrame_[0];
100 }
101 
102 inline StkFrames& TwoZero :: tick( StkFrames& frames, unsigned int channel )
103 {
104 #if defined(_STK_DEBUG_)
105  if ( channel >= frames.channels() ) {
106  oStream_ << "TwoZero::tick(): channel and StkFrames arguments are incompatible!";
107  handleError( StkError::FUNCTION_ARGUMENT );
108  }
109 #endif
110 
111  StkFloat *samples = &frames[channel];
112  unsigned int hop = frames.channels();
113  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
114  inputs_[0] = gain_ * *samples;
115  *samples = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0];
116  inputs_[2] = inputs_[1];
117  inputs_[1] = inputs_[0];
118  }
119 
120  lastFrame_[0] = *(samples-hop);
121  return frames;
122 }
123 
124 inline StkFrames& TwoZero :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
125 {
126 #if defined(_STK_DEBUG_)
127  if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
128  oStream_ << "TwoZero::tick(): channel and StkFrames arguments are incompatible!";
129  handleError( StkError::FUNCTION_ARGUMENT );
130  }
131 #endif
132 
133  StkFloat *iSamples = &iFrames[iChannel];
134  StkFloat *oSamples = &oFrames[oChannel];
135  unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
136  for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
137  inputs_[0] = gain_ * *iSamples;
138  *oSamples = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0];
139  inputs_[2] = inputs_[1];
140  inputs_[1] = inputs_[0];
141  }
142 
143  lastFrame_[0] = *(oSamples-oHop);
144  return iFrames;
145 }
146 
147 } // stk namespace
148 
149 #endif

The Synthesis ToolKit in C++ (STK)
©1995--2014 Perry R. Cook and Gary P. Scavone. All Rights Reserved.