From 97aeb8de320b03c13bb6c0ce89705f4e15f06070 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 20 Jan 2023 14:14:45 +0100 Subject: [PATCH] Fixes for compressor effect. --- .../src/effect_compressor.cpp | 20 +++++-------------- .../effect_compressor/src/effect_compressor.h | 6 +----- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/third-party/effect_compressor/src/effect_compressor.cpp b/third-party/effect_compressor/src/effect_compressor.cpp index cf369c6..903395c 100644 --- a/third-party/effect_compressor/src/effect_compressor.cpp +++ b/third-party/effect_compressor/src/effect_compressor.cpp @@ -93,8 +93,8 @@ void AudioEffectCompressor2::begin(void) { // Find the smoothed envelope, target gain and compressed output vPeak = vPeakSave; - for (int k=0; klength; k++) { - vAbs = (block->data[k] >= 0.0f) ? block->data[k] : -block->data[k]; + for (int k=0; k= 0.0f) ? block_f32[k] : -block_f32[k]; if (vAbs >= vPeak) { // Attack (rising level) vPeak = alpha * vPeak + (oneMinusAlpha) * vAbs; } else { // Release (decay for falling level) @@ -116,31 +116,21 @@ void AudioEffectCompressor2::begin(void) { targetGain = pow10f(0.05f*(vOutDB - vInDB)); // And apply target gain to signal stream from the delayed data. The // delay buffer is circular because of delayBufferMask and length 2^m m<=8. - out_block->data[k] = targetGain * delayData[(k + in_index) & delayBufferMask]; - - if(printIO) { - Serial.print(block->data[k],6); - Serial.print("," ); - Serial.print(delayData[(k + in_index) & delayBufferMask],6); - Serial.print("," ); - Serial.println(targetGain); - } + out_block->data[k] = targetGain * delayData[(k + in_index) & delayBufferMask] * INT16_MAX; // Put the new data into the delay line, delaySize positions ahead. // If delaySize==256, this will be the same location as we just got data from. - delayData[(k + in_index + delaySize) & delayBufferMask] = block->data[k]; + delayData[(k + in_index + delaySize) & delayBufferMask] = block->data[k] / INT16_MAX; } vPeakSave = vPeak; // save last vPeak for next time sampleInputDB = vInDB; // Last values for get...() functions sampleGainDB = vOutDB - vInDB; // transmit the block and release memory - arm_float_to_q15(block_f32, block->data, AUDIO_BLOCK_SAMPLES); - AudioStream::release(block); AudioStream::transmit(out_block); // send the FIR output AudioStream::release(out_block); // Update pointer in_index to delay line for next 128 update - in_index = (in_index + block->length) & delayBufferMask; + in_index = (in_index + AUDIO_BLOCK_SAMPLES) & delayBufferMask; } // End update() // Sets a new compression curve by transferring structure diff --git a/third-party/effect_compressor/src/effect_compressor.h b/third-party/effect_compressor/src/effect_compressor.h index 85e2866..61b2cee 100644 --- a/third-party/effect_compressor/src/effect_compressor.h +++ b/third-party/effect_compressor/src/effect_compressor.h @@ -83,6 +83,7 @@ #include #include +#include "arm_math.h" // The following 3 defines are simplified implementations for common uses. // They replace the begin() function that is otherwise required. @@ -133,11 +134,6 @@ class AudioEffectCompressor2 : public AudioStream setAttackReleaseSec(0.005f, 0.100f); } - AudioEffectCompressor2(const AudioSettings &settings): AudioStream(1, inputQueueArray) { - //setSampleRate_Hz(settings.sample_rate_Hz); - setAttackReleaseSec(0.005f, 0.100f); - } - virtual void update(void); void begin(void); void setCompressionCurve(struct compressionCurve*);