From 5b99913a8f8743d5987faa042304d3dc0a60f243 Mon Sep 17 00:00:00 2001 From: Iscle Date: Mon, 17 Oct 2022 00:48:32 +0200 Subject: [PATCH] Update --- src/cpp/viper/ViPER.cpp | 10 +- src/cpp/viper/effects/FETCompressor.cpp | 126 ++++++++++++------------ src/cpp/viper/effects/FETCompressor.h | 68 ++++++++----- 3 files changed, 112 insertions(+), 92 deletions(-) diff --git a/src/cpp/viper/ViPER.cpp b/src/cpp/viper/ViPER.cpp index dfb7308..07bf5a7 100644 --- a/src/cpp/viper/ViPER.cpp +++ b/src/cpp/viper/ViPER.cpp @@ -54,7 +54,7 @@ ViPER::ViPER() { this->playbackGain->Reset(); this->fetCompressor = new FETCompressor(); - this->fetCompressor->SetParameter(0, 0.0); + this->fetCompressor->SetParameter(FETCompressor::ENABLE, 0.0); this->fetCompressor->SetSamplingRate(this->samplingRate); this->fetCompressor->Reset(); @@ -473,7 +473,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u break; } // 0x1004A case PARAM_FETCOMP_RATIO: { - this->fetCompressor->SetParameter(1, (float) val1 / 100.0f); + this->fetCompressor->SetParameter(FETCompressor::THRESHOLD, (float) val1 / 100.0f); break; } // 0x1004B case PARAM_FETCOMP_KNEEWIDTH: { @@ -486,7 +486,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u break; } // 0x1004E case PARAM_FETCOMP_AUTOGAIN_ENABLED: { - this->fetCompressor->SetParameter(5, (float) val1 / 100.0f); + this->fetCompressor->SetParameter(FETCompressor::GAIN, (float) val1 / 100.0f); break; } // 0x1004F case PARAM_FETCOMP_ATTACK: { @@ -508,7 +508,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u break; } // 0x10055 case PARAM_FETCOMP_META_MAXRELEASE: { - this->fetCompressor->SetParameter(12, (float) val1 / 100.0f); + this->fetCompressor->SetParameter(FETCompressor::MAX_ATTACK, (float) val1 / 100.0f); break; } // 0x10056 case PARAM_FETCOMP_META_CREST: { @@ -518,7 +518,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u break; } // 0x10058 case PARAM_FETCOMP_META_NOCLIP_ENABLED: { - this->fetCompressor->SetParameter(15, (float) val1 / 100.0f); + this->fetCompressor->SetParameter(FETCompressor::ADAPT, (float) val1 / 100.0f); break; } // 0x10059 } diff --git a/src/cpp/viper/effects/FETCompressor.cpp b/src/cpp/viper/effects/FETCompressor.cpp index bea42ea..d2d70e7 100644 --- a/src/cpp/viper/effects/FETCompressor.cpp +++ b/src/cpp/viper/effects/FETCompressor.cpp @@ -30,7 +30,7 @@ FETCompressor::FETCompressor() { this->samplingRate = VIPER_DEFAULT_SAMPLING_RATE; for (uint32_t i = 0; i < 17; i++) { - SetParameter(i, GetParameterDefault(i)); + SetParameter((FETCompressor::Parameter) i, GetParameterDefault((FETCompressor::Parameter) i)); } Reset(); @@ -41,7 +41,7 @@ float FETCompressor::GetMeter(int param_1) { return 0.0; } - if (this->unk1) { + if (this->enable) { float tmp = (6.907755 - this->unk28) / 6.907755; if (tmp < 1.0) { if (tmp < 0.0) { @@ -54,13 +54,13 @@ float FETCompressor::GetMeter(int param_1) { return 1.0; } -float FETCompressor::GetParameter(uint32_t index) { - return this->parameters[index]; +float FETCompressor::GetParameter(FETCompressor::Parameter parameter) { + return this->parameters[parameter]; } -float FETCompressor::GetParameterDefault(uint32_t index) { - if (index < 17) { - return DEFAULT_FETCOMP_PARAMETERS[index]; +float FETCompressor::GetParameterDefault(FETCompressor::Parameter parameter) { + if (parameter < 17) { + return DEFAULT_FETCOMP_PARAMETERS[parameter]; } return 0.0; } @@ -80,13 +80,13 @@ void FETCompressor::Process(float *samples, uint32_t size) { } double out = ProcessSidechain(in); - if (this->unk1) { + if (this->enable) { 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); + this->unk23 = this->unk23 + (this->threshold - this->unk23) * this->unk22; + this->unk24 = this->unk24 + this->unk22 * (this->gain - this->unk24); } } @@ -96,10 +96,10 @@ double FETCompressor::ProcessSidechain(double in) { 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; + float a = this->attack2; + float b = this->unk25 + this->crest2 * (in2 - this->unk25); + float c = this->unk26 + this->crest2 * (in2 - this->unk26); + float d = this->attack1; if (in2 < b) { in2 = b; @@ -110,11 +110,11 @@ double FETCompressor::ProcessSidechain(double in) { 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 { } - if (this->unk7) { - if (!this->unk21) { + if (this->autoGain) { + if (!this->noClip) { } else { @@ -143,8 +143,8 @@ double FETCompressor::ProcessSidechain(double in) { void FETCompressor::Reset() { this->unk22 = calculate_exp_something(this->samplingRate, 0.05); - this->unk23 = this->unk2; - this->unk24 = this->unk6; + this->unk23 = this->threshold; + this->unk24 = this->gain; this->unk25 = 0.000001; this->unk26 = 0.000001; this->unk27 = 0.0; @@ -152,104 +152,104 @@ void FETCompressor::Reset() { this->unk29 = 0.0; } -void FETCompressor::SetParameter(uint32_t index, float value) { - this->parameters[index] = value; +void FETCompressor::SetParameter(FETCompressor::Parameter parameter, float value) { + this->parameters[parameter] = value; - switch (index) { - case 0: { - this->unk1 = value >= 0.5; + switch (parameter) { + case ENABLE: { + this->enable = value >= 0.5; break; } - case 1: { - this->unk2 = log(pow(10.0, (value * -60.0) / 20.0)); + case THRESHOLD: { + this->threshold = log(pow(10.0, (value * -60.0) / 20.0)); break; } - case 2: { - this->unk3 = -value; + case RATIO: { + this->ratio = -value; break; } - case 3: { - this->unk4 = log(pow(10.0, (value * 60.0) / 20)); + case KNEE: { + this->knee = log(pow(10.0, (value * 60.0) / 20)); break; } - case 4: { - this->unk5 = value >= 0.5; + case AUTO_KNEE: { + this->autoKnee = value >= 0.5; break; } - case 5: { - this->unk6 = log(pow(10.0, (value * 60.0) / 20.0)); + case GAIN: { + this->gain = log(pow(10.0, (value * 60.0) / 20.0)); break; } - case 6: { - this->unk7 = value >= 0.5; + case AUTO_GAIN: { + this->autoGain = value >= 0.5; break; } - case 7: { + case ATTACK: { double tmp = exp(value * 7.600903 - 9.21034); - this->unk8 = tmp; + this->attack1 = tmp; if (tmp <= 0.0) { tmp = 1.0; } else { tmp = calculate_exp_something(this->samplingRate, tmp); } - this->unk9 = tmp; + this->attack2 = tmp; break; } - case 8: { - this->unk10 = value >= 0.5; + case AUTO_ATTACK: { + this->autoAttack = value >= 0.5; break; } - case 9: { + case RELEASE: { double tmp = exp(value * 5.991465 - 5.298317); - this->unk11 = tmp; + this->release1 = tmp; if (tmp <= 0.0) { tmp = 1.0; } else { tmp = calculate_exp_something(this->samplingRate, tmp); } - this->unk12 = tmp; + this->release2 = tmp; break; } - case 10: { - this->unk13 = value >= 0.5; + case AUTO_RELEASE: { + this->autoRelease = value >= 0.5; break; } - case 11: { - this->unk14 = value * 4.0; + case KNEE_MULTI: { + this->kneeMulti = value * 4.0; break; } - case 12: { - this->unk15 = exp(value * 7.600903 - 9.21034); + case MAX_ATTACK: { + this->maxAttack = exp(value * 7.600903 - 9.21034); break; } - case 13: { - this->unk16 = exp(value * 5.991465 - 5.298317); + case MAX_RELEASE: { + this->maxRelease = exp(value * 5.991465 - 5.298317); break; } - case 14: { + case CREST: { double tmp = exp(value * 5.991465 - 5.298317); - this->unk17 = tmp; + this->crest1 = tmp; if (tmp <= 0.0) { tmp = 1.0; } else { tmp = calculate_exp_something(this->samplingRate, tmp); } - this->unk18 = tmp; + this->crest2 = tmp; break; } - case 15: { + case ADAPT: { double tmp = exp(value * 1.386294); - this->unk19 = tmp; + this->adapt1 = tmp; if (tmp <= 0.0) { tmp = 1.0; } else { tmp = calculate_exp_something(this->samplingRate, tmp); } - this->unk20 = tmp; + this->adapt2 = tmp; break; } - case 16: { - this->unk21 = value >= 0.5; + case NO_CLIP: { + this->noClip = value >= 0.5; break; } } @@ -259,7 +259,7 @@ void FETCompressor::SetSamplingRate(uint32_t samplingRate) { this->samplingRate = samplingRate; for (uint32_t i = 0; i < 17; i++) { - SetParameter(i, GetParameter(i)); + SetParameter((FETCompressor::Parameter) i, GetParameter((FETCompressor::Parameter) i)); } Reset(); diff --git a/src/cpp/viper/effects/FETCompressor.h b/src/cpp/viper/effects/FETCompressor.h index 4628157..197a377 100644 --- a/src/cpp/viper/effects/FETCompressor.h +++ b/src/cpp/viper/effects/FETCompressor.h @@ -4,49 +4,69 @@ class FETCompressor { 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(); float GetMeter(int param_1); - float GetParameter(uint32_t index); - float GetParameterDefault(uint32_t index); + float GetParameter(FETCompressor::Parameter parameter); + float GetParameterDefault(FETCompressor::Parameter parameter); void Process(float *samples, uint32_t size); double ProcessSidechain(double in); void Reset(); - void SetParameter(uint32_t index, float value); + void SetParameter(FETCompressor::Parameter parameter, 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; + bool enable; + bool autoKnee; + bool autoGain; + bool autoAttack; + bool autoRelease; float unk27; float unk28; float unk29; float unk23; - float unk2; - float unk4; + float threshold; + float knee; float unk24; - float unk6; - float unk3; + float gain; + float ratio; 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; + float attack1; + float attack2; + float release1; + float release2; + float kneeMulti; + float maxAttack; + float maxRelease; + float crest1; + float crest2; + float adapt1; + float adapt2; + float noClip; };