Version 4.0

This commit is contained in:
Gary Scavone
2013-09-25 14:50:19 +02:00
committed by Stephen Sinclair
parent 3f126af4e5
commit 81475b04c5
473 changed files with 36355 additions and 28396 deletions

View File

@@ -1,68 +1,97 @@
/*******************************************/
/* 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));
outputs = (MY_FLOAT *) malloc(sizeof(MY_FLOAT));
b0Coeff = (MY_FLOAT) 1.0;
b1Coeff = (MY_FLOAT) 0.0;
a1Coeff = (MY_FLOAT) 0.0;
gain = (MY_FLOAT) 1.0;
this->clear();
}
PoleZero :: ~PoleZero()
{
free(inputs);
free(outputs);
}
void PoleZero :: clear()
{
inputs[0] = (MY_FLOAT) 0.0;
outputs[0] = (MY_FLOAT) 0.0;
lastOutput = (MY_FLOAT) 0.0;
}
void PoleZero :: setA1(MY_FLOAT coeff)
{
a1Coeff = coeff;
}
void PoleZero :: setB0(MY_FLOAT coeff)
{
b0Coeff = coeff;
}
void PoleZero :: setB1(MY_FLOAT coeff)
{
b1Coeff = 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 in_sample = gain*sample;
lastOutput = b0Coeff*in_sample + b1Coeff*inputs[0] - a1Coeff*outputs[0];
inputs[0] = in_sample;
outputs[0] = lastOutput;
return lastOutput;
}
/***************************************************/
/*! \class PoleZero
\brief STK one-pole, one-zero filter class.
This protected Filter subclass implements
a one-pole, one-zero digital filter. A
method is provided for creating an allpass
filter with a given coefficient. Another
method is provided to create a DC blocking filter.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
*/
/***************************************************/
#include "PoleZero.h"
PoleZero :: PoleZero() : Filter()
{
// Default setting for pass-through.
MY_FLOAT B[2] = {1.0, 0.0};
MY_FLOAT A[2] = {1.0, 0.0};
Filter::setCoefficients( 2, B, 2, A );
}
PoleZero :: ~PoleZero()
{
}
void PoleZero :: clear(void)
{
Filter::clear();
}
void PoleZero :: setB0(MY_FLOAT b0)
{
b[0] = b0;
}
void PoleZero :: setB1(MY_FLOAT b1)
{
b[1] = b1;
}
void PoleZero :: setA1(MY_FLOAT a1)
{
a[1] = a1;
}
void PoleZero :: setAllpass(MY_FLOAT coefficient)
{
b[0] = coefficient;
b[1] = 1.0;
a[0] = 1.0; // just in case
a[1] = coefficient;
}
void PoleZero :: setBlockZero(MY_FLOAT thePole)
{
b[0] = 1.0;
b[1] = -1.0;
a[0] = 1.0; // just in case
a[1] = -thePole;
}
void PoleZero :: setGain(MY_FLOAT theGain)
{
Filter::setGain(theGain);
}
MY_FLOAT PoleZero :: getGain(void) const
{
return Filter::getGain();
}
MY_FLOAT PoleZero :: lastOut(void) const
{
return Filter::lastOut();
}
MY_FLOAT PoleZero :: tick(MY_FLOAT sample)
{
inputs[0] = gain * sample;
outputs[0] = b[0] * inputs[0] + b[1] * inputs[1] - a[1] * outputs[1];
inputs[1] = inputs[0];
outputs[1] = outputs[0];
return outputs[0];
}
MY_FLOAT *PoleZero :: tick(MY_FLOAT *vector, unsigned int vectorSize)
{
for (unsigned int i=0; i<vectorSize; i++)
vector[i] = tick(vector[i]);
return vector;
}