ViPERFX_RE/src/cpp/viper/effects/SpeakerCorrection.cpp

59 lines
1.9 KiB
C++
Raw Normal View History

2021-07-30 21:51:26 +02:00
#include "SpeakerCorrection.h"
#include "../constants.h"
SpeakerCorrection::SpeakerCorrection() {
2022-10-13 03:01:20 +02:00
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
this->enable = false;
2021-07-30 21:51:26 +02:00
Reset();
}
void SpeakerCorrection::Process(float *samples, uint32_t size) {
2022-10-13 03:01:20 +02:00
if (!this->enable) return;
for (int i = 0; i < size * 2; i += 2) {
double outL = samples[i];
outL = this->lowPass[0].ProcessSample(outL);
outL = this->highPass[0].ProcessSample(outL);
outL /= 2.0;
outL += this->bandPass[0].ProcessSample(outL);
samples[i] = (float) outL;
double outR = samples[i + 1];
outR = this->lowPass[1].ProcessSample(outR);
outR = this->highPass[1].ProcessSample(outR);
outR /= 2.0;
outR += this->bandPass[1].ProcessSample(outR);
samples[i + 1] = (float) outR;
2021-07-30 21:51:26 +02:00
}
}
void SpeakerCorrection::Reset() {
2022-10-13 03:01:20 +02:00
this->lowPass[0].Reset();
this->lowPass[1].Reset();
this->bandPass[0].Reset();
this->bandPass[1].Reset();
2022-10-13 03:53:30 +02:00
this->highPass[0].RefreshFilter(MultiBiquad::FilterType::HIGH_PASS, 0.0, 80.0, this->samplingRate, 1.0, false);
this->highPass[1].RefreshFilter(MultiBiquad::FilterType::HIGH_PASS, 0.0, 80.0, this->samplingRate, 1.0, false);
2022-10-13 03:01:20 +02:00
this->lowPass[0].SetLowPassParameter(13500.0, this->samplingRate, 1.0);
this->lowPass[1].SetLowPassParameter(13500.0, this->samplingRate, 1.0);
this->bandPass[0].SetBandPassParameter(420.0, this->samplingRate, 3.88);
this->bandPass[1].SetBandPassParameter(420.0, this->samplingRate, 3.88);
2021-07-30 21:51:26 +02:00
}
2022-10-13 03:01:20 +02:00
void SpeakerCorrection::SetEnable(bool enable) {
if (this->enable != enable) {
if (!this->enable) {
Reset();
}
this->enable = enable;
2021-07-31 01:15:40 +02:00
}
2021-07-30 21:51:26 +02:00
}
2022-09-23 04:15:43 +02:00
void SpeakerCorrection::SetSamplingRate(uint32_t samplingRate) {
2022-10-13 03:01:20 +02:00
if (this->samplingRate != samplingRate) {
this->samplingRate = samplingRate;
Reset();
}
2022-09-06 17:57:23 +02:00
}