Search Unity

Question Audio Compression Best Practices

Discussion in 'Audio & Video' started by GameDevSA, Feb 8, 2024.

  1. GameDevSA

    GameDevSA

    Joined:
    Dec 12, 2016
    Posts:
    252
    I've been trying to work out best practices for audio compression, but my Googling has not come up with a clear answer. I'm curious if anyone has some best practices they can recommend?

    upload_2024-2-8_22-47-14.png

    These are my settings. I have noticed that trying to load too many music files at the start of the game is causing a lag on boot time, so, one solution is possibly to look at something like Addressables, I've been told. But, I was wondering if anyone had any recommendations of compression for performance? It's important I want to keep the quality of the music tracks quite high.

    As best I can tell, Vorbis seems like the best compression format for me, but I cannot tell what load type would be ideal, especially bearing console in mind, and whether to leave the quality at 100, or if I could lower it and still have something decent?

    I did try out the ADPCM and I did not like what it did to my music at all.

    At the moment I've just had all the music files in the games as public variables on a "Sound Manager" object, which has not created performance issues on my PC, but I am seeing some older devices have a longer boot time for it.
     
  2. JLF

    JLF

    Joined:
    Feb 25, 2013
    Posts:
    139
    OGG should work well for you in most situations, however, if you want to know more about what's going on behind the scenes, I wrote an article on audio optimisation in Unity a few years ago now, which includes a section on compression vs load type: https://gamedevbeginner.com/unity-audio-optimisation-tips/#audio_load_types

    Looking at your screenshot, you may want to try enabling Load in Background. This loads the audio asynchronously, meaning your boot time should be faster, at least in terms of how long the application hangs while loading. Alternatively, you can manually load and unload the audio data you need to reduce how much is loaded at any one time. Unchecking preload audio data means that the clip is referenced, but the data isn't loaded. Unity will usually load this on demand, or you can manually load it in advance.

    Alternatively, for long files, the streaming load type can be good for music files, as it removes most of the memory overhead and loading times at the cost of increased cpu usage.

    Hope that helps!
     
    GameDevSA and spiney199 like this.
  3. GameDevSA

    GameDevSA

    Joined:
    Dec 12, 2016
    Posts:
    252
    That information sounds very helpful, thank you! I used to use OGG files in another engine, but hadn't realised they could be better than mp3. I can see looking at the two, OGG is slightly smaller. Does OGG have any other benefits?

    I actually just came across an interesting post when I was investigating looping sounds better, and saw that mp3 files add a moment of silence at the start and end of a file, so it sounds like OGG are better for looping too. I tested it out and it was definitely true.

    I did read about streaming, but the mention about extra CPU usage made me pause. Hardware and CPU usage is not my strong area. Do you think it will make any noticeable impact to stream background music or lower powered devices?

    Also, do you think "Load in Background" is safe to use for sound effects, like, a player bumping into a wall, or could that cause delays?

    I've had a look through your article and that is very helpful, thank you. The "Load in Background" point you make makes me wonder if there are similar benefits out there for sprites? I've got a separate post on that if you had any tips in that regards: https://forum.unity.com/threads/sprite-compression-best-practices-recommendations.1545320/
     
    Last edited: Feb 9, 2024
  4. GameDevSA

    GameDevSA

    Joined:
    Dec 12, 2016
    Posts:
    252
    Just doing a quick test, I can confirm it more than halved boot time from roughly 50 seconds or just under to around 20-21 seconds, just by adding in "Load in Background", on an under powered device. Still need more gains but that's a huge improvement, thanks.
     
  5. GameDevSA

    GameDevSA

    Joined:
    Dec 12, 2016
    Posts:
    252
    @JLF thanks for your help.

    There seemed to be big delays when I first used Load in Background, I can't remember now if there were performance drops. I was using "Decompress on Load" as my load type, maybe that was an issue?

    upload_2024-3-7_0-21-9.png

    I also originally had "Preload Audio Data" on.

    I have since switched to using addressables for loading the music and background ambience, and got boot time from around 60 seconds down to about 9-10. The sound folder is only 90MB, which is weird, because that was a huge gain (on what I can only assume not was an underpowered console). But, addressables left me with a hitch - graphics rendering stopped for a half second to a second, maybe more, when loading the music.

    Someone pointed out to me that a different load type might be better for the overhead of loading audio, when using addressables. So, I switch to ""compressed in memory" for music. This removed all my performance issues. I also use "Streaming" for sound effects.

    I now wonder whether "load in background" plus "compressed in memory" may have been able to achieve the same result without learning how to use the addressable system, worth trying for anyone else looking at this, but it runs super silky smooth now.
     

    Attached Files: