mirror of
https://github.com/AndroidAudioMods/ViPERFX_RE.git
synced 2025-06-08 10:39:29 +08:00
Implement HighShelf
This commit is contained in:
parent
a0034f3acc
commit
83563168ea
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
class Biquad {
|
class Biquad {
|
||||||
@ -15,6 +14,13 @@ public:
|
|||||||
void SetLowPassParameter(double frequency, double samplingRate, double qFactor);
|
void SetLowPassParameter(double frequency, double samplingRate, double qFactor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double y_2, y_1, x_2, x_1;
|
double x_1;
|
||||||
double b0, b1, b2, a1, a2;
|
double x_2;
|
||||||
|
double y_1;
|
||||||
|
double y_2;
|
||||||
|
double a1;
|
||||||
|
double a2;
|
||||||
|
double b0;
|
||||||
|
double b1;
|
||||||
|
double b2;
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
#include <cmath>
|
|
||||||
#include "HighShelf.h"
|
#include "HighShelf.h"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
float HighShelf::Process(float sample) {
|
double HighShelf::Process(double sample) {
|
||||||
float out = sample * this->b0 + this->x_1 * this->b1 + this->x_2 * this->b2 + this->y_1 * this->a1 +
|
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;
|
||||||
this->y_2 * this->a2;
|
|
||||||
this->y_2 = this->y_1;
|
this->y_2 = this->y_1;
|
||||||
this->y_1 = out;
|
this->y_1 = out;
|
||||||
this->x_2 = this->x_1;
|
this->x_2 = this->x_1;
|
||||||
@ -11,18 +10,37 @@ float HighShelf::Process(float sample) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HighShelf::SetFrequency(uint32_t freq) {
|
void HighShelf::SetFrequency(double freq) {
|
||||||
this->frequency = freq;
|
this->frequency = freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HighShelf::SetGain(float gain) {
|
void HighShelf::SetGain(double gain) {
|
||||||
this->gain = 20.f * log10f(gain);
|
this->gain = log10(gain) * 20.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HighShelf::SetQuality(float q) {
|
void HighShelf::SetSamplingRate(double samplingRate) {
|
||||||
this->quality = q;
|
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);
|
||||||
|
|
||||||
void HighShelf::SetSamplingRate(uint32_t samplerate) {
|
this->x_1 = 0.0;
|
||||||
this->samplerate = samplerate;
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
@ -4,21 +4,24 @@
|
|||||||
|
|
||||||
class HighShelf {
|
class HighShelf {
|
||||||
public:
|
public:
|
||||||
float Process(float sample);
|
double Process(double sample);
|
||||||
|
void SetFrequency(double freq);
|
||||||
|
void SetGain(double gain);
|
||||||
|
void SetSamplingRate(double samplingRate);
|
||||||
|
|
||||||
void SetFrequency(uint32_t freq);
|
private:
|
||||||
|
double frequency;
|
||||||
void SetGain(float gain);
|
double gain;
|
||||||
|
double x_1;
|
||||||
void SetQuality(float q);
|
double x_2;
|
||||||
|
double y_1;
|
||||||
void SetSamplingRate(uint32_t samplerate);
|
double y_2;
|
||||||
|
double b0;
|
||||||
uint32_t frequency, samplerate;
|
double b1;
|
||||||
float quality, gain;
|
double b2;
|
||||||
|
double a0;
|
||||||
float y_2, y_1, x_2, x_1;
|
double a1;
|
||||||
float b0, b1, b2, a1, a2;
|
double a2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user