# Input latency / lag: where is it coming from? how to reduce it?

**URL:** <https://forums.unrealengine.com/t/input-latency-lag-where-is-it-coming-from-how-to-reduce-it/531089>\
**Category:** Audio\
**Tags:** unreal-engine\
**Created:** [April 17, 2022, 3:53am UTC](https://forums.unrealengine.com/t/input-latency-lag-where-is-it-coming-from-how-to-reduce-it/531089 "2022-04-17T03:53:17Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![BitShapeSoft](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bitshapesoft/32/485424_2.png) [@BitShapeSoft](https://forums.unrealengine.com/u/BitShapeSoft)\
**Post date:** [July 21, 2022, 3:24am UTC](https://forums.unrealengine.com/t/input-latency-lag-where-is-it-coming-from-how-to-reduce-it/531089/3 "2022-07-21T03:24:09Z")

</div>

I don’t have answers yet, but I’ll post my investigations here just as a log.

I followed [this audio plugin tutorial](https://forums.unrealengine.com/t/making-a-ue-plugin-for-audio-from-scratch/152606) (very nice, btw) to run my own synth code. In the `OnGenerateAudio` function, I checked the `NumSamples` requested:

```auto
int32 ULibpdSynthComponent::OnGenerateAudio(float* OutAudio, int32 NumSamples)
{
	//each tick is one block of audio, typically 64 samples
	int32 ticks = NumSamples / pd.blockSize();
	pd.processFloat(ticks, InBufferPlaceholder, OutAudio);
	pd.receiveMessages();

	return NumSamples;
}

```

What I was expecting to see was the buffer size I requested in `Project Settings >> Platforms >> Windows >> Callback Buffer Size`, i.e., something like 256 or 512. However, no matter what settings I input there, the `NumSamples` requested was always 1024.

Diving into the engine source, I found in the `AudioMixerSourceDecode.cpp DoWork()` function that the `ProceduralTaskData.NumSamples` that filters down to my generate audio function is always set to… 8192!

So, my current understanding is that something in my system is setting the actual buffer size to 8192, and my plugin `OnGenerateAudio()` function is being run in blocks of 1024 samples multiple times to fill it up.

Next step… who is setting the buffer size to 8192?

---

_[View the full topic](https://forums.unrealengine.com/t/input-latency-lag-where-is-it-coming-from-how-to-reduce-it/531089)._
