Fixes for compressor effect.

dev
Holger Wirtz 1 year ago
parent 3a97367755
commit 97aeb8de32
  1. 20
      third-party/effect_compressor/src/effect_compressor.cpp
  2. 6
      third-party/effect_compressor/src/effect_compressor.h

@ -93,8 +93,8 @@ void AudioEffectCompressor2::begin(void) {
// Find the smoothed envelope, target gain and compressed output
vPeak = vPeakSave;
for (int k=0; k<block->length; k++) {
vAbs = (block->data[k] >= 0.0f) ? block->data[k] : -block->data[k];
for (int k=0; k<AUDIO_BLOCK_SAMPLES; k++) {
vAbs = (block_f32[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

@ -83,6 +83,7 @@
#include <Arduino.h>
#include <AudioStream.h>
#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*);

Loading…
Cancel
Save