24const StkFloat RECIP_SQRT_2 =
static_cast<StkFloat
>( M_SQRT1_2 );
39 void setCoefficients( StkFloat b0, StkFloat b1, StkFloat b2, StkFloat a1, StkFloat a2,
bool clearState =
false );
42 void setB0( StkFloat b0 ) { b_[0] = b0; };
45 void setB1( StkFloat b1 ) { b_[1] = b1; };
48 void setB2( StkFloat b2 ) { b_[2] = b2; };
51 void setA1( StkFloat a1 ) { a_[1] = a1; };
54 void setA2( StkFloat a2 ) { a_[2] = a2; };
70 void setResonance( StkFloat frequency, StkFloat radius,
bool normalize =
false );
80 void setNotch( StkFloat frequency, StkFloat radius );
152 StkFloat
lastOut(
void )
const {
return lastFrame_[0]; };
155 StkFloat
tick( StkFloat input );
181 virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
185 void setCommonFilterValues( StkFloat fc, StkFloat Q );
192inline StkFloat BiQuad :: tick( StkFloat input )
194 inputs_[0] = gain_ * input;
195 lastFrame_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
196 lastFrame_[0] -= a_[2] * outputs_[2] + a_[1] * outputs_[1];
197 inputs_[2] = inputs_[1];
198 inputs_[1] = inputs_[0];
199 outputs_[2] = outputs_[1];
200 outputs_[1] = lastFrame_[0];
202 return lastFrame_[0];
207#if defined(_STK_DEBUG_)
208 if ( channel >= frames.
channels() ) {
209 oStream_ <<
"BiQuad::tick(): channel and StkFrames arguments are incompatible!";
210 handleError( StkError::FUNCTION_ARGUMENT );
214 StkFloat *samples = &frames[channel];
215 unsigned int hop = frames.
channels();
216 for (
unsigned int i=0; i<frames.
frames(); i++, samples += hop ) {
217 inputs_[0] = gain_ * *samples;
218 *samples = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
219 *samples -= a_[2] * outputs_[2] + a_[1] * outputs_[1];
220 inputs_[2] = inputs_[1];
221 inputs_[1] = inputs_[0];
222 outputs_[2] = outputs_[1];
223 outputs_[1] = *samples;
226 lastFrame_[0] = outputs_[1];
232#if defined(_STK_DEBUG_)
234 oStream_ <<
"BiQuad::tick(): channel and StkFrames arguments are incompatible!";
235 handleError( StkError::FUNCTION_ARGUMENT );
239 StkFloat *iSamples = &iFrames[iChannel];
240 StkFloat *oSamples = &oFrames[oChannel];
242 for (
unsigned int i=0; i<iFrames.
frames(); i++, iSamples += iHop, oSamples += oHop ) {
243 inputs_[0] = gain_ * *iSamples;
244 *oSamples = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
245 *oSamples -= a_[2] * outputs_[2] + a_[1] * outputs_[1];
246 inputs_[2] = inputs_[1];
247 inputs_[1] = inputs_[0];
248 outputs_[2] = outputs_[1];
249 outputs_[1] = *oSamples;
252 lastFrame_[0] = outputs_[1];
STK biquad (two-pole, two-zero) filter class.
Definition BiQuad.h:26
void setLowPass(StkFloat fc, StkFloat Q=RECIP_SQRT_2)
Set the filter coefficients for a low-pass with cutoff frequency fc (in Hz) and Q-factor Q.
void setA1(StkFloat a1)
Set the a[1] coefficient value.
Definition BiQuad.h:51
void setB2(StkFloat b2)
Set the b[2] coefficient value.
Definition BiQuad.h:48
void setB0(StkFloat b0)
Set the b[0] coefficient value.
Definition BiQuad.h:42
void setEqualGainZeroes(void)
Sets the filter zeroes for equal resonance gain.
void setHighPass(StkFloat fc, StkFloat Q=RECIP_SQRT_2)
Set the filter coefficients for a high-pass with cutoff frequency fc (in Hz) and Q-factor Q.
void setResonance(StkFloat frequency, StkFloat radius, bool normalize=false)
Sets the filter coefficients for a resonance at frequency (in Hz).
void setBandReject(StkFloat fc, StkFloat Q)
Set the filter coefficients for a band-reject centered at fc (in Hz) with Q-factor Q.
StkFloat tick(StkFloat input)
Input one sample to the filter and return a reference to one output.
Definition BiQuad.h:192
void setAllPass(StkFloat fc, StkFloat Q)
Set the filter coefficients for an all-pass centered at fc (in Hz) with Q-factor Q.
void setBandPass(StkFloat fc, StkFloat Q)
Set the filter coefficients for a band-pass centered at fc (in Hz) with Q-factor Q.
BiQuad()
Default constructor creates a second-order pass-through filter.
void ignoreSampleRateChange(bool ignore=true)
A function to enable/disable the automatic updating of class data when the STK sample rate changes.
Definition BiQuad.h:36
StkFloat lastOut(void) const
Return the last computed output value.
Definition BiQuad.h:152
~BiQuad()
Class destructor.
void setB1(StkFloat b1)
Set the b[1] coefficient value.
Definition BiQuad.h:45
void setNotch(StkFloat frequency, StkFloat radius)
Set the filter coefficients for a notch at frequency (in Hz).
void setA2(StkFloat a2)
Set the a[2] coefficient value.
Definition BiQuad.h:54
void setCoefficients(StkFloat b0, StkFloat b1, StkFloat b2, StkFloat a1, StkFloat a2, bool clearState=false)
Set all filter coefficients.
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
The STK namespace.
Definition ADSR.h:6