mirror of
https://github.com/AndroidAudioMods/ViPERFX_RE.git
synced 2024-12-22 22:47:25 +08:00
MultiBiquad
This commit is contained in:
parent
bbcdf238a9
commit
c5534cf59f
@ -4,7 +4,8 @@ project("ViPER4Android Reworked")
|
||||
|
||||
set(CMAKE_CXX_COMPILER_VERSION 20)
|
||||
|
||||
include_directories("include/")
|
||||
include_directories(include/)
|
||||
message(${ANDROID_NDK}/include/)
|
||||
|
||||
set(FILES
|
||||
# Main
|
||||
|
@ -11,17 +11,52 @@ Cure::Cure() {
|
||||
|
||||
void Cure::Process(float *buffer, uint32_t size) {
|
||||
if (this->enabled) {
|
||||
Crossfeed::ProcessFrames(buffer, size);
|
||||
this->crossfeed.ProcessFrames(buffer, size);
|
||||
this->pass.ProcessFrames(buffer, size);
|
||||
}
|
||||
}
|
||||
|
||||
void Cure::Reset() {
|
||||
Crossfeed::Reset();
|
||||
this->crossfeed.Reset();
|
||||
this->pass.Reset();
|
||||
}
|
||||
|
||||
void Cure::SetEnable(bool enabled) {
|
||||
Reset();
|
||||
this->enabled = enabled;
|
||||
}
|
||||
|
||||
void Cure::SetSamplingRate(uint32_t samplerate) {
|
||||
Crossfeed::SetSamplingRate(samplerate);
|
||||
this->crossfeed.SetSamplingRate(samplerate);
|
||||
this->pass.SetSamplingRate(samplerate);
|
||||
}
|
||||
|
||||
uint16_t Cure::GetCutoff() {
|
||||
return this->crossfeed.GetCutoff();
|
||||
}
|
||||
|
||||
float Cure::GetFeedback() {
|
||||
return this->crossfeed.GetFeedback();
|
||||
}
|
||||
|
||||
float Cure::GetLevelDelay() {
|
||||
return this->crossfeed.GetLevelDelay();
|
||||
}
|
||||
|
||||
preset_t Cure::GetPreset() {
|
||||
return this->crossfeed.GetPreset();
|
||||
}
|
||||
|
||||
void Cure::SetCutoff(uint16_t cutoff) {
|
||||
this->crossfeed.SetCutoff(cutoff);
|
||||
|
||||
}
|
||||
|
||||
void Cure::SetFeedback(float feedback) {
|
||||
this->crossfeed.SetFeedback(feedback);
|
||||
}
|
||||
|
||||
void Cure::SetPreset(preset_t preset) {
|
||||
this->crossfeed.SetPreset(preset);
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,24 @@
|
||||
#include "../utils/Crossfeed.h"
|
||||
#include "../utils/PassFilter.h"
|
||||
|
||||
class Cure : public Crossfeed {
|
||||
class Cure {
|
||||
public:
|
||||
Cure();
|
||||
|
||||
void Process(float* buffer, uint32_t size);
|
||||
void Reset();
|
||||
void SetEnable(bool enabled);
|
||||
|
||||
uint16_t GetCutoff();
|
||||
float GetFeedback();
|
||||
float GetLevelDelay();
|
||||
preset_t GetPreset();
|
||||
void SetCutoff(uint16_t cutoff);
|
||||
void SetFeedback(float feedback);
|
||||
void SetPreset(preset_t preset);
|
||||
void SetSamplingRate(uint32_t samplerate);
|
||||
|
||||
Crossfeed crossfeed;
|
||||
PassFilter pass;
|
||||
bool enabled;
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ CAllpassFilter::CAllpassFilter() {
|
||||
}
|
||||
|
||||
void CAllpassFilter::Mute() {
|
||||
memset(this->buffer, 0, this->bufsize * sizeof(float))
|
||||
memset(this->buffer, 0, this->bufsize * sizeof(float));
|
||||
}
|
||||
|
||||
float CAllpassFilter::Process(float sample) {
|
||||
|
@ -50,7 +50,7 @@ void Crossfeed::Reset() {
|
||||
|
||||
void Crossfeed::ProcessFrames(float* buffer, uint32_t size) {
|
||||
for (int x = 0; x < size; x+=2) {
|
||||
FilterSample(&buffer[x])
|
||||
FilterSample(&buffer[x]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ void FixedBiquad::SetHighPassParameter(float frequency, uint32_t samplerate, flo
|
||||
fVar9 + fVar9,
|
||||
fVar11 - (fVar7 + fVar7) * fVar6,
|
||||
(fVar12 + (fVar7 + fVar7) * fVar6) * x * fVar2,
|
||||
x * -2.0 * (fVar8 + fVar10 * fVar5) * fVar2,
|
||||
x * -2.f * (fVar8 + fVar10 * fVar5) * fVar2,
|
||||
(fVar12 - (fVar7 + fVar7) * fVar6) * x * fVar2);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ IIR_1st::IIR_1st() {
|
||||
this->b0 = 0.f;
|
||||
this->b1 = 0.f;
|
||||
this->a1 = 0.f;
|
||||
Mute()
|
||||
Mute();
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Created by mart on 7/27/21.
|
||||
//
|
||||
|
||||
#include <cmath>
|
||||
#include "MultiBiquad.h"
|
||||
|
||||
MultiBiquad::MultiBiquad() {
|
||||
@ -26,7 +27,123 @@ float MultiBiquad::ProcessSample(float sample) {
|
||||
}
|
||||
|
||||
void MultiBiquad::RefreshFilter(FilterType type, float gainAmp, float freq, float samplerate, float qFactor, bool param_7) {
|
||||
// TODO
|
||||
bool uVar1;
|
||||
int iVar2;
|
||||
int iVar3;
|
||||
double dVar4;
|
||||
double dVar5;
|
||||
double dVar6;
|
||||
double dVar7;
|
||||
double dVar8;
|
||||
double dVar9;
|
||||
double dVar10;
|
||||
double dVar11;
|
||||
double a0;
|
||||
double a1;
|
||||
double a2;
|
||||
double b0;
|
||||
double b1;
|
||||
double b2;
|
||||
|
||||
dVar10 = pow(10.0,gainAmp / 40.0);
|
||||
dVar4 = (freq * 2*M_PI) / samplerate;
|
||||
dVar5 = sin(dVar4);
|
||||
dVar11 = cos(dVar4);
|
||||
uVar1 = type == HIGHSHELF;
|
||||
dVar4 = (1.0 / dVar10 + dVar10) * (1.0 / qFactor - 1.0) + 2.0;
|
||||
dVar6 = sqrt(dVar4);
|
||||
if (!(bool)uVar1) {
|
||||
dVar4 = sinh(dVar4);
|
||||
dVar6 = dVar4;
|
||||
}
|
||||
dVar4 = sqrt(dVar10);
|
||||
dVar5 = dVar5 * 0.5 * dVar6;
|
||||
if (!(bool)uVar1) {
|
||||
dVar4 = sinh(dVar10);
|
||||
}
|
||||
dVar4 = (dVar4 + dVar4) * dVar5;
|
||||
switch(type) {
|
||||
case LOWPASS:
|
||||
b1 = 1.0 - dVar11;
|
||||
dVar10 = b1;
|
||||
b0 = dVar10 * 0.5;
|
||||
a0 = dVar5 + 1.0;
|
||||
a1 = dVar11 * -2.0;
|
||||
a2 = 1.0 - dVar5;
|
||||
b2 = b0;
|
||||
break;
|
||||
case HIGHPASS:
|
||||
b1 = 0.0 - (dVar11 + 1.0);
|
||||
dVar10 = dVar11 + 1.0;
|
||||
b0 = dVar10 * 0.5;
|
||||
a0 = dVar5 + 1.0;
|
||||
a1 = dVar11 * -2.0;
|
||||
a2 = 1.0 - dVar5;
|
||||
b2 = b0;
|
||||
break;
|
||||
case BANDPASS:
|
||||
a1 = dVar11 * -2.0;
|
||||
a2 = 1.0 - dVar5;
|
||||
a0 = dVar5 + 1.0;
|
||||
b1 = 0.0;
|
||||
b0 = dVar5;
|
||||
b2 = 0.0 - dVar5;
|
||||
break;
|
||||
case BANDSTOP:
|
||||
b1 = dVar11 * -2.0;
|
||||
a2 = 1.0 - dVar5;
|
||||
a0 = dVar5 + 1.0;
|
||||
b0 = 1.0;
|
||||
b2 = 1.0;
|
||||
a1 = b1;
|
||||
break;
|
||||
case ALLPASS:
|
||||
b1 = dVar11 * -2.0;
|
||||
a2 = 1.0 - dVar5;
|
||||
a0 = dVar5 + 1.0;
|
||||
b0 = a2;
|
||||
b2 = a0;
|
||||
a1 = b1;
|
||||
break;
|
||||
case PEAK:
|
||||
b1 = dVar11 * -2.0;
|
||||
a2 = 1.0 - dVar5 / dVar10;
|
||||
a0 = dVar5 / dVar10 + 1.0;
|
||||
b0 = dVar5 * dVar10 + 1.0;
|
||||
b2 = 1.0 - dVar5 * dVar10;
|
||||
a1 = b1;
|
||||
break;
|
||||
case LOWSHELF:
|
||||
dVar6 = dVar10 - 1.0;
|
||||
dVar7 = dVar10 + 1.0;
|
||||
dVar5 = dVar7 - dVar6 * dVar11;
|
||||
dVar8 = dVar7 + dVar6 * dVar11;
|
||||
a0 = dVar8 + dVar4;
|
||||
b1 = (dVar10 + dVar10) * (dVar6 - dVar11 * dVar7);
|
||||
a2 = dVar8 - dVar4;
|
||||
a1 = (dVar6 + dVar11 * dVar7) * -2.0;
|
||||
b0 = (dVar5 + dVar4) * dVar10;
|
||||
b2 = (dVar5 - dVar4) * dVar10;
|
||||
break;
|
||||
case HIGHSHELF:
|
||||
dVar6 = dVar10 - 1.0;
|
||||
dVar8 = dVar10 + 1.0;
|
||||
dVar5 = dVar8 + dVar6 * dVar11;
|
||||
dVar9 = dVar8 - dVar6 * dVar11;
|
||||
dVar7 = dVar6 - dVar11 * dVar8;
|
||||
a0 = dVar9 + dVar4;
|
||||
b1 = dVar10 * -2.0 * (dVar6 + dVar11 * dVar8);
|
||||
a2 = dVar9 - dVar4;
|
||||
a1 = dVar7 + dVar7;
|
||||
b0 = (dVar5 + dVar4) * dVar10;
|
||||
b2 = (dVar5 - dVar4) * dVar10;
|
||||
}
|
||||
|
||||
this->a1 = a1 / a0;
|
||||
this->a2 = a2 / a0;
|
||||
this->b0 = b0 / a0;
|
||||
this->b1 = b1 / a0;
|
||||
this->b2 = b2 / a0;
|
||||
|
||||
this->y_2 = 0.f;
|
||||
this->y_1 = 0.f;
|
||||
|
@ -6,7 +6,14 @@
|
||||
|
||||
|
||||
enum FilterType {
|
||||
|
||||
LOWPASS,
|
||||
HIGHPASS,
|
||||
BANDPASS,
|
||||
BANDSTOP,
|
||||
ALLPASS,
|
||||
PEAK,
|
||||
LOWSHELF,
|
||||
HIGHSHELF
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user