From 202e8dee6ea0762186fc17cf3f512adbead0266f Mon Sep 17 00:00:00 2001 From: Phil Schatzmann Date: Mon, 23 Oct 2023 00:22:41 +0200 Subject: [PATCH] Compressor cleanup --- src/AudioEffects/AudioEffect.h | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/AudioEffects/AudioEffect.h b/src/AudioEffects/AudioEffect.h index da778df104..e953f36eb4 100644 --- a/src/AudioEffects/AudioEffect.h +++ b/src/AudioEffects/AudioEffect.h @@ -521,8 +521,25 @@ class Compressor : public AudioEffect { /// Processes the sample effect_t process(effect_t inSample) { - float inSampleF = (float)inSample; + return compress(inSample); + } + + Compressor *clone() { return new Compressor(*this); } + +protected: + enum CompStates {S_NoOperation, S_Attack, S_GainReduction, S_Release }; + enum CompStates state = S_NoOperation; + + int32_t attack_count, release_count, hold_count, timeout; + float gainreduce, gain_step_attack, gain_step_release, gain, threshold; + uint32_t sample_rate; + + void recalculate() { + gain_step_attack = (1.0f - gainreduce) / attack_count; + gain_step_release = (1.0f - gainreduce) / release_count; + } + float compress(float inSampleF){ if (fabs(inSampleF) > threshold) { if (gain >= gainreduce) { if (state==S_NoOperation) { @@ -586,25 +603,10 @@ class Compressor : public AudioEffect { } - float outSampleF = gain * inSample; + float outSampleF = gain * inSampleF; return outSampleF; } - Compressor *clone() { return new Compressor(*this); } - -protected: - enum CompStates {S_NoOperation, S_Attack, S_GainReduction, S_Release }; - enum CompStates state = S_NoOperation; - - int32_t attack_count, release_count, hold_count, timeout; - float gainreduce, gain_step_attack, gain_step_release, gain, threshold; - uint32_t sample_rate; - - void recalculate() { - gain_step_attack = (1.0f - gainreduce) / attack_count; - gain_step_release = (1.0f - gainreduce) / release_count; - } - };