iPlug2 Forum

How does plugin latency work?

Title mostly says it all. I’m working on a part of a plugin that involves time warping to give a pitch wobble effect. I am delayed roughly 2000 samples given the sample rate is 44100. I am aware of the PLUG_LATENCY option in config.h, but I’m not quite sure how to use it. Thanks for any help!

Just change the line:
#define PLUG_LATENCY 0
#define PLUG_LATENCY 2000

What does that do? How do I get to look ahead at the samples?

You’re misunderstanding how it works. You (the plugin) reports to the host how much latency you expect your plugin to produce. The HOST is the one that manages that latency…aligning the results from your plugin with other plugins and other tracks. From your standpoint, you don’t “look ahead”, you “process behind”. If you need to look ahead at a sample 2000 samples ahead of time, just look at the samples you’re receiving NOW and have it impact the sample 2000 samples ago. If you’ve reported latency to the host, it will align that result as expected. Since block sizes sent to the plugin can be of varying sizes, your latency may be larger than the block size, so that usually means you have to have some sort of circular buffering inside your plugin. ProcessBlock adds samples to the head of buffer/queue, you do your processing IN the buffer, and then you remove samples from the tail of the buffer/queue to return to the host.

There’s lots of sticky details about how to do that without pops and clicks, how to avoid off-by-one errors in your latency, and what to do if you receive buffers but there’s no output to generate and return to the host yet (you generally return zeroes / dead silence until the buffer’s latency is filled), but that’s kind of the basics. I’m probably not explaining it well, but there you go.


That cleared a lot of things up, thanks!