# Playback latency

**URL:** <https://qa.fmod.com/t/playback-latency/19362>\
**Category:** FMOD Studio\
**Tags:** csharp\
**Created:** [October 4, 2022, 8:05pm UTC](https://qa.fmod.com/t/playback-latency/19362 "2022-10-04T20:05:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grimelios](https://avatars.discourse-cdn.com/v4/letter/g/9de053/32.png) [@Grimelios](https://qa.fmod.com/u/Grimelios)\
**Post date:** [October 4, 2022, 8:05pm UTC](https://qa.fmod.com/t/playback-latency/19362/1 "2022-10-04T20:05:39Z")

</div>

I’m new to FMOD and currently implementing basic playback in my custom C# engine. Following the quick-start tutorial [here](https://fmod.com/docs/2.02/studio/quick-start-tutorial.html), I’ve exported my banks and successfully loaded and played a sound effect in-game (played on key press). The issue is that, no matter what I try, I seem to be stuck with roughly 150-250 ms latency.

There are many existing posts on this forum related to event latency. Unfortunately, none of the proposed solutions have worked for me so far. Here’s what I’ve already tried/verified:

1. Sample data is loaded in advance (using `Studio::EventDescription::loadSampleData`). I’ve verified that the data is loaded (using `Studio::EventDescription::getSampleLoadingState`) prior to creating an event instance.
2. The asset in FMOD Studio is _not_ marked as streaming.
3. There’s no blank space at the beginning of each asset. In other words, latency is _not_ present in FMOD Studio (or when playing assets through a separate player).
4. I’ve called `System::setDSPBufferSize` with varying values (to no effect).
5. All relevant objects are valid (verified using the `isValid()` function on each object).
6. No FMOD errors are detected (the `FMOD_RESULT` from each relevant call is always `OK`).
7. I’ve tried pausing the instance immediately after creation (using `Studio::EventInstance::setPaused`), then unpausing later (no change).
8. The system itself is updated frequently (currently 60 FPS). I’ve also tried calling `Studio::System::update` as quickly as the thread can run, with no change. In other words, there are no other slow or blocking parts of my engine currently affecting FMOD.

As a last-ditch effort, I even precisely timed the delay between starting an instance (using `Studio::EventDescription::createInstance`, then `Studio::EventInstance::start` on the returned instance) and that instance being confirmed as playing (using `Studio::EventInstance::getPlaybackState`). Over many instances, the average delay between creation and playback was roughly 10 ms. I’ve further experimented with additional assets and events, and changed platform encoding settings (no luck).

Given all this, I’m at a loss for why I’m still experiencing latency during playback. Hoping someone can provide some direction. Thank you!

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [October 10, 2022, 12:51am UTC](https://qa.fmod.com/t/playback-latency/19362/2 "2022-10-10T00:51:13Z")

</div>

Sounds like you’ve eliminated all of the usual suspects. Are you using any [Convolution Reverb](https://fmod.com/docs/2.02/api/effects-reference.html#convolution-reverb) plugins in any of your events/buses? That’s another common source of additional latency.  
Just to verify your system settings, can you please run this basic debug code inside your game engine and tell me what the results for blocksize, buffersize and latency are reported as?

```csharp
var result = system.getDSPBufferSize(out uint blocksize, out int numblocks);
result = system.getSoftwareFormat(out int frequency, out _, out _);

float ms = (float)blocksize * 1000.0f / (float)frequency;

Console.WriteLine("Mixer blocksize = {0:N2} ms", ms);
Console.WriteLine("Mixer Total buffersize = {0:N2} ms", ms * numblocks);
Console.WriteLine("Mixer Average Latency = {0:N2} ms", ms * ((float)numblocks - 1.5f));

```

---

<div class="post-metadata">

**Author:** ![Grimelios](https://avatars.discourse-cdn.com/v4/letter/g/9de053/32.png) [@Grimelios](https://qa.fmod.com/u/Grimelios)\
**Post date:** [October 10, 2022, 2:12pm UTC](https://qa.fmod.com/t/playback-latency/19362/3 "2022-10-10T14:12:16Z")

</div>

Thank you for the reply! I’m not using any convolution reverb plugins currently, no.

Here are my current settings:

- `blocksize: 1024`
- `numBlocks: 4`
- `frequency: 48,000`

And the console output:

- Mixer blocksize = 21.33 ms
- Mixer Total buffersize = 85.33 ms
- Mixer Average Latency = 53.33 ms

In grabbing these values, I also realized an important mistake I made: the reason that calling `setDSPBufferSize` had no effect is that I had been calling it _after initializing the FMOD.Studio.System_. When calling it prior to initialization, I am finally hearing reduced latency (I’ve tried `bufferlength` values of 512 and 256, and unsurprisingly, 256 gives the lowest latency).

The documentation for `setDSPBufferSize` mentions that `bufferlength` is best left alone. Changing `numbuffers` does have a _small_ effect, but not nearly as impactful as lowering `bufferlength`. Are there recommended values generally used for video games (besides the defaults)?

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [October 10, 2022, 10:26pm UTC](https://qa.fmod.com/t/playback-latency/19362/4 "2022-10-10T22:26:44Z")

</div>

Thank you for the additional information, glad to hear the latency has improved.  
The required `bufferlength` should always be a factor of 2, but other than that there are no definite rules. Just low enough that you don’t notice latency, and high enough that it isn’t flogging the cpu and creating other issues like clicks and pops.  
There are [platform considerations](https://fmod.com/docs/2.02/api/platforms.html) when setting the `bufferlength` which you can read about in the Latency section of each respective platform.

---

<div class="post-metadata">

**Author:** ![Grimelios](https://avatars.discourse-cdn.com/v4/letter/g/9de053/32.png) [@Grimelios](https://qa.fmod.com/u/Grimelios)\
**Post date:** [October 10, 2022, 11:02pm UTC](https://qa.fmod.com/t/playback-latency/19362/5 "2022-10-10T23:02:58Z")

</div>

I’ll keep that in mind. Thanks so much Jeff!

As mentioned in my post above, the fix here was to **call `setDSPBufferSize` prior to `FMOD.Studio.System` initialization** , where I had been calling it after (which, per documentation and debugging, has no effect). I’ll mark this answer as the solution for clarity.
