Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Heavy audio stutter in 5.4, but not 5.3

Discussion in 'Audio & Video' started by Thelo, Oct 16, 2016.

  1. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Hi all, I'm having trouble pinpointing the source of this audio problem. In Unity 5.3, we have no audio problems. But after upgrading to 5.4, the audio in our game will periodically start to heavily stutter and slow down, as if starved of CPU or something like that.

    The profiler graphs between 5.3 and 5.4 for the audio in our game look basically identical, as does the Game pane's Stats panel, and the game's overall framerate seems basically the same. Nothing out of the ordinary is going on in the Audio Mixer pane that I can see, either. And yet we get periods of heavy audio stutter in 5.4 that we never got in 5.3!

    These stutter periods seem to come and go, lasting a couple minutes, then healing themselves for another five minutes... then coming back later. During a stutter period, ALL audio painfully stutters and slows down (!)

    Setting all sounds to pure-2D or to pure-3D doesn't affect this problem, and when it happens, it affects all sounds and music, regardless of their compression method, quality, or load type.

    I am at my wit's end trying to fix this, or at least understand why it would possibly happen. Does anyone have ideas on where else to look? Or perhaps have experienced similar audio problems when upgrading to 5.4?
     
  2. moshangmusic

    moshangmusic

    Joined:
    Jul 16, 2015
    Posts:
    9
    This describes the issue we're having exactly. I've established that the problem doesn't occur in Unity 5.3.5f1, but does in Unity 5.3.6 onwards (I've tested 5.3.6, 5.4.1, and 5.4.2). I had hopes that the recent bugfix related to an audio memory leak would fix the issue, but it doesn't - specifically this one in 5.4.1p4
    • (832271) - Audio: Fixed memory leak when quickly loading and unloading lots of audio assets.
    I'm about to test a build made with the 5.5 Beta, but I also want to incrementally do builds with the patch versions of 5.3.5 to see if I can pinpoint an exact version where the problem starts. It's time consuming though because the problem is intermittent and I haven't yet found a procedure to induce the stutter.

    @Thelo Have you filed a bug report?
     
    Last edited: Oct 17, 2016
  3. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    I haven't filed a bug report yet, in part because I can't seem to get a consistent way to reproduce the problem yet. Doing incremental builds sounds like a good idea though, if very time consuming.

    Edit: We get the stutter on 5.4.1p4, but not on 5.3.3p3, which it seems you already figured out.
     
  4. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    I haven't yet found a way to reliably trigger it, but here are a couple comparative screenshots of the profiler while the stutter is going on, and while it's not, in our game:



    The main difference I can see between the two is that the "Total Audio CPU" line veers wildly up and down during a stutter period, although it still doesn't exceed like, 3%. Whereas during regular times, this same line stays flat around 3%.

    So I wonder if the stutter indicates that the audio subsystem is trying to free up resources when it shouldn't?
     
  5. moshangmusic

    moshangmusic

    Joined:
    Jul 16, 2015
    Posts:
    9
    The Unity evangelist here in Taiwan has filed a bug report regarding this issue on our behalf. In the meantime, we've reverted our project back to 5.3.5f1.
     
  6. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Thanks! Do you have the bug report number, so that I can track it?
     
  7. moshangmusic

    moshangmusic

    Joined:
    Jul 16, 2015
    Posts:
    9
    The number we have is 809727, but that might be an internal number as I don't see it in the issue tracker yet.
     
  8. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    129
    With the same problem for weeks...
     
  9. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Bug 809727 still isn't in the issue tracker, very annoying. This audio stutter bug is quite embarrassing for our game, and we can't really revert to 5.3 because of PS4 requirements, so I hope Unity can fix it soon.

    Interestingly, it constantly happens in our main game, but I haven't been able to reproduce it in a small repro project yet. So there's probably some specific trigger for it that I have yet to find. Has anyone been able to get either a consistent repro, or any "small scale" repro project that has the stutter problem?
     
  10. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    129
    Is it possible to create a video demonstrating this bug and send to me via PM? Just want to make sure we are talking about the same thing..

    I also tried to downgrade to 5.3, but no success. Sometimes I have the same stuttering just hitting play directly on audio file on inspector...
     
  11. LudoSmith

    LudoSmith

    Joined:
    Oct 27, 2010
    Posts:
    5
    Any updates on this? I am in the same position - I already patched my project, users complain for stuttering audio, and I cannot revert back.... seriously Unity engineers... what are you doing???
     
  12. vicenterusso

    vicenterusso

    Joined:
    Jan 8, 2013
    Posts:
    129
    Yep, I'm still waiting for any news too..
     
  13. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    As am I.
     
  14. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,142
    It's still waiting for QA reproduction. I've given the relevant QA person a prod.
     
  15. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Bump, we're having lots of players complain about the audio stuttering, it is really embarrassing. As a reminder, this issue was introduced in 5.4.
     
    vicenterusso likes this.
  16. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,142
    It seems we are still waiting for the people who reported 809727 to get back to us with more information, as we've not yet been able to repro it internally.

    If you can repro it reliably, I recommend filing a new bug with your project and repro steps attached, and mention in the bug description that it might be related to 809727.
     
  17. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    I don't have a repro project yet, but in the meantime, here's a quick video clip of how the problem looks like in action, in our full project:
    http://thelo.ca/FS-SoundStutter/FS-SoundStutter.html

    In that clip, the stutter starts around 0:09, but gets really bad around 0:30 (round 7). It persists for about two minutes, healing around 2:20.

    I believe it's only happening on the Windows build, not on the Mac build, if that's a clue.
     
  18. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
  19. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Interestingly, I tried putting heavy load on the machine on purpose (looping useless Debug.Log lines, loading up other heavy programs on the computer), and it didn't seem to affect the occurrence of the stuttering at all.
     
  20. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Here's an update: I just saw the stutter-period happen while playing an audio clip in the inspector, not even while playing our project. It lasted a couple minutes before healing itself. So this means it's not even related to whatever is happening in our project, I suppose?

    Edit: A profiler snapshot of the editor during this:

     
  21. Matti-Jokipii

    Matti-Jokipii

    Joined:
    Apr 24, 2015
    Posts:
    15
    Peter77 likes this.
  22. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Thanks! It would make sense that it's related to the garbage collector actually. That could explain my failure so far to reproduce it in simpler repro projects, even if I constantly get the problem in my huge main project.
     
  23. Matti-Jokipii

    Matti-Jokipii

    Joined:
    Apr 24, 2015
    Posts:
    15
    Yes, i found that the time GC takes during an allocation of a new object in a script depends on the number of previous exising allocations. This number typically grows during the session in an app. It took about half an our of normal use before the dropouts started on the app i'm working on. Was a bit of a pain to hunt down. :)

    Surprisingly it's not that much of the total amount of allocated memory, but the number of objects. It's easy to reproduce by creating a large number of objects in a script at the start of your app and just holding a reference so that they remain allocated. The objects need not even be accessed as long as you hold the reference.
     
  24. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Hmm, actually, I think your issue and mine might be separate. The stutter issue I have happens on Windows, but not on Mac or PS4, while yours happens on Mac. And the stutter issue I have did not exist prior to 5.4, while yours does.

    Also, I just tried reproducing it through the GC hypothesis by creating and holding a large amount of junk data (deactivated instances of a cube, small C# dictionaries, a few hundred thousand of each) while playing a constant sound in the background, in a repro project, and I failed to reproduce the stutter issue on my Windows machine in 5.4.2f2, hmm.
     
  25. Matti-Jokipii

    Matti-Jokipii

    Joined:
    Apr 24, 2015
    Posts:
    15
    Good to know! Thanks! Just for the record, mine is on iOS with IL2CPP compiler. I'm not sure if it occurs on Mac.
     
  26. Itooh

    Itooh

    Joined:
    Nov 11, 2016
    Posts:
    2
    For the record, I might have the same issue as well. As I described here, it appears only on Windows. I've been able to "correct" it by setting DSP Buffer to Good Latency, but… "surprisingly", it creates latency! So that's not really a solution.
    The version I'm using is Unity 5.5.0xb2.

    I recently realized that I was using .ogg files. I could try .wav, just to see if it changes anything… Other than that, I'm also out of idea.
     
  27. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Wow, it looks like setting the DSP buffer to "Good latency" (512) rather than "Best latency" (256) really does fix the stutter problem on Windows, from my initial testing!!
     
    Last edited: Jan 25, 2017
  28. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    777
    The issue with audio stuttering when using a small buffer size has been there for a long time. Are you sure it was working with 5.3? I noticed it long ago, I think I was using 5.3 at the time.
     
  29. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Yes, for sure. I had 5.3.3p3 and 5.4 builds of the project, and 5.3.3p3 had no stutter while 5.4 did. Our users also noticed it at the time of the change. A user above says that 5.3.6 introduced the problem, where 5.3.5 didn't have it.
     
  30. moshangmusic

    moshangmusic

    Joined:
    Jul 16, 2015
    Posts:
    9
    Thelo and Peter77 like this.
  31. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    Thanks, that does describe the stutter bug well.

    I would just add that you don't need to switch the DSP buffer size at runtime to have stuttering audio, you just need to have it set to low latency to start with.
     
  32. moshangmusic

    moshangmusic

    Joined:
    Jul 16, 2015
    Posts:
    9
    Right, my actual bug report was clear on the fact that it happened in the editor as well as built projects, but was rewritten by the person who added it to the issue tracker. I've added that fact as a comment.
     
  33. moshangmusic

    moshangmusic

    Joined:
    Jul 16, 2015
    Posts:
    9
  34. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    524
    For the record, I'm seeing this exact issue right now and I'm using Unity 2017.3.b8

    Been fighting this issue for many days.
     
  35. Thelo

    Thelo

    Joined:
    Sep 13, 2009
    Posts:
    98
    To avoid this problem, we've had to use the DSP buffer size "Good latency", rather than "Best Latency" which is unusable these days.
     
    ilmario likes this.
  36. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    524
    Yeah, I'm going to try that tonight... really hope it works. Like I said above. I've been haunted by the lagging background music for many days. Tried everything.... except this DSP buffer size work around.

    -Jeff
     
  37. moshangmusic

    moshangmusic

    Joined:
    Jul 16, 2015
    Posts:
    9
    Frustratingly it's been marked as "won't fix" a second time. Sadly "good latency" is not good enough for our use case.
     
  38. barcode802

    barcode802

    Joined:
    Apr 6, 2014
    Posts:
    26
    Yeah - this is really frustrating...
     
  39. propeller

    propeller

    Joined:
    Jul 2, 2012
    Posts:
    200
  40. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,120
    In 2018.1b13, my Windows build still have horribly glitched sound with "Best Latency". All other platform (macOS, iOS, Android) can deal with Best Latency. (Or if you want better than the best latency you could use native methods, I have made a plugin for iOS and Android)

    I guess since Unity disallow us to specify a number of byte directly as a buffer size this is supposed to magically get the right number for you. Unfortunately it might have guess wrong number on Windows and "Good Latency" is actually just enough to not get a glitched sound. Every platform will do fine with Best Performance, however audio latency might be unbearable. (esp. game like music games, or FPS where shooting sound does not match up with your gun's animation etc.)
     
    Last edited: Jun 6, 2018
  41. almo

    almo

    Joined:
    Jul 14, 2010
    Posts:
    83
    same problem Unity 2017.4.2f2

    I set "Best Performace", seems to work properly now.
     
    Last edited: May 13, 2018
  42. metroidsnes

    metroidsnes

    Joined:
    Jan 5, 2014
    Posts:
    63
    I had the same problem (i.e. audio clicking, jittering and slowing down) in my game project (Unity 2017.4.4f1). I noticed that, after starting Unity I could play audio files from the Project window with no problems but after going into play mode (where these problems occur) and back, playing audio clips from the Project window resulted in having background clicking sound.

    Changing DSP Buffer Size did not help until editor restart. Now I'm using Good latency setting and it's much better (although not perfect) (increased latency is not much of a consideration for my project).
     
  43. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    5,577
    We have 2018.3 now (and alphas and beta of 2019), and this is still a thing.

    Unity says "won't fix" ( https://issuetracker.unity3d.com/is...-size-is-changed-to-best-latency-in-play-mode ) and the developer said
    My question is : Is there ANY Windows setup anywhere where best latency does not produce stuttering in the editor in new versions of Unity? It used to work. Now it doesn't. But somehow it's not a regression.

    I have tried it in multiple different Windows machines, from high end to low end ones and it stutters like crazy even with an empty project, and yet somehow it's not a problem with Unity's implementation?
     
  44. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,120
    Note that in the latest alpha (2019.1.9b4) now Best Latency glitched in the Editor as well. I used to be able to work in editor without problem on this MacBook Pro Early 2015 (maxed out CPU). Now I need at least Default/Good Latency to be able to work and not have an audio glitch/slow down/went offsync.

    (The case : https://fogbugz.unity3d.com/default.asp?1118164_ip87hse66aelc9od which the dev says the solution is to "just change to Default")

    Also I have never found any Windows machine that could handle Best Latency. Maybe we should debug what is the actual buffer size that is the edge that Windows can handle. (AudioSettings.GetConfiguration() -> AudioSettings.Reset(newConfig) )
     
  45. ReaktorDave

    ReaktorDave

    Joined:
    May 8, 2014
    Posts:
    103
    I've had dropout issues when using OnAudioCustomFilterRead(), because that pipes affected audio streams from the separate FMOD-Thread into the Main-Thread and back to the FMOD-Thread, causing glitches depending on how heavy the game is running (so glitches were completely unrelated to the audio load). I fixed that by gedding rid of the custom C# DSPs and created native C++ audio plugins wherever I could.

    Apart from using OnAudioCustomFilterRead(), I never had a single issue with dropouts on my i7-3770 (from 2013) with projects using about 500+ available AudioSources (40 playing simultaneous).
     
  46. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    5,577
  47. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    5,577
    Dear Unity:

    We want to build for iOS and Android with Best Latency. It works fine there.

    But that means we CANNOT preview audio in editor, because you broke it. It used to work.

    I don't want to add more steps to our build process, it's already complicated.

    There is no Windows Machine were best latency works that I have scene, the problem is on your end.