📄 twozero.cpp
字号:
/***************************************************//*! \class TwoZero \brief STK two-zero filter class. This protected Filter subclass implements a two-zero digital filter. A method is provided for creating a "notch" in the frequency response while maintaining a constant filter gain. by Perry R. Cook and Gary P. Scavone, 1995 - 2005.*//***************************************************/#include "TwoZero.h"#if !defined(SYMBIAN)#include <math.h>#else#include "symbmath.h"#endifTwoZero :: TwoZero() : Filter(){#if !defined(SYMBIAN) std::vector<StkFloat> b(3, 0.0); b[0] = 1.0; std::vector<StkFloat> a(1, 1.0);#else FloatVector b(3, 0.0); b[0] = 1.0; FloatVector a(1,1.0);/* TReal *b = new (ELeave) TReal[3]; b[0] = 1.0; b[1] = 0.0; b[2] = 0.0; TReal *a = new (ELeave) TReal[1]; a[0] = 1.0;*/#endif Filter::setCoefficients( b, a );}TwoZero :: ~TwoZero(){}void TwoZero :: clear(void){ Filter::clear();}void TwoZero :: setB0(StkFloat b0){ b_[0] = b0;}void TwoZero :: setB1(StkFloat b1){ b_[1] = b1;}void TwoZero :: setB2(StkFloat b2){ b_[2] = b2;}void TwoZero :: setNotch(StkFloat frequency, StkFloat radius){ b_[2] = radius * radius; b_[1] = (StkFloat) -2.0 * radius * cos(TWO_PI * (double) frequency / Stk::sampleRate()); // Normalize the filter gain. if (b_[1] > 0.0) // Maximum at z = 0. b_[0] = 1.0 / (1.0+b_[1]+b_[2]); else // Maximum at z = -1. b_[0] = 1.0 / (1.0-b_[1]+b_[2]); b_[1] *= b_[0]; b_[2] *= b_[0];}void TwoZero :: setGain(StkFloat gain){ Filter::setGain(gain);}StkFloat TwoZero :: getGain(void) const{ return Filter::getGain();}StkFloat TwoZero :: lastOut(void) // SYMBIAN const removed: const{ return Filter::lastOut();}StkFloat TwoZero :: tick( StkFloat input ){ inputs_[0] = gain_ * input; outputs_[0] = b_[2] * inputs_[2] + b_[1] * inputs_[1] + b_[0] * inputs_[0]; inputs_[2] = inputs_[1]; inputs_[1] = inputs_[0]; return outputs_[0];}StkFrames& TwoZero :: tick( StkFrames& frames, unsigned int channel ){ return Filter::tick( frames, channel );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -