output buffer changing values randomly when leaving a function xCode VST

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
Hello kvr,
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];
    }

}
Ok, pretty simple for the moment.

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);
}
As you see, this methot just calls another method (duplex). I know it's stupid at the moment. The method will have more code in the future.

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;
So, as you can see, the right channel isn't touched (last line of the code).

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.
Magic of C++.jpg
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.
You do not have the required permissions to view the files attached to this post.

Post

I didn't check everything, but first obvious thing is that your last loop in doubleprocessreplacing is useless.

Post

Miles1981 wrote:I didn't check everything, but first obvious thing is that your last loop in doubleprocessreplacing is useless.
OK, I now understand that what seems logicial isn't at all due to the convoluted way you are passing arguments.
Did you really think that changing your left output pointer for a pointer to a temporary vector would work?

Code: Select all

lOut = &vlIn.at(0);
So basically your main mistake is that you are not using the array the host gives you (although you pass them from valid values! I can't understand why you did that).

Post

lout and rout are pointers passed by reference from outside. You are reassigning both of them with temporary data created in your last function
It is a miracle it is not crashing

Post Reply

Return to “DSP and Plugin Development”