Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Audio.FMODSystemUpdate occasionally does SyncRequests on main thread causing sound to stutter [2022]

Discussion in 'Audio & Video' started by love_wessman, Nov 21, 2023.

  1. love_wessman

    love_wessman

    Joined:
    Jun 26, 2023
    Posts:
    7
    upload_2023-11-21_17-55-39.png
    I've noticed that audio occasionally stutters. It only happens when the game is already running at low FPS, and only when using (at least some) assets set to streaming in their import settings. When I look in the profiler, the culprit appears to be Audio.FMODSystemUpdate - most frames, this is only doing some audibility calculations, but every now and then it does a syncRequest which causes the audio to stop playing briefly, which is experienced as a kind of stuttering. I feel like this should be happening on another thread, not the main thread, but I could be wrong here. This did not happen in Unity 2020, and only appeared when we moved to Unity 2022. I'm not sure how to prevent this from happening. Setting all audio to non-streaming is not feasible due to memory limitations. We can increase the amount of Max Real voices in the audio settings to make it rarer, but ultimately we want a solution where the audio will never stutter in this kind of situation. Afaik I can't affect what's going on here, it appears to be Unity's own code, but maybe there is something I can do?

    One idea I have is to dynamically activate objects playing audio depending on their distance to the player and if the number of audio objects exceeds the limit of "max real voices" I start disabling those furthest away to avoid them being loaded in and out of memory and then loaded from disk if they're needed again - basically force the game to always be below the number of max real voices. If my assumptions are correct, I think this would work, but it feels kind of hacky, especially since it's something that used to work flawlessly before.

    (I tagged this as a bug, in case it actually is a bug, but it's also a question)
     
  2. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    380
    I will discuss this with the team and give you some feedback when I can.

    Cheers!
     
    love_wessman likes this.
  3. love_wessman

    love_wessman

    Joined:
    Jun 26, 2023
    Posts:
    7
    Hi there, any updates on this? :)
     
  4. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    380
    Hi!

    Thank you for poking :)

    There was this discussion here about the cost of Audibility Computation, for which Nis does have a fix. It "just" needs to go through the release grinder now.

    Cheers!
     
    love_wessman likes this.
  5. love_wessman

    love_wessman

    Joined:
    Jun 26, 2023
    Posts:
    7
    Thanks a lot for the update :)

    I just tried this again on 2022.3.18, which according to the release notes here: https://unity.com/releases/editor/whats-new/2022.3.18 it says:
    • Audio: Fixed performance issue that would occur when having many inactive audio sources in a scene. (UUM-52194)
    So, it seems like this should have been fixed (unless I am mistaking the fixed issue above, for another similar, related issue that I'm having) - however, I am still able to reproduce the same behavior that I described above, even when running 2022.3.18. So I'm wondering if maybe the thing I'm encountering is something else?

    In any case, there is some slightly different behaviour that I am seeing after updating to 2022.3.18: Rather than seeing several different instances of "AsyncReadManager.SyncRequest" and "Audibility Computation" as I do in the image above, there is now just one entry for each of those per frame, as can be seen in this image (perhaps it's relevant, perhaps not):
    upload_2024-1-23_18-50-1.png
    But, as you can see we are still getting these quite-large lagspikes where the FMODSystemUpdate takes much longer than usual (most frames it's just a couple hundredths of a millisecond, even with tons of both inactive and active audio sources), and these lagspikes result in the audio stuttering.
     
  6. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    380
    Looking at the issue tracker it looks like it's still being reviewed for the 2022 version. This is part of our "backport" process, where fixes made on the latest version are adapted by another team to be merged in LTS versions. Don't hold your breathe as this can sometime take a few weeks. These guys are heroes, but still they have to handle a massive volume!
     
    love_wessman likes this.