Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


OnePole.h
1 #ifndef STK_ONEPOLE_H
2 #define STK_ONEPOLE_H
3 
4 #include "Filter.h"
5 
6 namespace stk {
7 
8 /***************************************************/
18 /***************************************************/
19 
20 class OnePole : public Filter
21 {
22 public:
23 
25  OnePole( StkFloat thePole = 0.9 );
26 
28  ~OnePole();
29 
31  void setB0( StkFloat b0 ) { b_[0] = b0; };
32 
34  void setA1( StkFloat a1 ) { a_[1] = a1; };
35 
37  void setCoefficients( StkFloat b0, StkFloat a1, bool clearState = false );
38 
40 
48  void setPole( StkFloat thePole );
49 
51  StkFloat lastOut( void ) const { return lastFrame_[0]; };
52 
54  StkFloat tick( StkFloat input );
55 
57 
65  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
66 
68 
76  StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
77 
78 };
79 
80 inline StkFloat OnePole :: tick( StkFloat input )
81 {
82  inputs_[0] = gain_ * input;
83  lastFrame_[0] = b_[0] * inputs_[0] - a_[1] * outputs_[1];
84  outputs_[1] = lastFrame_[0];
85 
86  return lastFrame_[0];
87 }
88 
89 inline StkFrames& OnePole :: tick( StkFrames& frames, unsigned int channel )
90 {
91 #if defined(_STK_DEBUG_)
92  if ( channel >= frames.channels() ) {
93  oStream_ << "OnePole::tick(): channel and StkFrames arguments are incompatible!";
94  handleError( StkError::FUNCTION_ARGUMENT );
95  }
96 #endif
97 
98  StkFloat *samples = &frames[channel];
99  unsigned int hop = frames.channels();
100  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
101  inputs_[0] = gain_ * *samples;
102  *samples = b_[0] * inputs_[0] - a_[1] * outputs_[1];
103  outputs_[1] = *samples;
104  }
105 
106  lastFrame_[0] = outputs_[1];
107  return frames;
108 }
109 
110 inline StkFrames& OnePole :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
111 {
112 #if defined(_STK_DEBUG_)
113  if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
114  oStream_ << "OnePole::tick(): channel and StkFrames arguments are incompatible!";
115  handleError( StkError::FUNCTION_ARGUMENT );
116  }
117 #endif
118 
119  StkFloat *iSamples = &iFrames[iChannel];
120  StkFloat *oSamples = &oFrames[oChannel];
121  unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
122  for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
123  inputs_[0] = gain_ * *iSamples;
124  *oSamples = b_[0] * inputs_[0] - a_[1] * outputs_[1];
125  outputs_[1] = *oSamples;
126  }
127 
128  lastFrame_[0] = outputs_[1];
129  return iFrames;
130 }
131 
132 } // stk namespace
133 
134 #endif

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