Hi,
I’m new to Juce and trying to create an auto-wah plugin. I can’t get any effect to output audio no matter what I do, there is just some slight noise but no auto-wah. What could be the problem? The filters should be implemented correctly, as the same code creates a wah-effect on matlab.
Here is the processblock:
for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear(i, 0, buffer.getNumSamples());
// This is the place where you'd normally do the guts of your plugin's
// audio processing...
for (int channel = 0; channel < 2; ++channel)
{
// Output
float* channelData = buffer.getWritePointer(channel);
// Input
const float* x = buffer.getReadPointer(channel);
// Iterate over the signal
for (int n = 0; n < buffer.getNumSamples(); n++) {
//auto x = channelData;
float y = 0.0;
// Level detector
if (abs(x[n]) > yLn1) {
yLn = a_A * yLn1 + (1 - a_A)*abs(x[n]); // Attack
}
else {
yLn = a_R * yLn1 + (1 - a_R)*abs(x[n]); // Release
}
yLn1 = yLn;
fc = minf + (maxf - minf)*yLn;
// Peak filter parameters
d = -cos(2 * PI*fc / getSampleRate());
H0 = pow(10, (Gain / 20)) - 1;
c = (tan(PI*fb / getSampleRate()) - 1) / (tan(PI*fb / getSampleRate() + 1));
// Peak filter difference equations
xhn = x[n] - d*(1-c) * xhn1 + c * xhn2;
y1 = -c * xhn + d * (1 - c) * xhn1 + xhn2;
y = 0.5 * H0 * (x[n] - y1) + x[n];
xhn2 = xhn1;
xhn1 = xhn;
// channelData: Output channel
channelData[n] = y;
The simple answer is you have to keep separate variables (which hold the state) for each channel. So, throughout your code, the left and right channels, for example, will have their own distinct variables. That is how you keep the processing separate and avoid artifacts, like clicking and pops, in the output.
Ideally you put all your yLn1 xhn1, xhn2 etc. into a struct or class and have one instance for each channel…
Others call them then Coefficients, so you can look into the juce sources, how they do it for other filters:
You might be able to adapt that pattern to your implementation
Please don’t take this as a criticism of you - as I said in the linked post, there’s really no way a newcomer could reasonably be expected to find the other posts describing the same problem, because there isn’t a keyword or other term you could have searched for!
And TBH I think that’s one of the reasons why it’s such a common problem. There are probably many other common mistakes where a quick Google would immediately give you the solution, so we never hear about them.
I still couldn’t get it right I did it this time with the IIRFilter functionality and with separate variables for both channels, now there is no noise but also no difference in output audio at all. Why aren’t the audio samples processed? Can you help me out?
processSingleSampleRaw() returns the processed sample value. So you probably need to change the end of your for-loop to something like:
left[n] = filter_left.processSingleSampleRaw(x_left);
right[n] = filter_right.processSingleSampleRaw(x_right);