VST Plug-In: how to implement a "lookahead" buffer?

My goal is to write a VST plugin that should work in Audition and Audacity, I'm planning to go with VST v2.x. I'm new to VST development, but I have studied the examples here . And so far, most things look pretty straightforward. The main "magic" seems to happen in the process () or processReplace () function . Not really sure if this is the advantage / disadvantage of these two features.

Now the "problem" is that my filter will need the "Lookahead" buffer for a few seconds (maybe more, depending on the setup). This means that at the beginning of the process, I will need to fill my internal buffer. And, at the end of the process, I will need to clear the pending samples from the internal buffer.

I have coded SoX filters (Sound eXchange) before and their API is very similar to VST at first glance. What is called process () in VST is called flow () in SoX API. But there is one significant difference: the flow () function in the SoX API receives as parameters the number of samples available in the input buffer, as well as the number of samples that fit into the output buffer. Flow () functionreturns the number of samples it took from the input buffer, as well as the number of samples it wrote to the output buffer. This means that I don't have to process all the available input in every call. And one call can return fewer samples than it consumed. Consequently, at the beginning of the process I can use all of the input samples, but to return the output data is not ! This way I can fill my lookahead buffer at the beginning. Finally, the SoX API has a drain () function that will be called by the main application at the end of the process to flush pending samples from the internal filter buffer.

From what I understand about VST, the process () function only has one parameter, which is the number of input and output samples. And it has no way to limit the number of output samples. Apparently, process () assumes a simple "N samples in, N samples" behavior. It is right???

If so, what is the recommended way to fill my internal view buffer in VST? And what is the recommended way to flush my internal buffer at the end in VST?


By the way: I know that I could of course fill my internal buffer by only returning "silence" on the first few calls to process () , at the beginning of the process. But this will delay / shift the entire audio file that is not needed ! Also it doesn't solve the problem of how to clear the internal buffer at the end of the process.

Thanks for any advice !; -)

+3


source to share


1 answer


Ok I think I figured out the solution. The VST has a setInitialDelay () function . So I think I will need to defer the output myself and then compensate by setting the correct setInitialDelay () value .

[UPDATE]



This seems to work well with Audition, but not Audacity. It looks like Audacity is ignoring the value set by setInitialDelay () , so the sound ends up being delayed. Is there a way around Audacity ???

0


source







All Articles