Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

PoleZero.h
1#ifndef STK_POLEZERO_H
2#define STK_POLEZERO_H
3
4#include "Filter.h"
5
6 namespace stk {
7
8/***************************************************/
19/***************************************************/
20
21 class PoleZero : public Filter
22{
23 public:
24
26 PoleZero();
27
29 ~PoleZero();
30
32 void setB0( StkFloat b0 ) { b_[0] = b0; };
33
35 void setB1( StkFloat b1 ) { b_[1] = b1; };
36
38 void setA1( StkFloat a1 ) { a_[1] = a1; };
39
41 void setCoefficients( StkFloat b0, StkFloat b1, StkFloat a1, bool clearState = false );
42
44
50 void setAllpass( StkFloat coefficient );
51
53
59 void setBlockZero( StkFloat thePole = 0.99 );
60
62 StkFloat lastOut( void ) const { return lastFrame_[0]; };
63
65 StkFloat tick( StkFloat input );
66
68
75 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
76
77};
78
79 inline StkFloat PoleZero :: tick( StkFloat input )
80{
81 inputs_[0] = gain_ * input;
82 lastFrame_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] - a_[1] * outputs_[1];
83 inputs_[1] = inputs_[0];
84 outputs_[1] = lastFrame_[0];
85
86 return lastFrame_[0];
87}
88
89 inline StkFrames& PoleZero :: tick( StkFrames& frames, unsigned int channel )
90{
91#if defined(_STK_DEBUG_)
92 if ( channel >= frames.channels() ) {
93 oStream_ << "PoleZero::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] + b_[1] * inputs_[1] - a_[1] * outputs_[1];
103 inputs_[1] = inputs_[0];
104 outputs_[1] = *samples;
105 }
106
107 lastFrame_[0] = outputs_[1];
108 return frames;
109}
110
111} // stk namespace
112
113#endif
stk::Filter::Filter
Filter(void)
Class constructor.
Definition Filter.h:26
stk::PoleZero::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition PoleZero.h:79
stk::PoleZero::setAllpass
void setAllpass(StkFloat coefficient)
Set the filter for allpass behavior using coefficient.
stk::PoleZero::setB0
void setB0(StkFloat b0)
Set the b[0] coefficient value.
Definition PoleZero.h:32
stk::PoleZero::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition PoleZero.h:62
stk::PoleZero::~PoleZero
~PoleZero()
Class destructor.
stk::PoleZero::setBlockZero
void setBlockZero(StkFloat thePole=0.99)
Create a DC blocking filter with the given pole position in the z-plane.
stk::PoleZero::PoleZero
PoleZero()
Default constructor creates a first-order pass-through filter.
stk::PoleZero::setB1
void setB1(StkFloat b1)
Set the b[1] coefficient value.
Definition PoleZero.h:35
stk::PoleZero::setA1
void setA1(StkFloat a1)
Set the a[1] coefficient value.
Definition PoleZero.h:38
stk::PoleZero::setCoefficients
void setCoefficients(StkFloat b0, StkFloat b1, StkFloat a1, bool clearState=false)
Set all filter coefficients.
stk::StkFrames
An STK class to handle vectorized audio data.
Definition Stk.h:279
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
stk
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.