Audio Memory Allocations

Here are some tips and facts on Master Audio memory allocation usage and optimization. Master Audio has been highly optimized for allocations / garbage collections and uses 0 bytes for most uses. When not using an "AndForget" method to play Sound Groups, only 16 bytes will be allocated. This means it's extremely stable and lightweight and can be safely used on mobile without eating much of your resources.

 

First off, make sure to read the Audio Origin page fully to understand the next sections.

Unless you are using Addressables, Resource Files, turn off "Preload Audio Data" on some Audio Clips' import settings, or enable / disable Dynamic Sound Group Creator game objects in the Scene, then the amount of memory used by Master Audio will remain constant per Scene. It's not dynamic. So all Sound Group Variation Audio Clips (that aren't Addressables, Resource Files or have Preload Audio Data off) are loaded into memory when the Scene starts. The same goes for all Playlist clips that are set up the same way. Extra clones of Variations take up zero memory because they're the same Audio Clip. Playing a sound does not make the audio memory change, unless it's an Addressable, Resource File or the Audio Clip has Preload Audio Data off in which case the memory increases only during the time it plays.

 

Typically, to optimize memory usage, we do the following:

     
  1. If the target platform is mobile, we resample all Audio Clips to 22050Hz so they're smaller. We can't tell the difference in sound. For pure speech sounds, you can get away with an even lower sample rate. We use .wav files for all sound effects, although some users report success with .ogg files as well.
       
    • Make sure to NEVER use mp3's, compressed audio or "stream from disc" for sound effects (Sound Group Variations). A single call to AudioSource.Play() with an mp3 file will take about 2.4 ms. Whereas AudioSource.Play() with a wav file takes about 0.02 ms. That's 120 times faster! It can drastically affect your frame rate if you have a lot of sound effects playing! For Playlists it's fine to use mp3's because you don't fire off many each second like you do with sound effects.
  2.  
  3. Set all music clips to compressed and streaming which takes up very little memory (although the Profiler many not show this correctly when running inside Unity - make sure to run Profiler against the build on the actual target device). But don't stream more than one Audio Clip at a time, as it is terrible on performance.
       
    • Sometimes large streaming clips can cause performance hiccups in Unity when the next streaming song starts playing. If you are having a spike in performance, try turning off streaming and/or using Addressables / Resource Files or turn off Preload Audio Data on the Audio Clips instead.
    •  
    • If you have more than a couple music clips, it's usually best to set up all music clips as Addressables or Resource Files, or turn off Preload Audio Data on the Audio Clips instead to compare audio memory usage. It may use far less memory (as well as drastically speed up Scene loading), especially with layered music. Note that if you want perfect gapless song transitions, Addressables or Resource Files are recommended.
    •  
    • Be wary of using streaming if you have layered music (i.e. more than one music audio track playing at a time with multiple Playlist Controllers) as it's quite bad on performance and memory, depending on the platform. You might even run into the dreaded "Streaming system overload".
  4.  
  5. Set up infrequently used sounds in an Addressable or Resources folder and configure the Audio Origin accordingly so they will be loaded only when played and promptly unloaded after done playing.
       
    • Unity has a slightly easier alternative of turning off Preload Audio Data on Audio Clips. It defaults to on. If this is unchecked, Master Audio will automatically load the audio data when the sound is played, then unload it after it is done. Unless you need Localization (which only Resource Files support), it may be easier to just turn Preload Audio Data off.
    •  
    • Unity also has an option for "Load in background" which is supported with Master Audio and can help things load over several frames if they need to. This may introduce audio latency for the particular audio but it will keep your frame rate good.
  6.  
  7. If you only need certain sounds in certain Scenes, set up a separate Master Audio game object per Scene only with needed sounds, or use the Dynamic Sound Group Creator game object to populate those sounds in each Scene if you have a "persist across Scenes" Master Audio.
  8.  
  9. Only use Filter effects on Unity Audio Mixer Groups, and not on individual Variations. It will save a lot of memory.
  10.  
  11. Each "clone" of a Variation (from Voices > 1) takes up zero audio memory due to extensive audio optimizations in the new audio engine since Unity 5.
 
Note: Resource Files have a hard limit of 4GB and if you go above that, you will need to use a different option. Addressables wraps up Resource Files and are our recommended option of the 3 except for the most often played sound effects.