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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Audio Slowing Down During Runtime

Discussion in 'Audio & Video' started by maxmitchelll, Jun 15, 2020.

  1. maxmitchelll

    maxmitchelll

    Joined:
    May 19, 2019
    Posts:
    7
    Hi all. I've been experiencing this problem periodically throughout my game's development. This issue was mentioned in this thread: https://forum.unity.com/threads/audio-slow-down-and-crackling.719720/ , but it was not resolved and I have seen no other threads pertaining to the bug, so I thought I'd post about it.

    Essentially what is happening is that all audio in my game will slow down, to the point of lowered pitch and crackling. It is very noticeable when it happens. It tends to occur after extended usage in Play mode, or extended play of a Standalone build. It's not super common, but also an unacceptable bug due to how much it distorts the audio. What's most concerning is that I've had Alpha testers report this same problem to me after playing the build on their PC, indicating that it's not an issue local to my computer.

    To give more information on my setup:

    I'm using version 2019.3.14f1
    Platform is PC (Windows is what I use)
    Audio files are a mix of .mp3 and .wav. (although, the bug, when it occurs, happens across the board and distorts all the audio in the game (music, sfx, etc.))
    Audio file sample rates are set to Preserve Sample Rate (which is the default. I didn't change any settings for these audio files from the default per compression, load type, quality, etc.)

    Does anyone recognize this bug or have any suggestions? I'd be happy to provide info, screenshots, or anything that would be helpful.
     
  2. maxmitchelll

    maxmitchelll

    Joined:
    May 19, 2019
    Posts:
    7
  3. maxmitchelll

    maxmitchelll

    Joined:
    May 19, 2019
    Posts:
    7
    bumping this again, please let me know if you have any ideas or suggestions!
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    10,004
    Well, there is not much to go on. So I will shoot some ideas which may or may not will take you closer to any solutions:
    - I would immediately start profiling, GC can cause stutters, which may or may not could manifest as audio problems (CPU usage)
    - check your CPU usage, if you bring the CPU to its knees, there won't be enough power to handle the audio thread properly
    - check your memory usage, if you overflow the memory it may start to swap, which is a very slow operation, you don't want to go there
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,066
    Unity's audio stuff are just horrible.

    Check the Latency setting in Project Settings -> Audio -> DSP Buffer Size and see if changing that changes anything.
     
  6. Jon_Olive

    Jon_Olive

    Joined:
    Sep 26, 2017
    Posts:
    23
    I have come across this problem when implementing processing in OnAudioFilterRead(). From another post (sorry I can't remember where it was now) someone suggested it might be related to c# garbage collection - and indeed on cleaning up my scripts to remove unnecessary garbage creation the problem went away. Maybe worth checking out.
     
  7. maxmitchelll

    maxmitchelll

    Joined:
    May 19, 2019
    Posts:
    7
    @Lurking-Ninja
    Just ran while checking CPU. Game (when run in the Unity editor) appears to use ~50% of CPU at launch, then soon drops to about ~34% and appears to stay there. In overview, CPU use in total across the PC never goes over ~60%. In standalone build, seems to stagnate at about ~12%. Do these numbers seem high, or normal? (I don't have a frame of reference here).

    Memory-wise, in the editor it appears to use ~500mb, and in the build ~160mb. Do these numbers seem too high? (also a side note, my task manager says I'm using 78% memory when neither is running, is that normal?)

    Used the profiler as well (really cool tool, didn't know Unity even had this!). In total, seems to be roughly 10ms, with consistent 16ms spikes and a few spikes up to/past 33ms. Also, when I take out "Others", CPU usage is steadily below 5ms. Not sure exactly what "Others" is, but if there's a problem with CPU usage, that'd probably be where it's coming from.

    If these numbers seem too high, what are some steps I could take to cut down?

    @AcidArrow
    DSP Buffer Size is set to "Best latency" right now. Would there be a better setting for it to be on, or should I stick with that?

    @Jon_Olive
    According to the profiler, GarbageCollector is a negligible portion of my CPU usage (couldn't even give you a number, as none shows up on the profiler). This seems weird, as surely some garbage collection should be occurring, right? Is there any reason this might be happening that you know of? Should I check garbage collection some other way? In any event, I will definitely clean up my code.

    Thanks to all of you for responding, I understand this is sort of a frustrating bug as it is hard to reproduce and unclear in cause. I appreciate your patience and suggestions.
     
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,066
    Yeah, try Good Latency or Default.
     
  9. maxmitchelll

    maxmitchelll

    Joined:
    May 19, 2019
    Posts:
    7
    @AcidArrow Got it. I'll try that, and will report back here if the bug persists. Wish I could elicit the bug to perform a more immediate test, but unfortunately I don't know of any way to do that right now.
     
  10. Jon_Olive

    Jon_Olive

    Joined:
    Sep 26, 2017
    Posts:
    23
    @maxmitchelll Definitely try higher latency setting - good latency made it go away for me - though I needed best latency hence my garbage cleaning. I seem to recall that I didn't see much garbage activity in the profiler either - but I was generating a ton of garbage from some badly written custom inspector scripts - so if you have any of those might be the first place to look. I wonder if the profiler bothers to show those since they don't operate in a build...

    EDIT - I see in your case it was happening in the build too - so not the custom inspectors then!
     
  11. Katerpilet

    Katerpilet

    Joined:
    Aug 2, 2015
    Posts:
    87
    Having DSP Buffer Size on Best Latency causes this issue for me on PC but not on mobile. Would be great to get a fix
     
  12. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,066
    We won't, it has been buggy for many years, Unity doesn't intend to fix it.
     
  13. kim_haa

    kim_haa

    Joined:
    Nov 19, 2018
    Posts:
    1
    For me this happens when i have spatial blend enabled, if I make it completely 2d it works as intended. But this is not a fix that is valid since the sound should be in 3d...

    EDIT: After playing around for a while with the settings my problem was resolved by having spatial blend, then in the 3D sound settings I adjusted the doppler level to 0, this seems to allow the sound files to play normally in my case
     
    Last edited: Dec 23, 2022
  14. guyann45

    guyann45

    Joined:
    Dec 17, 2022
    Posts:
    1
    I can't help with Unity 2019.3.14f1