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

Instantiating a new VstAudioBuffer

Topics: Audio, Newbie, Plugin Development
Apr 12, 2011 at 1:07 AM
Edited Apr 12, 2011 at 1:09 AM

Hi,

I am working on the audio stuttering problem, as well, and I am almost certain that I have figured out what it is - my buffer is too small. Its only 512 samples, but the sample rate is 44100 (i believe). Because of this, I tried to call the process method over and over to reproduce a continuous buffer. I have to see if there is a way to lengthen the output buffer - I think this will solve my problem. I am not sure how to increase the size of the buffer or how to set the buffer size when I instantiate it. Does this seem to make sense as a plausible reason for my problem, and do you know how I can set the buffer size?

I am trying to instantiate a new VstAudioBuffer because the buffer that exists currently is only 512 samples and I want it to be 44100 samples. Since the SampleCount property is read only, i am trying to instantiate a new VstAudioBuffer as follows:

float[] newBuffer = new float[44100];

output =  new VstAudioBuffer(newBuffer*, 44100, true); 

(the underline is where the error is, which says ') expected' mousing over the 44100 and '; expected' mousing over the true)

What am I doing wrong? I have considered that this may not be the proper way to achieve the result that I want, as well - is there another way this should be done?

 

Thanks,

 

Jake

Coordinator
Apr 12, 2011 at 5:45 AM

Hi Jake,

If you take a look at the Jacobi.Vst.Interop.Host classes, you'll see a VstAudioBufferManager class. This is the easiest way to create VstAudioBuffers. Specify the size and number of buffers in the constructor and then call ToArray to gain access to each individual buffer.

Unless you are building a host, you do not have any influence on the audio buffers and their size. The host will notify the plugin of the buffer size with a call to (set)BlockSize. Buffersizes can usually be changed in the host (advanced settings).

As a plugin, you simply have to work with what is handed to you by the host. The host will call the the Process method on the audio processor repeatedly (sample rate / block size). So a smaller buffer means more call per second to the Process method, but it also means a smaller lag time.

Hope it helps,
Marc

 

Apr 13, 2011 at 4:09 PM
Edited Apr 13, 2011 at 4:09 PM

After reading about it, I think that while the base problem is the same, the actual issue is different for me than for sgtPerm in his thread about a similar problem. In my case, as you've stated, I have no control over my output buffer except for the values that I put into it.

While simply a theory, I therefore think that my problem is with values clashing between the end and the start of each buffer. Currently, the values are something like this (assuming a max amplitude of 2, a very basic triangle wave, and a buffer size of 10):

 

The process method is called and the buffer is filled with this data:

0, 1, 2, 1, 0, -1, -2, -1, 0, 1

and at that point, the buffer is full and cannot receive any more data.

Then, the process method is called again, and the buffer is filled as such:

0, 1, 2, 1, 0, -1, -2, -1, 0, 1

 

So, the audio output looks something like this when put together:

0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 0, 1, 2, 1, 0, -1, -2, -1, 0, 1

When in actuality the output should look something like this:

0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1

 

While I'm not certain this is the reason for my stuttering, it seems plausible; thus, I have considered the option of keeping track of my current amplitude position at the end of each buffer and passing it into the next buffer's start. There may be a better way to do this, however, and with your experience, you may know that this is not the problem. Can I get your thoughts on this?

 

Thanks,

Jake

Apr 13, 2011 at 7:06 PM

I fixed it!! I made a 44100 sample buffer, filled it, and then pulled from it during each process cycle.

Sweet!!!

Now I just got to figure out how to overlay an ADSR envelope on it :)

 

Thanks for all of your help, Marc.

 

Jake