Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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

Discussion in 'Audio & Video' started by _Adriaan, Dec 25, 2016.

  1. _Adriaan

    _Adriaan

    Joined:
    Nov 12, 2009
    Posts:
    478
    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?
     
    jrumps and LilGames like this.
  2. _Adriaan

    _Adriaan

    Joined:
    Nov 12, 2009
    Posts:
    478
    Still not sure what to do with this...
     
  3. supertonkers

    supertonkers

    Joined:
    Jun 13, 2015
    Posts:
    4
    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).
     
  4. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,553
    FYI setting buffer size from script is unsupported after Unity 5.0. The only way is to set it in advance from menu.
    https://docs.unity3d.com/ScriptReference/AudioSettings.GetDSPBufferSize.html

    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.)
     
    patrickgh3 likes this.
  5. lars_bwb

    lars_bwb

    Joined:
    Feb 8, 2017
    Posts:
    3
    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: https://docs.unity3d.com/ScriptReference/AudioSettings.Reset.html

    Example
    Code (CSharp):
    1. var configuration = AudioSettings.GetConfiguration;
    2. configuration.dspBufferSize = 32;
    3. AudioSettings.Reset(configuration);
     
  6. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,553
    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.
     
    Last edited: Apr 9, 2019
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    9,434
    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?
     
  8. drupaljoe

    drupaljoe

    Joined:
    Feb 4, 2019
    Posts:
    119
    +1
    Would like to know more about what to set this to for each platform.
     
  9. mgstauff

    mgstauff

    Joined:
    Sep 6, 2017
    Posts:
    45
    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.
     
    glenneroo and DriesVienne like this.
  10. philspitlerSF

    philspitlerSF

    Joined:
    Oct 10, 2018
    Posts:
    37
    I tired the script above, I put it on my camera in the start function but now I get no audio output.

    Any idea?
     
unityunity