ViPERFX_RE/src/cpp/viper/utils/HighShelf.cpp

47 lines
1.2 KiB
C++
Raw Normal View History

2021-07-28 23:50:34 +02:00
#include "HighShelf.h"
2022-09-18 05:12:26 +02:00
#include <cmath>
2021-07-28 23:50:34 +02:00
2022-09-18 05:12:26 +02:00
double HighShelf::Process(double sample) {
double out = (((this->x_1 * this->b1 + sample * this->b0 + this->b2 * this->x_2) - this->y_1 * this->a1) - this->a2 * this->y_2) * this->a0;
2021-07-28 23:50:34 +02:00
this->y_2 = this->y_1;
this->y_1 = out;
this->x_2 = this->x_1;
this->x_1 = sample;
return out;
}
2022-09-18 05:12:26 +02:00
void HighShelf::SetFrequency(double freq) {
2021-07-28 23:50:34 +02:00
this->frequency = freq;
}
2022-09-18 05:12:26 +02:00
void HighShelf::SetGain(double gain) {
this->gain = log10(gain) * 20.0;
2021-07-28 23:50:34 +02:00
}
2022-09-18 05:12:26 +02:00
void HighShelf::SetSamplingRate(double samplingRate) {
double x = (2 * M_PI * this->frequency) / samplingRate;
double sinX = sin(x);
double cosX = cos(x);
double y = exp((this->gain * log(10.0)) / 40.0);
this->x_1 = 0.0;
this->x_2 = 0.0;
this->y_1 = 0.0;
this->y_2 = 0.0;
double z = sqrt(y * 2.0) * sinX;
double a = (y - 1.0) * cosX;
double b = (y + 1.0) - a;
double c = z + b;
double d = (y + 1.0) * cosX;
double e = (y + 1.0) + a;
double f = (y - 1.0) - d;
2021-07-28 23:50:34 +02:00
2022-09-18 05:12:26 +02:00
this->a0 = 1.0 / c;
this->a1 = a * 2.0;
this->a2 = b - z;
this->b0 = (e + z) * y;
this->b1 = -y * 2.0 * ((y - 1.0) + d);
this->b2 = (e - z) * y;
2021-07-28 23:50:34 +02:00
}