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*);