Set buffer size on Android to achieve minimum latency

I read that to get the best possible latency on Android I should use OpenSL, and use the device output native frequency and device native buffer.

But testing the fmod record.cpp example on a Pixel 2 XL (native buffer size = 96) and setting SetDSPBufferSize(96, 4) I get very unstable sound. On a Nokia 7 Plus (native buffer size = 192) it works perfectly setting SetDSPBufferSize(192, 4).

So, I think I’m not correct, and it leads me to some questions:

  • Should the fmod dsp buffer size needs to be equal the device native buffer size?
  • How many buffers should I use? How different is to use a buffer of 1024 from using 2 buffers of 512?
  • Using the record.cpp example, is there any way to achieve the minimum possible latency on each Android device, without getting stuttering/skipping/unstable sound?

The problem with Android is that it runs on so many different devices and they all tend to have their own (sometimes odd) preferred buffer sizes.

For minimal latency we recommend using OpenSL and the device output native frequency, leaving FMOD to handle the DSPBufferSize (defaults to 512 x 4, which then feeds the hardware at it’s native size).

Warning! The ‘buffersize’ is generally best left alone. Making the granularity smaller will just increase CPU usage (cache misses and DSP network overhead). Making it larger affects how often you hear commands update such as volume/pitch/pan changes. Anything above 20ms will be noticable and sound parameter changes will be obvious instead of smooth.

FMOD chooses the most optimal size by default for best stability, depending on the output type. It is not recommended changing this value unless you really need to. You may get worse performance than the default settings chosen by FMOD.

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

There is some more information on latency on Andoid devices here:
https://www.fmod.com/resources/documentation-api?version=2.0&page=platforms-android.html#audio-latency

1 Like

Thank you for your detailed answer. I’ll do like you explained.

Hi…which Nexus device are you referring to? Off the top of my head Nexus 9 has a buffer size of 128, Nexus 6P has 192 and Nexus 5X has 192.
Incidentally I think you mean 96 frames on Pixel, not 94.
Either way, 1920 is a very large buffer and unless it’s a very old Nexus device it sounds too high to be correct.