Hi all,
I am experiencing a problem where I only get audio from the right channel. This is my code is processBlock, what am i doing wrong here? I am trying to process a custom filter in stereo, meaning left and right channel.
for (int channel = 0; channel < buffer.getNumChannels(); ++channel)
{
float* channelData = buffer.getWritePointer (channel);
Filter* highPassFilter = (channel == 0) ? &leftHighPass : &rightHighPass;
for (int sample = 0; sample < numSamples; ++sample)
{
channelData[sample] = highPassFilter-process(channelData[sample]);
leftHighPass.setHighPass(getSampleRate(), highPass);
rightHighPass.setHighPass(getSampleRate(), highPass);
}
}
Your assistance would be appreciated as always.
Ok, looking at my code I think another issue with my code is that I’m setting the parameters inside the loop, would that be the reason? I will move them out of the loop and see if the problem persist. But in the mean time any other suggestions are welcomed.
1 Like
I would keep it simple and just create two instances of the filter class, one per channel, as private members of our processor
myFilterClass hpf[2];
then, in your processBlock
for(int c = 0; c < numChannels; ++c)
{
for(int i = 0; i < numSamples; ++i)
{
channelData[i] = hpf[c].process(channelData[i]);
}
}
Thank you @lcapozzi for your response, yeah that would be the simplest way of doing it but i was right the problem was caused by setting the parameters inside the loop, i moved it outside the loop and it worked.
you can update filters in a loop. the way you did it just felt a little confusing. cause you still had that step of selecting a filter while aleady being in the loop, which is kinda redundant. if you used an array of filters, like ica suggested, it could look like this:
for(int c = 0; c < numChannels; ++c)
{
auto channelData = buffer.getWritePointer(c);
hpf[c].setHighPass(getSampleRate(), highPass);
for(int i = 0; i < numSamples; ++i)
{
channelData[i] = hpf[c].process(channelData[i]);
}
}
@Mrugalla I appreciate your input. Upon reviewing my code more closely, I realized that while setting filter parameters inside the channel loop indeed works, my initial error was setting them within the sample loop. By moving the parameter-setting operations outside of the sample loop and into the channel loop, I was able to resolve the issues and ensure proper processing of stereo audio with the desired filter settings. Thank you for your assistance in troubleshooting this matter.