This project has moved. For the latest updates, please go here.

AudioProcessor buffer lengths always equal?

Mar 13, 2010 at 2:42 PM

Hello again!

When implementing the audio processor, can I assume that the length of each input/output are always equal?

 

public override void Process(VstAudioBuffer[] inputs, VstAudioBuffer[] outputs)

 

For example if I want to make an effect that switches the left and right channel I have 4 buffers (input[0], input[1], output[0] and output[1])

Each of the buffers has a SampleCount property which is the same for all buffers.

Could it be possible that a host processes the left and right channel with different buffer lengths?
If so, how would a stereo shaping plugin work in that environment?

For example., here I just use the length of in1 to process all buffers. what if the other buffers would have different lengths?

    public override void Process(VstAudioBuffer[] inputs, VstAudioBuffer[] outputs)
{
VstAudioBuffer in1 = inputs[0], in2 = inputs[1];
VstAudioBuffer out1 = outputs[0], out2 = outputs[1];


for (int i = 0; i < in1.SampleCount; i++)
{
out1[i] = in2[i];
out2[i] = in1[i];
}
}

Coordinator
Mar 14, 2010 at 6:58 AM

Yes, you can. The SampleCount of all input buffers and all output buffers are always the same. So these conditions are all true:

in1.SampleCount == in2.SampleCount
in1.SampleCount == out1.SampleCount
out1.SampleCount == out2.SampleCount

The SampleCount property on the audio buffer was put there to always have that number handy. The underlying VST C++ API only specifies one sample count value for all buffers during process (replacing).

 

Mar 14, 2010 at 4:29 PM

Thanks!

Another question: How would I create a buffer that always contains the last, for example, 512 samples processed?
I tried making a buffer with "new VstAudioBuffer()" but what is the first argument "buffer"?

Mar 14, 2010 at 5:12 PM

Alright, I found a way...

I built myself a Buffer class instead of using VstAudioBuffer.

public class Buffer
{
    public float[] buffer;
    public int index;
    private int _len;
    public int length{
        get { return _len; }
        set { _len = value; updateLength(); }
    }

    private void updateLength()
    {
        buffer = new float[_len];
        index = 0;
    }
    public Buffer(int length)
    {
        _len = length;
        updateLength();
    }
    public void addSample(float sample)
    {
        buffer[index] = sample;
        if (++index >= _len) index = 0;
    }
}

Coordinator
Mar 14, 2010 at 6:47 PM

You never need to create a VstAudioBuffer by hand. The VstAudioBuffer just wraps unmanaged memory and allows managed access to it. It is the only data structure in VST.NET that is not marshaled from C++ to .NET. That first param in the ctor is an unmanaged pointer to a buffer containing samples.

If you need a buffer for internal plugin processing, you need to write your own code (as you have done).

Hope it helps.

Mar 14, 2010 at 7:29 PM

Thx again! I really appreciate your help!