1
#include "engineIIRfilter.h"
3
EngineIIRfilter::EngineIIRfilter(int potmeter_midi, int button_midi,
4
int button_bit, MidiObject *midi, const double *_coefs) {
5
// Initialize the buttons:
6
killbutton = new ControlPushButton("kill", simulated_latching, button_midi,
8
connect(killbutton, SIGNAL(valueChanged(valueType)), this, SLOT(slotUpdate()));
10
filterpot = new ControlPotmeter("filterpot", potmeter_midi, midi, 0., 2.);
11
connect(filterpot, SIGNAL(valueChanged(FLOAT)), this, SLOT(slotUpdate()));
16
EngineIIRfilter::~EngineIIRfilter() {
21
void EngineIIRfilter::process(CSAMPLE *source, CSAMPLE *destination, int buf_size) {
22
double GAIN = coefs[0];
23
for (int i=0; i<buf_size; i++) {
24
xv[0] = xv[1]; xv[1] = xv[2]; xv[2] = xv[3]; xv[3] = xv[4];
25
xv[4] = xv[5]; xv[5] = xv[6]; xv[6] = xv[7]; xv[7] = xv[8];
26
xv[8] = source[i] / GAIN;
27
yv[0] = yv[1]; yv[1] = yv[2]; yv[2] = yv[3]; yv[3] = yv[4];
28
yv[4] = yv[5]; yv[5] = yv[6]; yv[6] = yv[7]; yv[7] = yv[8];
30
yv[8] = (xv[0] + xv[8]) + coefs[1] * (xv[1] + xv[7]) +
31
coefs[2] * (xv[2] + xv[6])
32
+ coefs[3] * (xv[3] + xv[5]) + coefs[4] * xv[4]
33
+ (coefs[5] * yv[0]) + ( coefs[6] * yv[1])
34
+ (coefs[7] * yv[2]) + ( coefs[8] * yv[3])
35
+ (coefs[9] * yv[4]) + ( coefs[10] * yv[5])
36
+ (coefs[11] * yv[6]) + ( coefs[12] * yv[7]);
38
destination[i] += (gain-1)*yv[8];
42
void EngineIIRfilter::slotUpdate() {
43
// We've been called when either the killbutton or the potmeter has
44
// been touched. We have to check both.
45
if (killbutton->getValue()==down)
48
gain = filterpot->getValue();