This commit is contained in:
Iscle 2022-10-17 00:48:32 +02:00
parent 0648b3e759
commit 5b99913a8f
3 changed files with 112 additions and 92 deletions

View File

@ -54,7 +54,7 @@ ViPER::ViPER() {
this->playbackGain->Reset(); this->playbackGain->Reset();
this->fetCompressor = new FETCompressor(); this->fetCompressor = new FETCompressor();
this->fetCompressor->SetParameter(0, 0.0); this->fetCompressor->SetParameter(FETCompressor::ENABLE, 0.0);
this->fetCompressor->SetSamplingRate(this->samplingRate); this->fetCompressor->SetSamplingRate(this->samplingRate);
this->fetCompressor->Reset(); this->fetCompressor->Reset();
@ -473,7 +473,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u
break; break;
} // 0x1004A } // 0x1004A
case PARAM_FETCOMP_RATIO: { case PARAM_FETCOMP_RATIO: {
this->fetCompressor->SetParameter(1, (float) val1 / 100.0f); this->fetCompressor->SetParameter(FETCompressor::THRESHOLD, (float) val1 / 100.0f);
break; break;
} // 0x1004B } // 0x1004B
case PARAM_FETCOMP_KNEEWIDTH: { case PARAM_FETCOMP_KNEEWIDTH: {
@ -486,7 +486,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u
break; break;
} // 0x1004E } // 0x1004E
case PARAM_FETCOMP_AUTOGAIN_ENABLED: { case PARAM_FETCOMP_AUTOGAIN_ENABLED: {
this->fetCompressor->SetParameter(5, (float) val1 / 100.0f); this->fetCompressor->SetParameter(FETCompressor::GAIN, (float) val1 / 100.0f);
break; break;
} // 0x1004F } // 0x1004F
case PARAM_FETCOMP_ATTACK: { case PARAM_FETCOMP_ATTACK: {
@ -508,7 +508,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u
break; break;
} // 0x10055 } // 0x10055
case PARAM_FETCOMP_META_MAXRELEASE: { case PARAM_FETCOMP_META_MAXRELEASE: {
this->fetCompressor->SetParameter(12, (float) val1 / 100.0f); this->fetCompressor->SetParameter(FETCompressor::MAX_ATTACK, (float) val1 / 100.0f);
break; break;
} // 0x10056 } // 0x10056
case PARAM_FETCOMP_META_CREST: { case PARAM_FETCOMP_META_CREST: {
@ -518,7 +518,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u
break; break;
} // 0x10058 } // 0x10058
case PARAM_FETCOMP_META_NOCLIP_ENABLED: { case PARAM_FETCOMP_META_NOCLIP_ENABLED: {
this->fetCompressor->SetParameter(15, (float) val1 / 100.0f); this->fetCompressor->SetParameter(FETCompressor::ADAPT, (float) val1 / 100.0f);
break; break;
} // 0x10059 } // 0x10059
} }

View File

@ -30,7 +30,7 @@ FETCompressor::FETCompressor() {
this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE; this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE;
for (uint32_t i = 0; i < 17; i++) { for (uint32_t i = 0; i < 17; i++) {
SetParameter(i, GetParameterDefault(i)); SetParameter((FETCompressor::Parameter) i, GetParameterDefault((FETCompressor::Parameter) i));
} }
Reset(); Reset();
@ -41,7 +41,7 @@ float FETCompressor::GetMeter(int param_1) {
return 0.0; return 0.0;
} }
if (this->unk1) { if (this->enable) {
float tmp = (6.907755 - this->unk28) / 6.907755; float tmp = (6.907755 - this->unk28) / 6.907755;
if (tmp < 1.0) { if (tmp < 1.0) {
if (tmp < 0.0) { if (tmp < 0.0) {
@ -54,13 +54,13 @@ float FETCompressor::GetMeter(int param_1) {
return 1.0; return 1.0;
} }
float FETCompressor::GetParameter(uint32_t index) { float FETCompressor::GetParameter(FETCompressor::Parameter parameter) {
return this->parameters[index]; return this->parameters[parameter];
} }
float FETCompressor::GetParameterDefault(uint32_t index) { float FETCompressor::GetParameterDefault(FETCompressor::Parameter parameter) {
if (index < 17) { if (parameter < 17) {
return DEFAULT_FETCOMP_PARAMETERS[index]; return DEFAULT_FETCOMP_PARAMETERS[parameter];
} }
return 0.0; return 0.0;
} }
@ -80,13 +80,13 @@ void FETCompressor::Process(float *samples, uint32_t size) {
} }
double out = ProcessSidechain(in); double out = ProcessSidechain(in);
if (this->unk1) { if (this->enable) {
samples[i] *= (float) out; samples[i] *= (float) out;
samples[i + 1] *= (float) out; samples[i + 1] *= (float) out;
} }
this->unk23 = this->unk23 + (this->unk2 - this->unk23) * this->unk22; this->unk23 = this->unk23 + (this->threshold - this->unk23) * this->unk22;
this->unk24 = this->unk24 + this->unk22 * (this->unk6 - this->unk24); this->unk24 = this->unk24 + this->unk22 * (this->gain - this->unk24);
} }
} }
@ -96,10 +96,10 @@ double FETCompressor::ProcessSidechain(double in) {
in2 = 0.000001; in2 = 0.000001;
} }
float a = this->unk9; float a = this->attack2;
float b = this->unk25 + this->unk18 * (in2 - this->unk25); float b = this->unk25 + this->crest2 * (in2 - this->unk25);
float c = this->unk26 + this->unk18 * (in2 - this->unk26); float c = this->unk26 + this->crest2 * (in2 - this->unk26);
float d = this->unk8; float d = this->attack1;
if (in2 < b) { if (in2 < b) {
in2 = b; in2 = b;
@ -110,11 +110,11 @@ double FETCompressor::ProcessSidechain(double in) {
in2 /= c; in2 /= c;
if (this->unk10) { if (this->autoAttack) {
} }
if (this->unk13) { if (this->autoRelease) {
} }
@ -122,14 +122,14 @@ double FETCompressor::ProcessSidechain(double in) {
} }
if (!this->unk5) { if (!this->autoKnee) {
} else { } else {
} }
if (this->unk7) { if (this->autoGain) {
if (!this->unk21) { if (!this->noClip) {
} else { } else {
@ -143,8 +143,8 @@ double FETCompressor::ProcessSidechain(double in) {
void FETCompressor::Reset() { void FETCompressor::Reset() {
this->unk22 = calculate_exp_something(this->samplingRate, 0.05); this->unk22 = calculate_exp_something(this->samplingRate, 0.05);
this->unk23 = this->unk2; this->unk23 = this->threshold;
this->unk24 = this->unk6; this->unk24 = this->gain;
this->unk25 = 0.000001; this->unk25 = 0.000001;
this->unk26 = 0.000001; this->unk26 = 0.000001;
this->unk27 = 0.0; this->unk27 = 0.0;
@ -152,104 +152,104 @@ void FETCompressor::Reset() {
this->unk29 = 0.0; this->unk29 = 0.0;
} }
void FETCompressor::SetParameter(uint32_t index, float value) { void FETCompressor::SetParameter(FETCompressor::Parameter parameter, float value) {
this->parameters[index] = value; this->parameters[parameter] = value;
switch (index) { switch (parameter) {
case 0: { case ENABLE: {
this->unk1 = value >= 0.5; this->enable = value >= 0.5;
break; break;
} }
case 1: { case THRESHOLD: {
this->unk2 = log(pow(10.0, (value * -60.0) / 20.0)); this->threshold = log(pow(10.0, (value * -60.0) / 20.0));
break; break;
} }
case 2: { case RATIO: {
this->unk3 = -value; this->ratio = -value;
break; break;
} }
case 3: { case KNEE: {
this->unk4 = log(pow(10.0, (value * 60.0) / 20)); this->knee = log(pow(10.0, (value * 60.0) / 20));
break; break;
} }
case 4: { case AUTO_KNEE: {
this->unk5 = value >= 0.5; this->autoKnee = value >= 0.5;
break; break;
} }
case 5: { case GAIN: {
this->unk6 = log(pow(10.0, (value * 60.0) / 20.0)); this->gain = log(pow(10.0, (value * 60.0) / 20.0));
break; break;
} }
case 6: { case AUTO_GAIN: {
this->unk7 = value >= 0.5; this->autoGain = value >= 0.5;
break; break;
} }
case 7: { case ATTACK: {
double tmp = exp(value * 7.600903 - 9.21034); double tmp = exp(value * 7.600903 - 9.21034);
this->unk8 = tmp; this->attack1 = tmp;
if (tmp <= 0.0) { if (tmp <= 0.0) {
tmp = 1.0; tmp = 1.0;
} else { } else {
tmp = calculate_exp_something(this->samplingRate, tmp); tmp = calculate_exp_something(this->samplingRate, tmp);
} }
this->unk9 = tmp; this->attack2 = tmp;
break; break;
} }
case 8: { case AUTO_ATTACK: {
this->unk10 = value >= 0.5; this->autoAttack = value >= 0.5;
break; break;
} }
case 9: { case RELEASE: {
double tmp = exp(value * 5.991465 - 5.298317); double tmp = exp(value * 5.991465 - 5.298317);
this->unk11 = tmp; this->release1 = tmp;
if (tmp <= 0.0) { if (tmp <= 0.0) {
tmp = 1.0; tmp = 1.0;
} else { } else {
tmp = calculate_exp_something(this->samplingRate, tmp); tmp = calculate_exp_something(this->samplingRate, tmp);
} }
this->unk12 = tmp; this->release2 = tmp;
break; break;
} }
case 10: { case AUTO_RELEASE: {
this->unk13 = value >= 0.5; this->autoRelease = value >= 0.5;
break; break;
} }
case 11: { case KNEE_MULTI: {
this->unk14 = value * 4.0; this->kneeMulti = value * 4.0;
break; break;
} }
case 12: { case MAX_ATTACK: {
this->unk15 = exp(value * 7.600903 - 9.21034); this->maxAttack = exp(value * 7.600903 - 9.21034);
break; break;
} }
case 13: { case MAX_RELEASE: {
this->unk16 = exp(value * 5.991465 - 5.298317); this->maxRelease = exp(value * 5.991465 - 5.298317);
break; break;
} }
case 14: { case CREST: {
double tmp = exp(value * 5.991465 - 5.298317); double tmp = exp(value * 5.991465 - 5.298317);
this->unk17 = tmp; this->crest1 = tmp;
if (tmp <= 0.0) { if (tmp <= 0.0) {
tmp = 1.0; tmp = 1.0;
} else { } else {
tmp = calculate_exp_something(this->samplingRate, tmp); tmp = calculate_exp_something(this->samplingRate, tmp);
} }
this->unk18 = tmp; this->crest2 = tmp;
break; break;
} }
case 15: { case ADAPT: {
double tmp = exp(value * 1.386294); double tmp = exp(value * 1.386294);
this->unk19 = tmp; this->adapt1 = tmp;
if (tmp <= 0.0) { if (tmp <= 0.0) {
tmp = 1.0; tmp = 1.0;
} else { } else {
tmp = calculate_exp_something(this->samplingRate, tmp); tmp = calculate_exp_something(this->samplingRate, tmp);
} }
this->unk20 = tmp; this->adapt2 = tmp;
break; break;
} }
case 16: { case NO_CLIP: {
this->unk21 = value >= 0.5; this->noClip = value >= 0.5;
break; break;
} }
} }
@ -259,7 +259,7 @@ void FETCompressor::SetSamplingRate(uint32_t samplingRate) {
this->samplingRate = samplingRate; this->samplingRate = samplingRate;
for (uint32_t i = 0; i < 17; i++) { for (uint32_t i = 0; i < 17; i++) {
SetParameter(i, GetParameter(i)); SetParameter((FETCompressor::Parameter) i, GetParameter((FETCompressor::Parameter) i));
} }
Reset(); Reset();

View File

@ -4,49 +4,69 @@
class FETCompressor { class FETCompressor {
public: public:
enum Parameter {
ENABLE = 0,
THRESHOLD,
RATIO,
KNEE,
AUTO_KNEE,
GAIN,
AUTO_GAIN,
ATTACK,
AUTO_ATTACK,
RELEASE,
AUTO_RELEASE,
KNEE_MULTI,
MAX_ATTACK,
MAX_RELEASE,
CREST,
ADAPT,
NO_CLIP
};
FETCompressor(); FETCompressor();
float GetMeter(int param_1); float GetMeter(int param_1);
float GetParameter(uint32_t index); float GetParameter(FETCompressor::Parameter parameter);
float GetParameterDefault(uint32_t index); float GetParameterDefault(FETCompressor::Parameter parameter);
void Process(float *samples, uint32_t size); void Process(float *samples, uint32_t size);
double ProcessSidechain(double in); double ProcessSidechain(double in);
void Reset(); void Reset();
void SetParameter(uint32_t index, float value); void SetParameter(FETCompressor::Parameter parameter, float value);
void SetSamplingRate(uint32_t samplingRate); void SetSamplingRate(uint32_t samplingRate);
private: private:
uint32_t samplingRate; uint32_t samplingRate;
float parameters[17]; float parameters[17];
float unk22; float unk22;
bool unk1; bool enable;
bool unk5; bool autoKnee;
bool unk7; bool autoGain;
bool unk10; bool autoAttack;
bool unk13; bool autoRelease;
float unk27; float unk27;
float unk28; float unk28;
float unk29; float unk29;
float unk23; float unk23;
float unk2; float threshold;
float unk4; float knee;
float unk24; float unk24;
float unk6; float gain;
float unk3; float ratio;
float unk25; float unk25;
float unk26; float unk26;
float unk8; float attack1;
float unk9; float attack2;
float unk11; float release1;
float unk12; float release2;
float unk14; float kneeMulti;
float unk15; float maxAttack;
float unk16; float maxRelease;
float unk17; float crest1;
float unk18; float crest2;
float unk19; float adapt1;
float unk20; float adapt2;
float unk21; float noClip;
}; };