mirror of
https://github.com/thestk/stk
synced 2026-01-15 14:01:52 +00:00
Version 3.0
This commit is contained in:
committed by
Stephen Sinclair
parent
7c0ee03d60
commit
868787a5f9
63
STK/PoleZero.cpp
Normal file
63
STK/PoleZero.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/*******************************************/
|
||||
/* PoleZero (1-pole, 1-zero) Filter Class */
|
||||
/* by Gary P. Scavone, 1999 */
|
||||
/* */
|
||||
/* See books on filters to understand */
|
||||
/* more about how this works. Nothing */
|
||||
/* out of the ordinary in this version. */
|
||||
/*******************************************/
|
||||
|
||||
#include "PoleZero.h"
|
||||
|
||||
PoleZero :: PoleZero() : Filter()
|
||||
{
|
||||
inputs = (MY_FLOAT *) malloc(sizeof(MY_FLOAT));
|
||||
zeroCoeff = (MY_FLOAT) 0.0;
|
||||
poleCoeff = (MY_FLOAT) 0.0;
|
||||
gain = (MY_FLOAT) 1.0;
|
||||
this->clear();
|
||||
}
|
||||
|
||||
PoleZero :: ~PoleZero()
|
||||
{
|
||||
free(inputs);
|
||||
}
|
||||
|
||||
void PoleZero :: clear()
|
||||
{
|
||||
inputs[0] = (MY_FLOAT) 0.0;
|
||||
lastOutput = (MY_FLOAT) 0.0;
|
||||
}
|
||||
|
||||
void PoleZero :: setPoleCoeff(MY_FLOAT coeff)
|
||||
{
|
||||
poleCoeff = coeff;
|
||||
}
|
||||
|
||||
void PoleZero :: setZeroCoeff(MY_FLOAT coeff)
|
||||
{
|
||||
zeroCoeff = coeff;
|
||||
}
|
||||
|
||||
void PoleZero :: setGain(MY_FLOAT aValue)
|
||||
{
|
||||
gain = aValue;
|
||||
}
|
||||
|
||||
// PoleZero is one pole, one zero filter
|
||||
// Look it up in your favorite DSP text
|
||||
MY_FLOAT PoleZero :: tick(MY_FLOAT sample)
|
||||
{
|
||||
MY_FLOAT temp;
|
||||
|
||||
// Direct Form II Implementation - only 1 state variable
|
||||
temp = sample * gain;
|
||||
temp += inputs[0] * poleCoeff;
|
||||
|
||||
lastOutput = temp;
|
||||
lastOutput += (inputs[0] * zeroCoeff);
|
||||
inputs[0] = temp;
|
||||
|
||||
return lastOutput;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user