⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 twopole.cpp

📁 Mobile STK for Symbian OS V0.1
💻 CPP
字号:
/***************************************************//*! \class TwoPole    \brief STK two-pole filter class.    This protected Filter subclass implements    a two-pole digital filter.  A method is    provided for creating a resonance in the    frequency response while maintaining a nearly    constant filter gain.    by Perry R. Cook and Gary P. Scavone, 1995 - 2005.*//***************************************************/#include "TwoPole.h"#if !defined(SYMBIAN)#include <math.h>#else#include "symbmath.h"#endifTwoPole :: TwoPole() : Filter(){#if !defined(SYMBIAN)  std::vector<StkFloat> b(1, 1.0);  std::vector<StkFloat> a(3, 0.0);#else  FloatVector b(1, 1.0);  FloatVector a(3, 0.0);/*	TReal *b = new (ELeave) TReal[1];	b[0] = 1.0;	TReal *a = new (ELeave) TReal[3];	a[1] = 0.0;	a[2] = 0.0;*/#endif  a[0] = 1.0;  Filter::setCoefficients( b, a );}TwoPole :: ~TwoPole(){}void TwoPole :: clear(void){  Filter::clear();}void TwoPole :: setB0(StkFloat b0){  b_[0] = b0;}void TwoPole :: setA1(StkFloat a1){  a_[1] = a1;}void TwoPole :: setA2(StkFloat a2){  a_[2] = a2;}void TwoPole :: setResonance(StkFloat frequency, StkFloat radius, bool normalize){  a_[2] = radius * radius;  a_[1] = (StkFloat) -2.0 * radius * cos(TWO_PI * frequency / Stk::sampleRate());  if ( normalize ) {    // Normalize the filter gain ... not terribly efficient.    StkFloat real = 1 - radius + (a_[2] - radius) * cos(TWO_PI * 2 * frequency / Stk::sampleRate());    StkFloat imag = (a_[2] - radius) * sin(TWO_PI * 2 * frequency / Stk::sampleRate());    b_[0] = sqrt( pow(real, 2) + pow(imag, 2) );  }}void TwoPole :: setGain(StkFloat gain){  Filter::setGain(gain);}StkFloat TwoPole :: getGain(void) const{  return Filter::getGain();}StkFloat TwoPole :: lastOut(void) // SYMBIAN const removed: const{  return Filter::lastOut();}StkFloat TwoPole :: tick( StkFloat input ){  inputs_[0] = gain_ * input;  outputs_[0] = b_[0] * inputs_[0] - a_[2] * outputs_[2] - a_[1] * outputs_[1];  outputs_[2] = outputs_[1];  outputs_[1] = outputs_[0];  return outputs_[0];}StkFrames& TwoPole :: tick( StkFrames& frames, unsigned int channel ){  return Filter::tick( frames, channel );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -