I have a question...
I am trying to extend chipaudettes compressor class with an option to add another input and use it as a sidechain compressor. Where one of the inputs are analyzed and the other input gets the compression based on the analyze.
But the program freeze when I try to read the other input:
Code:
audio_block_sc = AudioStream_F32::receiveReadOnly_f32(1);
I can put this
Code:
audio_block_sc = AudioStream_F32::receiveReadOnly_f32(0);
and the program will run, but does not what it should obviously.
I have tried a lot of different methods and variants of receiveReadOnly, made new audioStreams etc.
Does anyone have an idea what I am missing?
Code:
#ifndef _AudioEffectCompressor2_F32
#define _AudioEffectCompressor2_F32
#include <arm_math.h> //ARM DSP extensions. https://www.keil.com/pack/doc/CMSIS/DSP/html/index.html
#include <AudioStream_F32.h>
class AudioEffectCompressor2_F32 : public AudioStream_F32
{
//GUI: inputs:2, outputs:1 //this line used for automatic generation of GUI node
public:
//constructor
AudioEffectCompressor2_F32(void) : AudioStream_F32(2, inputQueueArray_f32 ) {
setThresh_dBFS(-20.0f); //set the default value for the threshold for compression
setCompressionRatio(5.0f); //set the default copression ratio
setAttack_sec(0.005f, AUDIO_SAMPLE_RATE); //default to this value
setRelease_sec(0.200f, AUDIO_SAMPLE_RATE); //default to this value
setHPFilterCoeff(); enableHPFilter(true); //enable the HP filter to remove any DC offset from the audio
resetStates(); setSideChain(0);
};
//here's the method that does all the work
void update(void) {
//Serial.println("AudioEffectGain_F32: updating."); //for debugging.
audio_block_f32_t *audio_block, *audio_block_sc;
audio_block = AudioStream_F32::receiveWritable_f32(0);
if (!audio_block) return;
audio_block_sc = AudioStream_F32::receiveReadOnly_f32(1);
/*if (!audio_block_sc) {
release(audio_block);
return;
}
*/
//apply a high-pass filter to get rid of the DC offset
if (use_HP_prefilter) arm_biquad_cascade_df1_f32(&hp_filt_struct, audio_block->data, audio_block->data, audio_block->length);
//apply the pre-gain...a negative gain value will disable
//if (pre_gain > 0.0f) arm_scale_f32(audio_block->data, pre_gain, audio_block->data, audio_block->length); //use ARM DSP for speed!
//calculate the level of the audio (ie, calculate a smoothed version of the signal power)
audio_block_f32_t *audio_level_dB_block = AudioStream_F32::allocate_f32();
calcAudioLevel_dB(audio_block, audio_level_dB_block); //returns through audio_level_dB_block
//compute the desired gain based on the observed audio level
audio_block_f32_t *gain_block = AudioStream_F32::allocate_f32();
calcGain(audio_level_dB_block, gain_block); //returns through gain_block
//apply the desired gain...store the processed audio back into audio_block
//if sideChain is activated it affects the other input with the calculated gain.
if (!sideChain) arm_mult_f32(audio_block->data, gain_block->data, audio_block->data, audio_block->length);
else arm_mult_f32(audio_block_sc->data, gain_block->data, audio_block->data, audio_block->length);
//arm_mult_f32(audio_block->data, gain_block->data, audio_block->data, audio_block->length);
//transmit the block and release memory
AudioStream_F32::transmit(audio_block);
AudioStream_F32::release(audio_block_sc);
AudioStream_F32::release(audio_block);
AudioStream_F32::release(gain_block);
AudioStream_F32::release(audio_level_dB_block);
}