I’m experiencing important latency in Unreal Engine 4.20.
This is strange as I never witnessed this kind of latency with previous versions of both Fmod and UE4.
Here is a clip : https://clyp.it/jzedqk3k?token=3ca3e3997127510f7361aee5296e62b8
First sound is from UE4 (the softer and higher pitched one) and the harder and low pitch one is from Fmod.
There is about 50ms to 80 ms latency with Fmod event which is too much for gameplay reaction.
I’m on a Mac with a Motu Ultralite MK3 soundcard. My partner has a basic windows 10 realtek soundcard and he’s experiencing higher latency (min 150 ms).
I tweaked the Dsp Buffer length and count but it’s not reducing latency very much unless I add extreme values (DSP length 128 and Count 4 or 2), still there is some latency.
The weird thing is that when I download the UE4 integration for 4.20 UE4, the plugin section within UE4 says it’s 1.10.09 Fmod version. Could this be a problem?
Do you have solutions and could it be some Fmod or UE4 bug?
- You must login to post comments
Thanks for raising this.
When using FMOD with UE4 some additional latency compared to the built in Unreal audio system is normal because FMOD has a deeper pipeline than UE4. If we consider the point where UE4 triggers an FMOD event as the start of the pipeline, and the OS audio output buffer as the end, these are the steps along the way:
In UE4: a request to start the FMOD event is generated by the integration calling the FMOD API. Internally in FMOD this just places a command in a command queue.
In UE4: the FMOD integration component gets ticked and calls the FMOD Studio update function. Internally in FMOD the command queue is submitted for processing; processing of the submitted commands begins asynchronously the next time the FMOD Studio Update thread ticks.
In FMOD: when processing the command to play the event FMOD will first load any non-streaming sample data into memory.
In FMOD: once sample data is loaded FMOD will schedule the instruments on the event at some point in the future.
In FMOD: when the instrument starts producing signal in the mixer it is mixed into a ring buffer which is read by the OS output.
At each point there is some unavoidable latency, but there are values which can be tweaked to mitigate it:
In our testing we measured an average 6-7ms between Sequencer calling the FMOD integration to play an event and then UE4 calling FMOD to update the FMOD Studio system. You may well get longer delays in a complex game. There’s no tweakable setting which will mitigate this, we have made a change to our integration which will significantly reduce this in our next release.
FMOD Studio processes command queues at a fixed frequency. The default is 20ms, so on average there is 10ms, and a maximum of 20ms latency between UE4 ticking FMOD and the FMOD Studio system processing the commands. Setting the “Studio Update Period” to 10 will reduce the average to 5ms and the maximum to 10ms. Depending on the complexity of your soundscape reducing this might cause scheduling issues during playback, keep an eye on the logs if you lower this value.
The loading delay for sample data can be avoided completely by pre-loading sample data. The integration gives an option “Load All Sample Data” to preload all samples from all banks, you would probably want to work with your programmers or use Blueprints to selectively load and unload sample data as required.
To support sample accurate scheduling the FMOD Studio system needs to schedule instrument playback a little ahead of where the FMOD mixer is working. In the case of non-streaming sample data the schedule delay is one mixing block (which is 10ms by default). The size of mixing blocks can be reduced which will also reduce the schedule delay of non-streaming sounds (more below).
In the case of streaming data it’s 8192 samples (which is 170ms for a system sample rate of 48kHz). The schedule delay can be overriden for an event instance using code or Blueprint, you might wish to make the streaming schedule delay shorter but care needs to be taken as there will be a physical limit on how quickly FMOD can get the initial buffer of streaming data from media. If the length of the schedule delay for streams is a big issue there is another workaround for it which would require using a programmer sound instrument instead of placing the stream directly on the event. In that case the stream could be prepared and be ready to play in advance and then the event can start playing it immediately.
- The FMOD mixer mixes audio into a ring buffer which is broken up into a number of blocks. The latency between the FMOD mixer producing mixed audio and that data getting into the system output buffer is about half of the size of the ring buffer. The default values for the ring buffer vary from platform to platform and can be overriden in the project settings in UE4. The total size of the ring buffer is “DSPBuffer Count” multiplied by “DSPBuffer Length”. The default values for Windows are 4 and 1024 respectively, leading to an average 2048 sample latency between the FMOD mixer and the system output (40ms for a system sample rate of 48kHz). These values are probably higher than they need to be as we still need to support Windows XP which had relatively poor latency. For games targeting modern machines you should be able to reduce the “DSPBuffer Length” to 512.
Please let me know if this explanation makes sense, I can try to clarify anything which is too confusing, but basically the takeaways are:
You can easily and safely reduce the audio latency by about 20ms by adjusting the “DSPBuffer Length” to 512.
You can potentially reduce latency by a further 5ms on average by changing the “Studio Update Period” to 10, but that may cause scheduling problems if you have many or complex events playing.
You can eliminate loading delay for sample data by judicious use of the FMOD API.
The delay on playing streams is difficult to change, it is possible to reduce it somewhat with the “Schedule Delay” event instance property, but I advise you to be cautious with that setting. It is possible to workaround this limitation using a programmer sound instrument which can preload streams, eliminating the extra schedule delay. Please email email@example.com if you’d like help implementing the workaround.
- You must login to post comments
Please login first to submit.