Working on my synth so far is going great. Now I want to try and add a DSP processing effect ONLY to a single voice, and are starting out with just trying to apply some gain.
My project started from Projucer - Audio Plugin, so I got PluginProcessor, Editor, SynthSound (not using at all at the moment), and SynthVoice where in renderNextBlock audio data is pulled from a wavetable.
So in SynthVoice I got a bunch of initializers, but relevant now is;
class SynthVoice : public SynthesiserVoice {
public:
SynthVoice ()
{
auto& masterGain = processorChain.get<masterGainIndex> ();
masterGain.setGainLinear (0.5f);
}
Then related to the DSP processing I got;
//==============================================================================
void reset () noexcept
{
processorChain.reset ();
}
//==============================================================================
template <typename ProcessContext>
void process (const ProcessContext& context) noexcept
{
processorChain.process (context);
}
//==============================================================================
void prepare (const juce::dsp::ProcessSpec& spec)
{
tempBlock = juce::dsp::AudioBlock<float> (heapBlock, spec.numChannels,
spec.maximumBlockSize);
processorChain.prepare (spec);
}
In Private I got;
private:
juce::HeapBlock<char> heapBlock;
juce::dsp::AudioBlock<float> tempBlock;
enum { masterGainIndex };
juce::dsp::ProcessorChain<juce::dsp::LadderFilter<float>, juce::dsp::Gain<float>>
processorChain;
Finally in renderNextBlock I got;
void renderNextBlock (AudioBuffer<float>& outputBuffer, int startSample, int numSamples)
{
size_t start = startSample;
size_t samples = numSamples;
auto output = tempBlock.getSubBlock (startSample, (size_t) numSamples);
output.clear ();
while (--numSamples >= 0)
{
// Reset combined audio
combinedAudioLeft = 0.0f;
combinedAudioRight = 0.0f;
// Here I get my audio data from a wavetable
// Output audio
outputBuffer.addSample (0, startSample, combinedAudioLeft);
outputBuffer.addSample (1, startSample, combinedAudioRight);
++startSample;
}
// Here I am attempting to DSP process the mastergain
auto block = output.getSubBlock (start, samples);
juce::dsp::ProcessContextReplacing<float> context (block);
processorChain.process (context);
}
Code compiles without a hiccup, but gain is not changed when running.
HIGHLY
So what am I missing / doing wrong? Any help is ^^^^^^ appreciated!