📜 ⬆️ ⬇️

Optimize game performance with Unity sound import options

image

Developers usually do not fully understand the sound import options in Unity, and at the time of this writing, I could not find a single detailed guide on how to use them. The Unity documentation describes well what sound import options do, but I would like to parse these descriptions for a wider audience, as well as explain in more detail how to use these settings to squeeze maximum performance out of the game.

This document is divided into five parts:

  1. How sound affects performance
  2. Understanding Import Options
  3. My recommended options for PC and consoles
  4. My recommended options for mobile platforms
  5. Warnings and notes

Optimizing audio import settings Unity is one of the easiest ways to optimize. In the case of a small project, it can take you less than an hour to achieve significant improvements in load time, busy RAM, and other aspects of performance. Hope this guide is helpful to you. Information relevant to Unity version 2018.3

1. How sound affects performance


Sound data are voluminous. In many games, audio data takes up the lion's share of disk space (disk / cartridge / optical disk space where game data is stored) and RAM (the system's working memory). But moreover, they also seriously burden the CPU, especially if you use the effects of DSP (real-time audio processing), and also greatly increase the boot time.

In these three areas (disk space occupied by RAM, CPU utilization), optimization is a three-way over-pull of the rope, similar to the “good-cheap-fast” problem. If any of the aspects of the game cause you the most damage, you can save the effectiveness of one aspect by sacrificing the other. For example, if an uncompressed sound takes up too much RAM, you can store it in a compressed Vorbis form - this saves space in RAM, but at the cost of CPU load, because accessing a compressed file requires more computational power to decode it. Below is a diagram with different parameters and their influence on these three areas:


It is worth considering that this diagram does not tell us anything about the bandwidth of the data read from the disk / RAM.

In reality, the nuances are a bit more, but the diagram should give you a general idea of ​​how these problems are interconnected. To understand how to use these parameters (and cope with problems such as too long loading times), you need to take a closer look at each of the sound import options.

2. We understand the import options


When you select AudioClip in the Unity editor, the following panel appears in the inspector window:


Below is a list of sound parameters from top to bottom with a description of what they do:

Force to mono



In my work as a sound designer, I never reduce an audio signal to mono, because I create sounds for a specific purpose. But if you use standard sounds from drains and want to enable this parameter, then make sure that the mono file does not sound flat and strange because of the interfacial interaction of the left and right channels. You can preview the processed sound by clicking the Play button in the lower right corner of the inspector window - if you hear phase distortions, you can try to split the sound in a third-party audio editor and separately export the left and right channels as mono sound.

Normalize (available only with Force to Mono enabled)



If you use Force to Mono, then usually it is worth turning on normalization. A loud stereo file, when mixed in mono, can become even louder, exceed the maximum amplitude and lead to a sharp digital distortion, which is undesirable.

Load in Background / Preload Audio Data


These parameters have a direct impact on each other, so I combined them.
Load in backgroundPreload audio dataResult
EnabledEnabledWhen loading a scene, audio clips with this parameter begin to load, but do not stop the main stream. If by the time the scene is fully loaded, not all of them are loaded, the download will continue in the background when the scene is already running. If the sound is not loaded, but already started, then it will behave in the same way as when Preload is disabled (see the line below).
EnabledDisabledWhen the sound starts for the first time, it will load in the background and play when it is ready. If the file is large, then a noticeable delay may appear between the launch and playback, but on subsequent playbacks of the file everything will be fine.
DisabledEnabledThe sound is loaded in the process of loading the scene. The scene will not start until all sounds with this parameter are loaded into memory.
DisabledDisabledWhen the sound starts for the first time, it uses the main stream to load itself into memory - if the file is large, it may cause frame deceleration, but on subsequent playbacks everything will be fine.

I recommend using this configuration only for very small files, but even in this case, it is worth measuring its impact on performance in the profiler, and consider whether a large number of such sounds can be launched simultaneously, increasing the load on performance.

Ambisonic



Platform-Specific Parameters



Load type



Compression format



I have listed here only the standard editor formats, for more information about platform-specific types and compression, see below in the Remarks section.

Here is a brief comparison of CPU usage for different formats on my PC in the Unity editor:

Compression formatCPU load with 1 voteCPU load with 6 votes
PCM~ 0.05%~ 0.3%
ADPCM (compressed in memory)~ 0.2%~ 1.0%
Vorbis (compressed in memory)~ 0.5%~ 3.2%

