The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

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

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