Hi, I am trying to create a simple compressor that oversamples by a fixed 2x, and has a HPF in the side-chain. I haven’t been able to create a HPF, because I haven’t figured out an effective way to implement it. I found that the filterBlock.copyFrom(returnBlock)
statement, doesn’t perform a duplicate of returnBlock
in the way I was expecting. I was hoping for it to be a 1:1 copy of the block so that I can have two separate, equally-oversampled audio paths, one of which I will use as the side-chain with the HPF. Any insights into where I could go from here? Thank you.
The setup I have right now looks like this:
//**Process Block**
juce::dsp::AudioBlock< float> inputBlock (buffer);
auto returnBlock = oversampler.processSamplesUp(inputBlock);
//Ballistics Filter set up
ballisticsFilter.setAttackTime(*apvts.getRawParameterValue(ATTACK_TIME_ID));
ballisticsFilter.setReleaseTime(*apvts.getRawParameterValue(RELEASE_TIME_ID));
ballisticsFilter.setLevelCalculationType(juce::dsp::BallisticsFilterLevelCalculationType::peak);
juce::dsp::AudioBlock<float> filterBlock;
filterBlock.copyFrom(returnBlock); // <- right here is where I am having trouble
//Filter Process
updateFilters();
scHPF.process(juce::dsp::ProcessContextReplacing<float> (filterBlock));
//Gain Calculator + DCA
auto returnBlockNumSamples {returnBlock.getNumSamples()};
for (size_t channel {0}; channel < totalNumInputChannels; ++channel)
{
auto *channelData = returnBlock.getChannelPointer(channel);
auto *filterBlockChannelData = filterBlock.getChannelPointer(channel);
auto avgGain = 0.0f;
//Gain Calc
for (size_t sample {0}; sample < returnBlockNumSamples; ++sample) {
if (sample % 5 == 0) {
ballisticsFilter.snapToZero();
}
float envDB = 20.0f * std::log10f(ballisticsFilter.processSample(channel, filterBlockChannelData[sample]));
float gain = 0.0f;
if ((2.0f * (envDB - threshold)) < -knee){
gain = 1.0f;
} else if ((2.0f * std::abs(envDB - threshold)) <= knee){
gain = std::powf(10.0f, ((envDB + (1.0f / ratio - 1.0f) * std::powf(envDB - threshold + (knee / 2.0f), 2.0f) / (2.0f * knee)) - envDB) / 20.0f);
} else if ((2.0f * (envDB - threshold)) > knee) {
gain = std::powf(10.0f, (threshold + ((envDB - threshold) / ratio) - envDB) / 20.0f);
}
avgGain += gain;
}
avgGain /= returnBlockNumSamples;
//DCA w/ juce::SmoothedValue<float, juce::ValueSmoothingTypes::Linear>
smoothedGain.setTargetValue(avgGain);
smoothedGain.applyGain(channelData, returnBlockNumSamples);
}