Audio latency is the delay between the time an application submits a buffer of audio data to the APIs, until the time that it is heard. On the other hand, not confused the UI latency which is the time between a user’s tap or click on the screen and the processing event on the software side.
The UI latency origin can be mitigated with the new Unity input system or the OnPointerDown interface as with the MPTK demo EuclideanRhythm.
Luckily, to mitigate the latency on the hardware there is others solutions.
First Option: Audio Library with Oboe and MPTK Pro
FMOD is the default audio engine for Unity. It’s a powerful engine with a lot of features but too much generalist to be efficient. Rather prefer Oboe which is a more simple audio engine with low latency.
How to use Oboe with your MPTK application ?
- Buy and install this Unity asset : https://assetstore.unity.com/packages/tools/audio/oboe-for-unity-134705 in your Unity app.
- Go to Unity menu Edit → Project Settings → Player
- add symbol UNITY_OBOE
- allow unsafe code
- Build and deploy your APK and that’s all folks!!! MPTK has automatically switched to the Oboe audio engine.
Some drawbacks (world is not perfect!)
- Unity Audio Source are no more used so Unity effects and 3D sound are disabled but:
- panning left/right is already available
- MPTK effects are working as usual (low pass filter, reverb, chorus)
- MPTK synthesizer voices effects are working (ADSR, LFO, Pitch, …)
- Oboe is only working on Android.
- The latency with Unity is not only due to the audio engine. Also, search how to reduce input latency. But for this point, MPTK and OBOE can do nothing! Sorry!
In addition, you can going to the forum if you have question.
Second Option: Modify Unity Audio properties
According to your need, you could have only to change some properties on the Unity setting to resolve your latency issue.
From Unity menu Edit → Project Settings → Audio
- Set DSP Buffer size to Best latency
- Try with higher Sample Rate
- Minimize audio effects as much as possible
You can also change these parameters from the MPTK prefab inspectors.
- Audio latency is not a specific issue with Android but also on Windows, IOs, Mac, … Obviously, these setting are useful also for them.
- Depending on your system, too low buffer size can generate weird sound.
- Also, forget Bluetooth headset because of a high latency (for now) !
An APK is available for those who want to test on their Android. Ask me by email, i will send you a link to the APK Euclidean Rhythm. Of course, I would be very happy to have your return.
This demo is useful to test latency but also the MPTK synthesizer voices run time effects and running different players at the same time. So, there is two prefabs MidiStreamPlayer for the drums and one MidiFilePlayer for the midi running at the same time.