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
6namespace stk {
7
8/***************************************************/
18/***************************************************/
19
20class TwoZero : public Filter
21{
22 public:
25
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
92inline 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
102inline 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
124inline 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
STK abstract filter class.
Definition Filter.h:23
An STK class to handle vectorized audio data.
Definition Stk.h:279
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
STK two-zero filter class.
Definition TwoZero.h:21
void setB1(StkFloat b1)
Set the b[1] coefficient value.
Definition TwoZero.h:36
void setNotch(StkFloat frequency, StkFloat radius)
Sets the filter coefficients for a "notch" at frequency (in Hz).
void setCoefficients(StkFloat b0, StkFloat b1, StkFloat b2, bool clearState=false)
Set all filter coefficients.
void setB0(StkFloat b0)
Set the b[0] coefficient value.
Definition TwoZero.h:33
TwoZero()
Default constructor creates a second-order pass-through filter.
StkFloat lastOut(void) const
Return the last computed output value.
Definition TwoZero.h:60
void setB2(StkFloat b2)
Set the b[2] coefficient value.
Definition TwoZero.h:39
void ignoreSampleRateChange(bool ignore=true)
A function to enable/disable the automatic updating of class data when the STK sample rate changes.
Definition TwoZero.h:30
~TwoZero()
Class destructor.
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition TwoZero.h:92
The STK namespace.
Definition ADSR.h:6

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