This commit is contained in:
Iscle 2022-10-16 16:54:32 +02:00
parent 5c4092e8e4
commit e1b1df1901
6 changed files with 287 additions and 38 deletions

View File

@ -2,7 +2,7 @@
#include <cstring>
#include "../constants.h"
static float ANALOGX_HARMONICS[] = {
static const float ANALOGX_HARMONICS[] = {
0.01,
0.02,
0.0001,

View File

@ -1,41 +1,258 @@
#include <cmath>
#include "FETCompressor.h"
#include "../constants.h"
static const float DEFAULT_FETCOMP_PARAMETERS[] = {
1.000000,
0.000000,
0.000000,
0.000000,
1.000000,
0.000000,
1.000000,
0.514679,
1.000000,
0.384311,
1.000000,
0.500000,
0.879450,
0.884311,
0.615689,
0.660964,
1.000000
};
static double calculate_exp_something(double param_1, double param_2) {
return 1.0 - exp(-1.0 / (param_2 * param_1));
}
FETCompressor::FETCompressor() {
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
for (uint32_t i = 0; i < 17; i++) {
SetParameter(i, GetParameterDefault(i));
}
Reset();
}
FETCompressor::~FETCompressor() {
float FETCompressor::GetMeter(int param_1) {
if (param_1 != 0) {
return 0.0;
}
// TODO: Implement
return 1.0;
}
void FETCompressor::GetMeter() {
float FETCompressor::GetParameter(uint32_t index) {
return this->parameters[index];
}
void FETCompressor::GetParameter() {
}
void FETCompressor::GetParameterDefault() {
}
void FETCompressor::ProcessSidechain() {
}
void FETCompressor::Reset() {
}
void FETCompressor::SetParameter(int32_t param_1, float param_2) {
}
void FETCompressor::SetSamplingRate(uint32_t samplingRate) {
float FETCompressor::GetParameterDefault(uint32_t index) {
if (index < 17) {
return DEFAULT_FETCOMP_PARAMETERS[index];
}
return 0.0;
}
void FETCompressor::Process(float *samples, uint32_t size) {
if (size == 0) return;
for (uint32_t i = 0; i < size * 2; i += 2) {
double inL = abs(samples[i]);
double inR = abs(samples[i + 1]);
double in;
if (inL > inR) {
in = inL;
} else {
in = inR;
}
double out = ProcessSidechain(in);
if (this->unk1) {
samples[i] *= (float) out;
samples[i + 1] *= (float) out;
}
this->unk23 = this->unk23 + (this->unk2 - this->unk23) * this->unk22;
this->unk24 = this->unk24 + this->unk22 * (this->unk6 - this->unk24);
}
}
double FETCompressor::ProcessSidechain(double in) {
double in2 = pow(in, 2.0);
if (in2 < 0.000001) {
in2 = 0.000001;
}
float a = this->unk9;
float b = this->unk25 + this->unk18 * (in2 - this->unk25);
float c = this->unk26 + this->unk18 * (in2 - this->unk26);
float d = this->unk8;
if (in2 < b) {
in2 = b;
}
this->unk26 = c;
this->unk25 = in2;
in2 /= c;
if (this->unk10) {
}
if (this->unk13) {
}
if (in >= 0.000001) {
}
if (!this->unk5) {
} else {
}
if (this->unk7) {
if (!this->unk21) {
} else {
}
// return exp(-a - fVar6); // FIXME: Change "a" and "fVar6" variable
}
return exp(this->unk24 - a); // FIXME: Change "a" variable
}
void FETCompressor::Reset() {
this->unk22 = calculate_exp_something(this->samplingRate, 0.05);
this->unk23 = this->unk2;
this->unk24 = this->unk6;
this->unk25 = 0.000001;
this->unk26 = 0.000001;
this->unk27 = 0.0;
this->unk28 = 0.0;
this->unk29 = 0.0;
}
void FETCompressor::SetParameter(uint32_t index, float value) {
this->parameters[index] = value;
switch (index) {
case 0: {
this->unk1 = value >= 0.5;
break;
}
case 1: {
this->unk2 = log(pow(10.0, (value * -60.0) / 20.0));
break;
}
case 2: {
this->unk3 = -value;
break;
}
case 3: {
this->unk4 = log(pow(10.0, (value * 60.0) / 20));
break;
}
case 4: {
this->unk5 = value >= 0.5;
break;
}
case 5: {
this->unk6 = log(pow(10.0, (value * 60.0) / 20.0));
break;
}
case 6: {
this->unk7 = value >= 0.5;
break;
}
case 7: {
double tmp = exp(value * 7.600903 - 9.21034);
this->unk8 = tmp;
if (tmp <= 0.0) {
tmp = 1.0;
} else {
tmp = calculate_exp_something(this->samplingRate, tmp);
}
this->unk9 = tmp;
break;
}
case 8: {
this->unk10 = value >= 0.5;
break;
}
case 9: {
double tmp = exp(value * 5.991465 - 5.298317);
this->unk11 = tmp;
if (tmp <= 0.0) {
tmp = 1.0;
} else {
tmp = calculate_exp_something(this->samplingRate, tmp);
}
this->unk12 = tmp;
break;
}
case 10: {
this->unk13 = value >= 0.5;
break;
}
case 11: {
this->unk14 = value * 4.0;
break;
}
case 12: {
this->unk15 = exp(value * 7.600903 - 9.21034);
break;
}
case 13: {
this->unk16 = exp(value * 5.991465 - 5.298317);
break;
}
case 14: {
double tmp = exp(value * 5.991465 - 5.298317);
this->unk17 = tmp;
if (tmp <= 0.0) {
tmp = 1.0;
} else {
tmp = calculate_exp_something(this->samplingRate, tmp);
}
this->unk18 = tmp;
break;
}
case 15: {
double tmp = exp(value * 1.386294);
this->unk19 = tmp;
if (tmp <= 0.0) {
tmp = 1.0;
} else {
tmp = calculate_exp_something(this->samplingRate, tmp);
}
this->unk20 = tmp;
break;
}
case 16: {
this->unk21 = value >= 0.5;
break;
}
}
}
void FETCompressor::SetSamplingRate(uint32_t samplingRate) {
this->samplingRate = samplingRate;
for (uint32_t i = 0; i < 17; i++) {
SetParameter(i, GetParameter(i));
}
Reset();
}

View File

@ -5,16 +5,48 @@
class FETCompressor {
public:
FETCompressor();
~FETCompressor();
void GetMeter();
void GetParameter();
void GetParameterDefault();
float GetMeter(int param_1);
float GetParameter(uint32_t index);
float GetParameterDefault(uint32_t index);
void Process(float *samples, uint32_t size);
void ProcessSidechain();
double ProcessSidechain(double in);
void Reset();
void SetParameter(int32_t param_1, float param_2);
void SetParameter(uint32_t index, float value);
void SetSamplingRate(uint32_t samplingRate);
private:
uint32_t samplingRate;
float parameters[17];
float unk22;
bool unk1;
bool unk5;
bool unk7;
bool unk10;
bool unk13;
float unk27;
float unk28;
float unk29;
float unk23;
float unk2;
float unk4;
float unk24;
float unk6;
float unk3;
float unk25;
float unk26;
float unk8;
float unk9;
float unk11;
float unk12;
float unk14;
float unk15;
float unk16;
float unk17;
float unk18;
float unk19;
float unk20;
float unk21;
};

View File

@ -1,7 +1,7 @@
#include "SpectrumExtend.h"
#include "../constants.h"
static float SPECTRUM_HARMONICS[10] = {
static const float SPECTRUM_HARMONICS[10] = {
0.02f,
0.f,
0.02f,

View File

@ -2,7 +2,7 @@
#include <cmath>
#include "Harmonic.h"
static float HARMONIC_DEFAULT[] = {
static const float HARMONIC_DEFAULT[] = {
1.0,
0.0,
0.0,
@ -52,12 +52,12 @@ void Harmonic::Reset() {
this->prevOut = 0.0;
}
void Harmonic::SetHarmonics(float *coefficients) {
void Harmonic::SetHarmonics(const float *coefficients) {
UpdateCoeffs(coefficients);
Reset();
}
void Harmonic::UpdateCoeffs(float *coefficients) {
void Harmonic::UpdateCoeffs(const float *coefficients) {
float unkarr1[11];
float unkarr2[11];

View File

@ -8,8 +8,8 @@ public:
double Process(double sample);
void Reset();
void SetHarmonics(float *coeffs);
void UpdateCoeffs(float *coeffs);
void SetHarmonics(const float *coeffs);
void UpdateCoeffs(const float *coeffs);
private:
float coeffs[11];