Quality (not applicable to PCM / ADPCM)



These quality parameters mean that the sound will play at a rate of 100%, so they cut some of the higher frequencies that are usually outside the audible range. But when playing at reduced speed, they are shifted down into the audible range. If you plan to play low tones / speeds, it’s best to select PCM encoding.

The lower the quality, the stronger the files are compressed:

Vorbis quality% of original sizeCompression ratio
100~ 20%~ 5: 1
75~ 10%~ 10: 1
50~ 7%~ 14: 1
25~ 4%~ 25: 1
one~ 2%~ 50: 1

Sample Rate Setting




3. Recommended options for PC and consoles


Sound typeLoad in background
Load typePreload audio dataCompression formatQualitySample rate settingRemarks
DialoguesYCompressed in memoryYVorbis70Preserve
Long loops environment soundsn / aStreamingn / aVorbis70Preserve
Single sounds of the environmentYDecompress on loadYVorbis70Preserve
Noise effectsNCompressed in memoryYPCMn / aOptimizeIf the tone of these sounds ever went down, then the sampling rate needs to be kept
Sounds of footstepsNCompressed in memoryYPCMn / aOptimize
Music (long songs)n / aStreamingn / aVorbis85PreserveStreaming may not be suitable if several music tracks are played simultaneously.
Music (short fragments)YCompressed in memoryYVorbis85Preserve
Direct Voices
Y
Decompress on load
Y
Vorbis
70
Preserve
Special effects (SFX, short)
N
Compressed in memory
Y
PCM
n / a
Optimize
If the tone of these sounds ever went down, then the sampling rate needs to be kept
Special effects (long)
N
Decompress on load
Y
Vorbis
70
Preserve
Sounds UI (long)
Y
Decompress on load
Y
Vorbis
70
Preserve
Sounds UI (short)
N
Compressed in memory
Y
PCM
n / a
Optimize

These recommendations are suitable for games where there are up to 10 thousand sound clips. For most sounds, I recommend Decompress on Load, that is, they will be stored in RAM as unpacked audio data. If the total size of the unpacked sound files is more than the limitations you put on the RAM, then for the longest files you can select the Compressed in Memory option. But note that each time you start such a sound, the load on the CPU will increase slightly. The version of these tables in PDF can be downloaded from here .

4. Recommended options for mobile platforms


Sound type
Load in background
Load type
Preload audio data
Compression format
Quality
Sample rate setting
Remarks
Dialogues
Y
Compressed in memory
Y
Vorbis / MP3
50
Preserve
Long loops environment sounds
Y
Compressed in memory
Y
Vorbis
35
Preserve
For sounds without noise, use higher quality.
Single sounds of the environment
Y
Decompress on load
Y
Vorbis / MP3
50
Preserve
Noise effects
N
Compressed in memory
Y
PCM / ADPCM *
n / a
Preserve
Sounds of footsteps
N
Compressed in memory
Y

PCM / ADPCM *


n / a
Optimize
Music (long songs)
n / a
Streaming
n / a
Vorbis
70
Preserve
See below for streaming warnings.
Music (short fragments)
Y
Compressed in memory
Y
Vorbis / MP3
70
Preserve
Direct Voices
Y
Decompress on load
Y
Vorbis / MP3
50
Preserve
Special effects (SFX, short)
N
Compressed in memory
Y

PCM / ADPCM *


n / a
Optimize
If the tone of these sounds ever went down, then the sampling rate needs to be kept
Special effects (long)
N
Decompress on load
Y
Vorbis / MP3
50
Preserve
Sounds UI (long)
Y
Decompress on load
Y
Vorbis / MP3
50
Preserve
Sounds UI (short)
N
Compressed in memory
Y
PCM / ADPCM *
n / a
Optimize

* If you do not know what to choose, PCM or ADPCM, then see the above description of the ADPCM format in the “Understanding the Parameters” section . If saving disk space is not yet desperately needed, then I recommend leaning towards PCM.

These recommendations will work well in most mobile games; at least they can be used as a starting point. If you think that these parameters may not be suitable for your game, then read the full description of the parameters above. The version of these tables in PDF can be downloaded here .

5. Cautions and notes


Cautions






Remarks


Compression formats:


Miscellanea:

Source: https://habr.com/ru/post/437474/