Hi, I’m trying to do a unit filter delay in which I’m processing the left and right channels separately, and only getting output out of my left speaker. The filtering is actually working, but I’m trying to find the best (correct) way to handle the process block. Here’s what I have. I’ll put these into a class at a later point (I know I’m repeating code for left and right sides). Thanks for any help.
//get read buffer to input audio samples
const float* leftChannelIn = buffer.getReadPointer(0, 0);
const float* rightChannelIn = buffer.getReadPointer(1, 0);
//create left and right channels to output to
float* leftChannelOut = buffer.getWritePointer (0, 0);
float* rightChannelOut = buffer.getWritePointer (1, 0);
//place audio samples into buffer
for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
{
//get the values here from the slider
a1L = *tree.getRawParameterValue("a1Control");
a1R = *tree.getRawParameterValue("a1Control");
//design equation a0 = a1 - 1.0 (separate for left and right)
a0L = a1L - 1.0;
a1R = a1R - 1.0;
//get current value from read pointer
float xnL = leftChannelIn[sample];
float xnR = rightChannelIn[sample];
//delay xnL and xnR by one sample---previous value from output is now the delayed value
float xnL1 = z1L;
float xnR1 = z1R;
//use difference equation y(n) = a0x(n) + a1x(n-1) for left and right channels
float ynL = a0L * xnL + a1L * xnL1;
float ynR = a0R * xnR + a1R * xnR1;
//current output is stored to become previous output in next loop
z1L = xnL;
z1R = ynR;
leftChannelOut[sample] = ynL;
rightChannelOut[sample] = ynR;
}
Ok I’ve figured out why that’s happening- if I set the read and write buffer to output only out of channel 0, this outputs out of BOTH channels, so channel 1 (outputting out one side) is phasing out one of channel 0’s outputs and the resulting output is just output out the other side. So the question now is how can I get the read/write buffer of channel 0 to only output out of the other side? If I set it them to 0 then it must be interpreted as being a mono signal…
Ok figured it out. Had to use a for loop to iterate through the channels in my read/write pointers and just use one difference equation that applies for both sides as they’d be reading from one channel at a time. Here’s the code for anyone that runs into the same issue…
for (int channel = 0; channel < buffer.getNumChannels(); ++channel)
{
const float* inputData = buffer.getReadPointer(channel, 0);
float* outputData = buffer.getWritePointer (channel, 0);
//place audio samples into buffer
for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
{
//get the values here from the slider
a1 = *tree.getRawParameterValue("a1Control");
//design equation a0 = a1 - 1.0
a0 = a1 - 1.0;
//get current value from read pointer
float xn = inputData[sample];
//delay by one sample---previous value from output is now the delayed value
float xn1 = z1;
//use difference equation y(n) = a0x(n) + a1x(n-1)
float yn = a0 * xn + a1 * xn1;
//current output is stored to become previous output in next loop
z1 = xn;
//output to speakers
outputData[sample] = yn;
}
}
The code would be so much easier and cleaner to deal with, if you put it inside a class and then had different object instances for the multiple audio channels.