2016-09-10 13:03:27 -07:00
|
|
|
/*
|
|
|
|
* @file biquad.cpp
|
|
|
|
*
|
|
|
|
* @date Sep 10, 2016
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2016-09-10 13:03:27 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "biquad.h"
|
|
|
|
|
|
|
|
Biquad::Biquad() {
|
2018-12-27 06:40:40 -08:00
|
|
|
a0 = a1 = a2 = b1 = b2 = 0;
|
2016-09-17 12:02:55 -07:00
|
|
|
z1 = z2 = 0;
|
|
|
|
}
|
|
|
|
|
2019-03-31 13:33:16 -07:00
|
|
|
// todo: decouple from engine and just use bi_quard_s
|
|
|
|
void Biquad::initValue(float input, bi_quard_s *settings) {
|
|
|
|
a0 = settings->a0;
|
|
|
|
a1 = settings->a1;
|
|
|
|
a2 = settings->a2;
|
|
|
|
b1 = settings->b1;
|
|
|
|
b2 = settings->b2;
|
2016-09-10 13:03:27 -07:00
|
|
|
|
2016-09-17 12:02:55 -07:00
|
|
|
z1 = input * (1 - a0);
|
2016-09-17 13:02:56 -07:00
|
|
|
z2 = input * (1 - a0 - a1 + b1);
|
2016-09-10 19:03:38 -07:00
|
|
|
}
|
|
|
|
|
2016-09-10 13:03:27 -07:00
|
|
|
float Biquad::getValue(float input) {
|
|
|
|
float result = input * a0 + z1;
|
|
|
|
z1 = input * a1 + z2 - b1 * result;
|
|
|
|
z2 = input * a2 - b2 * result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|