Hi !
Cpp newbie here, so sorry if this is stupid, but after googling and experimenting, I can’t make any sense of this.
I’m trying to use an array of (custom_class) filters as a member class of my PluginProcessor, to have one filter per audio channel.
When I do the following with a stereo channel, everything works fine:
class BarebonefilterAudioProcessor : public AudioProcessor
{
...
private:
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BarebonefilterAudioProcessor)
//==============================================================================
MyFilter filterL;
MyFilter filterR;
...
void BarebonefilterAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();
for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
float* channelDataL = buffer.getWritePointer(0);
float* channelDataR = buffer.getWritePointer(1);
filterL.filterNSamples(channelDataL, buffer.getNumSamples());
filterR.filterNSamples(channelDataR, buffer.getNumSamples());
}
However, when I try to generalise the principle (I guess very naively), I do this, and the plugin outputs a full DC offset, it seems. Well, something with the way I handle the array is messed up.
class BarebonefilterAudioProcessor : public AudioProcessor
{
private:
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BarebonefilterAudioProcessor)
//==============================================================================
OwnedArray<MyFilter> filters;
...
BarebonefilterAudioProcessor::BarebonefilterAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", AudioChannelSet::stereo(), true)
#endif
.withOutput ("Output", AudioChannelSet::stereo(), true)
#endif
)
#endif
{
filters.clear();
for (int i = 0; i < getTotalNumInputChannels(); ++i)
{
MyFilter f;
filters.add(&f);
}
}
void BarebonefilterAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();
for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
float* channelData = buffer.getWritePointer(channel);
filters[channel]->filterNSamples(channelData, buffer.getNumSamples());
}
}
Are the instances of MyFilter going out of scope or something ? I can’t tell what the issue is.
Thank you for your time