DSP Buffer Size differences? Why isn't it a setting per platform?

Hey there!

I’ve been fiddling with the DSP Buffer Size to make sure that my audio plays a) the moment I need it to play and b) doesn’t crackle. Unfortunately, the four choices that Unity offers are very ambiguous: Default, Best Latency, Good Latency, and Best performance. Maybe someone here could explain what these choices actually mean?

My findings with the fiddling so far:

  • On iOS, with DSP Buffer Size set to Default, there is almost 1/3rd of a second delay between the moment a sound is played through script and is hearable. This is unacceptable, so on iOS both Good and Best Latency give the expected result.
  • On Windows, with DSP Buffer Size set to Good or Best Latency, there is a very clear crackling sound at the start of the sound, which is unacceptable. I have to set DSP Buffer Size to Default or Best Performance to stop that form happening.
  • On macOS, I can set DSP Buffer Size to anything and it will never crackle.

This makes me wonder: why isn’t DSP Buffer Size part of the per-platform build settings?

3 Likes

Still not sure what to do with this…

You might be able to set it in script to the optimal settings. I have the exact same problem with IOS where there’s slowness in playing the sound (5S).

FYI setting buffer size from script is unsupported after Unity 5.0. The only way is to set it in advance from menu.

Today, Unity 2017.3.1f1, “Best Latency” still produces cracking sound and slow-mo playback on Windows. On Android, iOS, and macOS, this setting is very reliable and has the best latency. (Other than skipping Unity and go native, then it can be a bit faster.)

1 Like

This doesn’t seem to be the case in at least Unity 2018.1.6f1. You can change the DSP Buffer size by using AudioSettings.GetConfiguration() and AudioSettings.Reset() as explained here: Unity - Scripting API: AudioSettings.Reset

Example

var configuration = AudioSettings.GetConfiguration;
configuration.dspBufferSize = 32;
AudioSettings.Reset(configuration);
6 Likes

I could confirm that Reset works.

To add some information for Android, it seems Best Latency = 256, Default/Good Latency = 512, Best Performance = 1024 regardless of devices, and this make Best Latency produce buffer underrun on some new flagship devices (and they are popular too) such as Huawei P20/P20 Pro/Mate 20/Mate 20X/Honor V20/various MeiZu. These devices actually needs something like 1024 to be enough.

Buffer underrun sounds like the song slowed down (always or occasionally) and cause gameplay to be ahead of the song.

9 Likes

Bringing this back because it’s still relevant.

  1. This should definitely be a per platform setting. Not sure why it’s per project. Every platform behaves very differently, not sure how one setting can just work.

  2. Can we get more transparency on what each setting corresponds too? Best latency, good latency. What values do they correspond to? What is default? On iOS default is different from “Good latency”. What is the logic behind default? Why isn’t this setting a numeric value?

4 Likes

+1
Would like to know more about what to set this to for each platform.

Would also be great to have an event that the system triggers when there’s a buffer underrun, and we can decide if we want to dynamically change the latency.

2 Likes

I tired the script above, I put it on my camera in the start function but now I get no audio output.

Any idea?

Still happening in 2021.3.16f1 cracking noise for music files only when played on android devices. Set DSP buffer to Best Performance no difference.

  • Disabled andriod wifi big improvement,
  • Disabled Wifi calling issue went away.

Had to turn them back on but Wi-Fi should not be interfering with playing sound.

1 Like