As a means of learning to create a synth plugin, I’m trying to expand the JuceDemoPlugin. My first step was to add a filter.
But, since this example has a way handling single and double floating point precision. The problem arises when trying to implement the IIRFilter class. I get the following compiler bugs:
error: C:\JUCE\examples\audio plugin demo\Source\PluginProcessor.cpp: cannot initialize a parameter of type ‘float *’ with an lvalue of type 'float’
error: C:\JUCE\examples\audio plugin demo\Source\PluginProcessor.cpp: cannot initialize a parameter of type ‘float *’ with an lvalue of type 'float’
error: C:\JUCE\examples\audio plugin demo\Source\PluginProcessor.cpp: cannot initialize a parameter of type ‘float *’ with an lvalue of type 'double’
error: C:\JUCE\examples\audio plugin demo\Source\PluginProcessor.cpp: cannot initialize a parameter of type ‘float *’ with an lvalue of type ‘double’
It seems to me that the IIRFilter class can’t handle Float type templates… (and I don’t yet exactly know how they work).
This is the code I’ve added:
PluginProcessor.h
template <typename FloatType>
void applyFilter (AudioBuffer<FloatType>&);
PluginProcessor.cpp
template <typename FloatType>
void JuceDemoPluginAudioProcessor::applyFilter (AudioBuffer<FloatType>& buffer)
{
IIRCoefficients ic = IIRCoefficients::makeLowPass(m_sampleRate, 500);
lowPassFilterLeft.setCoefficients(ic);
lowPassFilterRight.setCoefficients(ic);
const int numSamples = buffer.getNumSamples();
for (int channel = 0; channel < getTotalNumOutputChannels(); ++channel)
{
FloatType* const channelData = buffer.getWritePointer ( channel );
lowPassFilterLeft.processSamples ( channelData[0], numSamples );
lowPassFilterRight.processSamples( channelData[1], numSamples );
}
}
template <typename FloatType>
void JuceDemoPluginAudioProcessor::process (AudioBuffer<FloatType>& buffer,
MidiBuffer& midiMessages,
AudioBuffer<FloatType>& delayBuffer)
{
const int numSamples = buffer.getNumSamples();
// Now pass any incoming midi messages to our keyboard state object, and let it
// add messages to the buffer if the user is clicking on the on-screen keys
keyboardState.processNextMidiBuffer (midiMessages, 0, numSamples, true);
// and now get our synth to process these midi events and generate its output.
synth.renderNextBlock (buffer, midiMessages, 0, numSamples);
applyFilter (buffer); //FILTER OUTPUT
// Apply our delay effect to the new output..
applyDelay (buffer, delayBuffer);
// In case we have more outputs than inputs, we'll clear any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
for (int i = getTotalNumInputChannels(); i < getTotalNumOutputChannels(); ++i)
buffer.clear (i, 0, numSamples);
applyGain (buffer, delayBuffer); // apply our gain-change to the outgoing data..
// Now ask the host for the current time so we can store it to be displayed later...
updateCurrentTimeInfoFromHost();
}
Is there a way around this error without having to adjust the IIRFilter class? Any help in the right direction would be greatly appreciated!