Hi!
So I followed the basic example on DSPAudioPlugin demo found with juce. it works great on AudioProcessor, but I’m trying to get it to work on individual voices on synthesiser, so I’ve inherited Synthesiser-class, and overridden the RenderVoices-method to do the DSP-stuff in there. For some reason the DSP does not work as it works in AudioProcessor.
I also tried inherit SamplerVoice, and do it inside it’s renderNextBlock but the results are the same and I feel it’s unnecessay to do it in there…
Sound playbacks but is very distorted like 3/4 of the samples would be completely missing in the buffer or something. I’ve confirmed the thing works without these lines in RenderVoices-method, and for example a basic tempBuffer.ApplyGain confirms everything else is working ok:
dsp::AudioBlock<float> block(tempBuffer);
process(dsp::ProcessContextReplacing<float>(block));
Any Ideas?
Code:
//Sampler is a public Synthesiser
Sampler::Sampler() :
lowPassFilter(dsp::IIR::Coefficients<float>::makeFirstOrderLowPass(48000.0, 20000.f)) {}
void Sampler::renderVoices(AudioBuffer<float>& buffer, int startSample, int numSamples)
{
int SampleCount = buffer.getNumSamples();
int ChannelCount = buffer.getNumChannels();
//DSP STUFF
dsp::ProcessSpec spec{ getSampleRate(), static_cast<uint32> (numSamples), ChannelCount };
lowPassFilter.prepare(spec);
lowPassFilter.reset();
AudioBuffer<float> tempBuffer;
tempBuffer.setSize(ChannelCount, SampleCount, false, false, true);
tempBuffer.clear();
AudioBuffer<float> tempGatherBuffer;
tempGatherBuffer.setSize(ChannelCount, SampleCount, false, false, true);
tempGatherBuffer.clear();
for (auto* voice : voices) {
voice->renderNextBlock(tempBuffer, startSample, SampleCount);
updateParameters(500.0f); //low-pass of 500Hz
dsp::AudioBlock<float> block(tempBuffer);
process(dsp::ProcessContextReplacing<float>(block));
tempGatherBuffer.addFrom(0, startSample, tempBuffer, 0, startSample, numSamples, 1.0f);
if (ChannelCount==2) tempGatherBuffer.addFrom(1, startSample, tempBuffer, 1, startSample, numSamples, 1.0f);
tempBuffer.clear();
}
buffer.operator=(tempGatherBuffer);
}
void Sampler::process(dsp::ProcessContextReplacing<float> context) noexcept {
ScopedNoDenormals noDenormals;
// Post-lowpass filtering
lowPassFilter.process(context);
}
void Sampler::updateParameters(float LPHz) {
*lowPassFilter.state = *dsp::IIR::Coefficients<float>::makeLowPass(getSampleRate(), LPHz);
}
Any help would be much appreciated!