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
stk::Filter::Filter
Filter(void)
Class constructor.
Definition Filter.h:26
stk::OneZero::setCoefficients
void setCoefficients(StkFloat b0, StkFloat b1, bool clearState=false)
Set all filter coefficients.
stk::OneZero::~OneZero
~OneZero()
Class destructor.
stk::OneZero::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition OneZero.h:79
stk::OneZero::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition OneZero.h:50
stk::OneZero::setB1
void setB1(StkFloat b1)
Set the b[1] coefficient value.
Definition OneZero.h:34
stk::OneZero::OneZero
OneZero(StkFloat theZero=-1.0)
The default constructor creates a low-pass filter (zero at z = -1.0).
stk::OneZero::setB0
void setB0(StkFloat b0)
Set the b[0] coefficient value.
Definition OneZero.h:31
stk::OneZero::setZero
void setZero(StkFloat theZero)
Set the zero position in the z-plane.
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.