@ -93,8 +93,8 @@ void AudioEffectCompressor2::begin(void) {
// Find the smoothed envelope, target gain and compressed output
// Find the smoothed envelope, target gain and compressed output
vPeak = vPeakSave ;
vPeak = vPeakSave ;
for ( int k = 0 ; k < block - > length ; k + + ) {
for ( int k = 0 ; k < AUDIO_BLOCK_SAMPLES ; k + + ) {
vAbs = ( block - > data [ k ] > = 0.0f ) ? block - > data [ k ] : - block - > data [ k ] ;
vAbs = ( block_f32 [ k ] > = 0.0f ) ? block_f32 [ k ] : - block_f32 [ k ] ;
if ( vAbs > = vPeak ) { // Attack (rising level)
if ( vAbs > = vPeak ) { // Attack (rising level)
vPeak = alpha * vPeak + ( oneMinusAlpha ) * vAbs ;
vPeak = alpha * vPeak + ( oneMinusAlpha ) * vAbs ;
} else { // Release (decay for falling level)
} else { // Release (decay for falling level)
@ -116,31 +116,21 @@ void AudioEffectCompressor2::begin(void) {
targetGain = pow10f ( 0.05f * ( vOutDB - vInDB ) ) ;
targetGain = pow10f ( 0.05f * ( vOutDB - vInDB ) ) ;
// And apply target gain to signal stream from the delayed data. The
// 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.
// delay buffer is circular because of delayBufferMask and length 2^m m<=8.
out_block - > data [ k ] = targetGain * delayData [ ( k + in_index ) & delayBufferMask ] ;
out_block - > data [ k ] = targetGain * delayData [ ( k + in_index ) & delayBufferMask ] * INT16_MAX ;
if ( printIO ) {
Serial . print ( block - > data [ k ] , 6 ) ;
Serial . print ( " , " ) ;
Serial . print ( delayData [ ( k + in_index ) & delayBufferMask ] , 6 ) ;
Serial . print ( " , " ) ;
Serial . println ( targetGain ) ;
}
// Put the new data into the delay line, delaySize positions ahead.
// 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.
// 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
vPeakSave = vPeak ; // save last vPeak for next time
sampleInputDB = vInDB ; // Last values for get...() functions
sampleInputDB = vInDB ; // Last values for get...() functions
sampleGainDB = vOutDB - vInDB ;
sampleGainDB = vOutDB - vInDB ;
// transmit the block and release memory
// transmit the block and release memory
arm_float_to_q15 ( block_f32 , block - > data , AUDIO_BLOCK_SAMPLES ) ;
AudioStream : : release ( block ) ;
AudioStream : : release ( block ) ;
AudioStream : : transmit ( out_block ) ; // send the FIR output
AudioStream : : transmit ( out_block ) ; // send the FIR output
AudioStream : : release ( out_block ) ;
AudioStream : : release ( out_block ) ;
// Update pointer in_index to delay line for next 128 update
// 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()
} // End update()
// Sets a new compression curve by transferring structure
// Sets a new compression curve by transferring structure