57 lines
1.0 KiB
C++
57 lines
1.0 KiB
C++
/*
|
|
* Filename: svf.cpp
|
|
*
|
|
* Description:
|
|
*
|
|
*
|
|
* Version:
|
|
* Created: Thu Oct 31 23:24:34 2019
|
|
* Revision: None
|
|
* Author: Rachel Fae Fox (foxiepaws),fox@foxiepa.ws
|
|
*
|
|
*/
|
|
|
|
#include "svf.h"
|
|
#include <math.h>
|
|
#define MAX(a,b) (a>b?a:b)
|
|
#define MIN(a,b) (a<b?a:b)
|
|
|
|
SVF::SVF(FilterMode f) {
|
|
this->mode = f;
|
|
this->reset();
|
|
this->freq = 0.0f;
|
|
this->q = 0.0f;
|
|
this->sample_rate=44100;
|
|
}
|
|
|
|
void SVF::reset() {
|
|
this->notch = 0;
|
|
this->high = 0;
|
|
this->low = 0;
|
|
this->band = 0;
|
|
}
|
|
|
|
float SVF::run(float in) {
|
|
float a = in;
|
|
float q = 1-this->q;
|
|
float freq = 2.0*sin(M_PI * MIN(0.25, this->freq/this->sample_rate));
|
|
this->low = this->low + freq * this->band;
|
|
this->high = q * a - this->low - q * this->band;
|
|
this->band = freq * this->high + this->band;
|
|
this->notch = this->high + this->low;
|
|
|
|
|
|
switch (mode) {
|
|
case _low:
|
|
return this->low;
|
|
case _band:
|
|
return this->band;
|
|
case _high:
|
|
return this->high;
|
|
case _notch:
|
|
return this->notch;
|
|
}
|
|
|
|
}
|
|
|