i getting some issues while trying to implement the compressor in my juce app, it always give me the segmentation fault when i try to check if it is not null and process it, here is the following parts of the processor
MainComponent.h
private:
// Limiter por canal
std::vector<std::unique_ptr<juce::dsp::Compressor<float>>> compressors;
// Estado do compressor por canal (ativo ou inativo)
std::vector<bool> compressorActivated;
// Modo Automatico por canal
std::vector<bool> compressorAutomaticMode;
// Parametros do compressor
struct CompressorParameters
{
float threshold = 0.0f; // Default threshold in dB
float ratio = 1.0f;
float attack = 10.0f; // Default attack time in ms
float release = 160.0f; // Default release time in ms
};
std::vector<CompressorParameters> compressorParams;
MainComponent::MainComponent(){
//...other declarations like sliders and gains
// Inicializa compressor por canal
compressors.resize(numChannels);
compressorActivated.resize(numChannels, false);
compressorAutomaticMode.resize(numChannels, true);
compressorParams.resize(numChannels);
for (int channel = 0; channel < numChannels; ++channel)
{
compressors[channel] = std::make_unique<juce::dsp::Compressor<float>>();
// Defina os parâmetros padrão
compressors[channel]->setThreshold(compressorParams[channel].threshold);
compressors[channel]->setRatio(compressorParams[channel].ratio);
compressors[channel]->setAttack(compressorParams[channel].attack);
compressors[channel]->setRelease(compressorParams[channel].release);
compressors[channel]->prepare(spec);
}
}
void MainComponent::audioDeviceAboutToStart(juce::AudioIODevice* device)
{
currentSampleRate = device->getCurrentSampleRate();
// Prepare os crossovers com a nova taxa de amostragem
juce::dsp::ProcessSpec spec;
spec.sampleRate = currentSampleRate;
spec.maximumBlockSize = 512;
spec.numChannels = 1;
for (int channel = 0; channel < numChannels; ++channel)
{
if (crossovers[channel] != nullptr)
{
crossovers[channel]->prepare(spec);
}
if (compressors[channel] != nullptr)
{
compressors[channel]->prepare(spec);
}
}
}
void MainComponent::processOutputBuffer(juce::AudioBuffer<float>& outputBuffer)
{
int numOutputChannels = outputBuffer.getNumChannels();
int numSamples = outputBuffer.getNumSamples();
juce::dsp::AudioBlock<float> audioBlock(outputBuffer);
for (int channel = 0; channel < numOutputChannels; ++channel)
{
//Aplica Compressor
if (compressorActivated[channel] && compressors[channel] != nullptr)
{
// If automatic mode is on, update threshold based on some logic
if (compressorAutomaticMode[channel])
{
float autoAttack = 10;
float autoRelease = 160;
if(crossovers[channel] != nullptr){
autoAttack = (crossovers[channel]->getHpfGain())/500;
autoRelease = autoAttack*16;
}
compressors[channel]->setThreshold(compressorParams[channel].threshold);
compressors[channel]->setRatio(compressorParams[channel].ratio);
compressors[channel]->setAttack(autoAttack);
compressors[channel]->setRelease(autoRelease);
}
else
{
// Use manual parameters
compressors[channel]->setThreshold(compressorParams[channel].threshold);
compressors[channel]->setRatio(compressorParams[channel].ratio);
compressors[channel]->setAttack(compressorParams[channel].attack);
compressors[channel]->setRelease(compressorParams[channel].release);
}
compressors[channel]->process(context);
}
}
// Aplica o ganho master
outputBuffer.applyGain(static_cast<float>(masterGainSlider.getValue()));
}
and if i remove it from the output buffer the app work normally