Help reducing audio latency

Hi, I’m using FMOD and I’m experimenting a big latency when playing sounds. I think the latency is about 140ms.

I’m on Windows 10 64 bits, high end CPU, using FMOD C# bindings supplied by FMOD and mostly using raw C# (not unity)

My init is

result=lowLevelSystem.setSoftwareFormat (0,SPEAKERMODE.DEFAULT,0);	// so that can get same frequency as output and avoid some extra latency
result=system.initialize (256,
			FMOD.Studio.INITFLAGS.NORMAL,
			FMOD.INITFLAGS.NORMAL | FMOD.INITFLAGS._3D_RIGHTHANDED,
			IntPtr.Zero);

I’m playing the particular sound through FMOD Studio events.

I use system.getEvent at the start of the game, then each time I want to play the sound, I call the event’s createInstance, and finally effectInstance.start to play the sound.

I’ve been searching the forum and used lowLevelSystem.setDSPBufferSize (512,4); to reduce latency a bit (maybe from ~140 to ~100)
but that is still too big for my project, and I don’t feel like further reducing the DSP buffer size. (256 reduces it to ~80)

All sounds are added into FMOD Studio as wav, although I don’t know is FMS changes the format. The sound is “correctly trimmed” (no extra silence before the sample)

Could you please suggest any more actions to further reduce the latency? It seems like there are 60ms extra latency somewhere not caused by the DSP buffer.

Thanks!

KakCat, this is what I did to get my latency down to about 20ms:

  • Firstly, any audio asset that should have low-latency playback must NOT be marked as streaming in FMOD Studio. Compression doesn’t seem to impact latency, but streaming certainly does.

  • Secondly, an FMOD event needs to first be “buffered” by playing it, then immediately pausing it. Then, when it comes time to play the event, just set pause to false (rather than calling the play method).

These two things was all I needed. I reverted my DSP buffer settings back to default after making these changes and that latency was still super low.

Hi buffdash, thanks for your answer.

I’ve tried the pause method with my version and seemed not to change anything. Then I decided to move to FMOD 2 64bits (long overdue). After changing some code to adhere to the new API your trick seemed to reduce latency a bit, but unfortunately not as much as you could. Increasing the DSP buffer still increases the latency though.

Although the latency now is more bearable than before (50-70 ms) with 512, I’m wonder what I’m doing wrong :frowning:

I’ll try going with the pause trick for the moment, but I’ll have to really think how to structure the code so that it’s not a mess to just play a sound.

I’m also very interested in lowering latency for a rhythm game - any further information would be greatly appreciated.

As mentioned previously, the way to reduce latency with FMOD is to use the Core level System::setDSPBufferSize. The documentation contains certain caveats you need to be mindful of.

https://fmod.com/resources/documentation-api?version=2.00&page=core-api-system.html#system_setdspbuffersize