Unity Audio Import Optimisation - getting more BAM for your RAM

Jan. 7, 2019
protect

Edit: gave more nuanced advice on ADPCM, added some details that were missing, re-phrased some unclear wording, and fixed a mistake in the Venn diagram that erroneously listed Uncompressed on Disk as being a low-RAM option. Also added link to PDF version of the recommended settings tables.

Unity's audio import settings are not widely understood in their entirety, and at the time of writing, I have been unable to find any comprehensive guides to their use. Unity's documentation does a pretty good job of describing what its audio import settings do, but I would like to break these descriptions down for a wider audience, and give some more detail on how to use these settings to get better performance out of your game.

This document is divided into five parts:

Optimising your Unity audio import settings is one of the easiest wins for optimisation, and depending on the scale of your project, should take you less than an hour to achieve significant improvements in load times, RAM use, and other areas. I hope this guide will be of use to you. Info is current as of Unity version 2018.3

 

1. How audio affects performance

Audio data is big. For many games, sound data can take the lion’s share of disk space (the drive/cartridge/optical disc/etc that the game data is stored on) and RAM (the working memory of the system). As if this weren’t bad enough, it can also take a strain on the CPU - especially if you’re using DSP (runtime audio processing) effects  - and significantly increase load times.

For three of these areas (disk space, RAM use, CPU use) optimisation is a triangular tug of war, like the good-cheap-quick problem. Depending on which area is causing your game the most trouble, you can save efficiency in one area by sacrificing it in another. For example: if your raw audio is taking up too much RAM, you can store it compressed as Vorbis instead – this saves RAM space at the cost of the CPU, since it takes processing power to decode the compressed file when it is accessed. Below is a diagram of different settings and how they affect these three areas:

Compressed_20audio_20resource_20use_20Venn_20diagram_20(fixed).png

Please note: This diagram tells us nothing about the bandwidth of data being accessed from the disk/RAM.

In reality, it’s a little more nuanced than that, but this should give you a general idea of how these issues are interconnected. To understand how to implement these settings (and tackle problems like extended load times), we need to look at each of the audio import settings in detail.

 

2. Understanding import settings

When you select an AudioClip in the Unity editor, you are greeted by this panel in the inspector window:

AudioClip_20inspector_20screenshot.png

Below is a list of the audio settings from top to bottom, and what they do:

Force to Mono

  • Yes: if AudioClip is in stereo (or another number of channels), downmixes all channels down into mono.

  • No: does not modify channel count.

As an audio designer, I never force to mono, because I create sounds for purpose. But if you are using stock assets and want to enable this setting, be careful to check that the mono-summed file doesn't sound thin and weird because of phase interactions between the left and right channels. You can preview the processed sound by pressing the Play button on the bottom-right of the inspector window - if you are getting phasing issues, you may want to pull the sound apart in an audio editor and export just the left or right channel as a mono sound.

 

Normalize (only applicable if Force to Mono is enabled)

  • Yes: readjusts the gain of the AudioClip so that the now-mono sound is the same volume as the original stereo file.

  • No: does not readjust the gain.

It is usually advisable to enable normalization if you're using Force to Mono. A loud stereo file when summed to mono can be even louder, going above maximum amplitude and causing hard digital clipping, which is usually undesirable.

 

Load in Background/Preload Audio Data

These settings have direct effects on each other, so I'm presenting them together

Load in background

Preload audio data

Outcome

Enabled

Enabled

When the scene is loaded, AudioClips with this setting begin loading but do not stall the main thread. If they have not all finished loading by the time the scene has loaded, they will continue to load in the background as the scene plays.

If a sound that hasn't loaded yet is triggered, it will behave the same as if it had Preload disabled (see immediately below).

Enabled

Disabled

When the sound is triggered for the first time, it will load in the background and play as soon as it is ready. If the file is large, this will cause a noticeable delay between triggering and playing, but this is not an issue for subsequent plays of the sound.

Disabled

Enabled

The audio is loaded while the scene is loaded. The scene will not start until all sounds with this setting are loaded into memory.

Disabled

Disabled

When the sound is triggered for the first time, it uses the main thread to load itself into memory - if the file is large, this will cause a frame hitch, but this not an issue for subsequent plays of the sound.

I would only recommend this for very small files, and even then, make sure to measure the impact this has on performance in the profiler, and consider whether a large number of these sounds might possibly be triggered at once, multiplying the hit to performance.

 

Ambisonic

  • Check this box if the clip has ambisonic-encoded audio. Ambisonic audio is useful for VR, AR, and 360 video etc, but it’s not really germane to this guide.

 

Platform-specific settings

  • These tabs let you specify a default setting and platform-specific settings for the settings below. Some platforms have compression formats that aren’t available on other platforms, and some might just have different hardware that requires you to optimise differently. See Notes below for more on platform-specific compression formats.

  • Make sure to check the platform-specific settings, even if you want everything to use the general settings – Unity may set some platform-specific settings for you automatically. For example, iOS builds may default to “specify sample rate: 22kHz”, which can cause aliasing (a sound glitch introduced by downsampling incorrectly).

JikGuard.com, a high-tech security service provider focusing on game protection and anti-cheat, is committed to helping game companies solve the problem of cheats and hacks, and providing deeply integrated encryption protection solutions for games.

Read More>>