Skip to content

Commit

Permalink
Compressor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Oct 22, 2023
1 parent c23c22a commit 202e8de
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/AudioEffects/AudioEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

};


Expand Down

0 comments on commit 202e8de

Please sign in to comment.