简体   繁体   中英

VST Plug-In: How to implement a “lookahead” buffer?

My goal is to write a VST plug-in that should work in Audition and Audacity , so 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 stuff looks pretty straight forward. The main "magic" seems to happen in the process() or processReplace() function. Not quite sure what is the benefit/drawback of these two functions though.

Now the "problem" is that my filter is going to need a "Lookahead" buffer of a few seconds (maybe longer, depends on 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 flush the pending samples from the internal buffer.

I have been coding filters for SoX (Sound eXchange) before and their API is pretty similar to VST at a first glance. What is called process() in VST, is called flow() in SoX API. But there's one major difference: The flow() function in SoX API gets, as parameters, the number of samples available in the input buffer as well as the number of samples that fit into the output buffer. The flow() function then returns the number of samples it has taken from the input buffer as well as the number of samples it has written into the output buffer. It means I don't have to process all available input samples in every call. And a single call can return fewer samples than it has consumed. Consequently, at the beginning of the process, I can consume all input samples but return no output samples at all! This way I can fill my "lookahead" buffer at the beginning. Finally, SoX API has a drain() function that will be called by the Main application at the end of the process in order to flush the pending samples from the filter's internal buffer.

From what I understand about VST, the process() function only has a single parameter to indicate 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 out" behavior. Is that right ???

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


BTW: I know that I could, of course, fill my internal buffer by returning only "silence" in the first several process() calls, at the beginning of the process. But that would delay/shift the entire audio file, which is not wanted! Also it does not solve the problem how to flush the internal buffer at the end of the process.

Thank you for any advices! ;-)

Okay, I think I figured out a solution. There is a setInitialDelay() function in VST. So I guess I'll need to delay the output myself and then compensate by setting the proper value by setInitialDelay() .

[UPDATE]

This seems to work nice with Audition , but not with Audacity . Looks like Audacity ignores the value set by setInitialDelay() , so audio ends up delayed. Is there any workaround for Audacity ???

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM