I am having an issue with the output buffer. I am making a plugin that delays one channel a specified number of samples. I've done that in matlab and it's quite easy but it's driving me crazy with C++.
Now i'll write the code I have, but first I'll explain how I am doing everything so it's more easy for you to understand.
The host calls ProcessDoubleReplacing(...). In there, I call a method that does all the dsp. I'll show you:
Code: Select all (#)
void Synthesis::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
int const channelCount = 2;
int blockSize = GetBlockSize();
double* leftOutput = outputs[0];
double* rightoutput = outputs[1];
double* rightInput = inputs[1];
double* leftInput = inputs[0];
mDsp.procesos(leftInput, rightInput, leftOutput, rightoutput,nFrames,blockSize,mBufferDelay);
for (int i = 0; i < nFrames; i++) {
outputs[0][i] = leftOutput[i];
outputs[1][i] = rightoutput[i];
}
}
Then, I show you what the method "procesos" does:
Code: Select all (#)
void dsp::procesos(double* lIn, double* rIn, double* &lOut,double* &rOut, int nFrames,int blockSize, double* &bufferDelay){
duplex(lIn, rIn, lOut, rOut, nFrames, 30,bufferDelay);
}
So finally, I show you what the method duplex does:
Code: Select all (#)
void dsp::duplex(double* lIn, double* rIn, double* &lOut,double* &rOut, int nFrames, int angulo, double* &bufferDelay){
vector<double> vlIn(512);
vector<double> vrIn(512);
const double diametroCabeza = 0.09;
int j = 0;
int delayChannelMuestras = ((2*diametroCabeza*sin(3.14159/2))/343)*44100;
for (int i = 0; i < nFrames ; i++) {
vrIn.at(i) = rIn[i];
if (i < delayChannelMuestras) {
vlIn.at(i) = bufferDelay[i];
}
else{
vlIn.at(i) = lIn[i-delayChannelMuestras];
}
if (i > nFrames - delayChannelMuestras) {
bufferDelay[j] = lIn[i];
j++;
}
}
lOut = &vlIn.at(0);
rOut = rIn;
What I do with the left channel is the next:
I calculate the number of samples I want to delay (delayChannelMuestras)
I create a vector structure for the left channel
I fill this vector with a buffer that stores the last delayChannelMuestras samples of the previous processed block.
Then I continue filling with the samples of the block that the host is sending
Later, the buffer that stores the last samples is updated with the last delayChannelMuestras of the current block.
Finally I make the left output buffer (lOut) to point (so it has the values) the first position of the vector I used to process the block.
Ok, everything seems to be right, but there is a big problem:
When I debug I observe the outputs (lOut and rOut) at the end of the duplex method and the data in those arrays is perfect, as I expect it to be.
The problem comes when I look at those arrays in the method "procesos". The values in the arrays change! They adopt values like 2E75 or so. Random values but always very high.
This usually happens in just one of the two arrays. Sometimes the lOut works fine and the rOut changes randomly, sometimes rOut does fine and lOut missbehaves, and sometimes both go random.
How is that possible? How can the values of an array change so radically just exiting a method?
I show on the next image (poor paint skills I know) the phenomena. On the left you can see the code stopped just before leaving duplex method. On the right, just before leaving procesos method. I remember you that procesos method does absolutelyt nothing. I'm quite desperate and any help is much appreciated.
Thank you very much.
PD: I use xcode and wdl-ol, but I don't think it has much to do with the problem.