# How does plugin latency work?

**URL:** <https://iplug2.discourse.group/t/how-does-plugin-latency-work/410>\
**Category:** Uncategorized\
**Created:** [13 June 2021 21:30 UTC](https://iplug2.discourse.group/t/how-does-plugin-latency-work/410 "2021-06-13T21:30:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![snfk](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/snfk/32/140_2.png) [@snfk](https://iplug2.discourse.group/u/snfk)\
**Post date:** [13 June 2021 21:30 UTC](https://iplug2.discourse.group/t/how-does-plugin-latency-work/410/1 "2021-06-13T21:30:18Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![JohnCrosby](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/johncrosby/32/30_2.png) [@JohnCrosby](https://iplug2.discourse.group/u/JohnCrosby)\
**Post date:** [15 June 2021 22:19 UTC](https://iplug2.discourse.group/t/how-does-plugin-latency-work/410/2 "2021-06-15T22:19:19Z")

</div>

Just change the line:  
#define PLUG\_LATENCY 0  
to:  
#define PLUG\_LATENCY 2000

---

<div class="post-metadata">

**Author:** ![snfk](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/snfk/32/140_2.png) [@snfk](https://iplug2.discourse.group/u/snfk)\
**Post date:** [15 June 2021 23:42 UTC](https://iplug2.discourse.group/t/how-does-plugin-latency-work/410/3 "2021-06-15T23:42:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sstillwell](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/sstillwell/32/69_2.png) [@sstillwell](https://iplug2.discourse.group/u/sstillwell)\
**Post date:** [16 June 2021 04:17 UTC](https://iplug2.discourse.group/t/how-does-plugin-latency-work/410/4 "2021-06-16T04:17:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![snfk](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/snfk/32/140_2.png) [@snfk](https://iplug2.discourse.group/u/snfk)\
**Post date:** [16 June 2021 13:24 UTC](https://iplug2.discourse.group/t/how-does-plugin-latency-work/410/5 "2021-06-16T13:24:25Z")

</div>

That cleared a lot of things up, thanks!
