Understanding Audio Compression Settings in Unity

Made Indrayana
8 min readApr 15, 2020

--

Today we’ll be talking about audio compression formats in Unity’s Audio Import Settings and why setting the right compression type is important for your game.

Compression formats? Just squash it to death and be done with it. It worked for Metallica, right?

Editor’s Note: Compression Formats, Load Type and the Preload Audio Data/Load in Background settings go hand in hand. We recommend reading our blog posts on all three in the following order for a complete overview:

Blog 1: Compression Formats (this post)

Blog 2: Load Types

Blog 3: Preload Audio / Load in Background (coming soon)

This blog post has been made as a supplement to our video tutorial on this same topic.

Introduction

I don’t think we need to go over the general concept of file compression in detail. We compress files to make them smaller and easier to store. In our case, we want to store audio data in our game in a way that makes it as small as possible without degrading the audio quality more than necessary or leading to performance issues.

There are several different compression formats available in Unity. If you develop for computers, you will likely recognize them: The standard options are PCM, ADPCM, and Vorbis. Some platforms have other options available, such as MP3 for mobile.

Let’s take a look at the first option, PCM.

Lossless Formats (PCM)

PCM is short from Pulse Code Modulation and it is a lossless, uncompressed codec and format. Theoretically, this doesn’t really qualify as “compression”, as this is a standard for uncompressed audio formats in the professional audio world.

Speaking only of the quality, PCM is the best format for audio as it retains everything from the original audio content. It also requires almost no CPU processing to play in Unity because it requires no decompressing.

As good as it sounds, its strength is also its Achilles’ heel.

Because no compression is taking place, the audio retains its original size. This big size is a big disadvantage, as having many uncompressed audio files can quickly lead to a large increase in the size of your build. The devs (and players) are not going to be very happy about this, especially if you’re developing for mobile.

One side note on PCM is that Unity seems to be doing its own kind of lossless compression on some audio files. For example, with this file I have PCM selected but it is nonetheless compressed to 66%.

With this other example, however, it stays at 100%.

We couldn’t find any reliable documentation on how or why Unity is doing this, but it seems that the audio stays lossless in spite of what appears to be compression.

Before moving on to the various compressed formats, let’s take a closer look at a term I mentioned at the beginning of this blog: codec.

What is a Codec?

The word “codec” is a portmanteau for coder-decoder.

I’ll cite Wikipedia here:

“In software, an audio codec is a computer program implementing an algorithm that compresses and decompresses digital audio data according to a given audio file or streaming media audio coding format. The objective of the algorithm is to represent the high-fidelity audio signal with minimum number of bits while retaining quality. This can effectively reduce the storage space and the bandwidth required for transmission of the stored audio file.”

In the audio world, PCM, ADPCM, Vorbis, MP3, M4A, and many others, are all examples of audio codecs.

Audio codecs have different methods of compressing audio data. PCM happens to be the one that does not “compress” in the normal sense, but rather in terms of storing data digitally.

All other formats such as MP3 and Vorbis compress the audio data with their own algorithms, resulting in much smaller file size. However, this means that they do not retain the full quality of the original PCM audio, like file compression in your operating system would. Once compressed, you cannot restore the lost details through the decoding/decompressing process. This puts them into a new category called lossy compression.

Lossy Formats (ADPCM, Vorbis, MP3)

In Unity, depending on what platform you are developing, you can choose from a wide variety of lossy compression formats.

Different lossy compression formats are available depending on what platform you’re developing for.

Let’s take a look at ADPCM first.

ADPCM Compression

ADPCM is short for Adaptive Differential Pulse Code Modulation. From the name alone you might get the impression that this format is also one of the lossless codecs, like PCM. In reality, it is not.

ADPCM’s algorithm offers a fixed ratio of compression in Unity, which results in a file around 3.5 times smaller than the original PCM audio.

We’ll use this piece of music from our personal royalty-free library to demonstrate. As PCM, it is already compressed to 66,66% of its original size.

With ADPCM, it drops to 18,75%, which is roughly 3.5 times smaller.

Advantages & Disadvantages:

What is the advantage of ADPDM compression? Like PCM, the cost of decompressing or decoding this codec is very light, just a tad more in comparison to PCM in exchange for a greatly reduced file size.

The disadvantage of this format is the compression method itself. The way ADPCM compresses audio data can occasionally cause distortion, or “extra noises”, that weren’t there in the original file.

For the nerds, this is called quantization distortion.

How much quantization distortion, or extra noise, is introduced depends on the frequency content of the original audio file. Let’s take a listen to this example:

ADPCM Example — SFX Pre-Compression
ADPCM Example — SFX Post-Compression

When we convert this sound effect to ADPCM, we suddenly hear something that wasn’t there before.

Let’s have a listen to a different example. This time, we’ll use a dialogue example from a game we worked on, Leisure Suit Larry:

ADPCM Example — Dialogue Pre-Compression
ADPCM Example — Dialogue Post-Compression

In this case, there is no audible difference between pre- and post-compression.

In our personal experience, this quantization distortion occurs more often with files containing lots of high-frequency content. Because of this potential for unwanted noise, our advice would be: always double-check the resulting audio file when you use ADPCM.

Vorbis Compression

According to the Vorbis website, Vorbis is a fully open, non-proprietary, patent-and-royalty-free, general-purpose audio format. It is a very efficient audio codec that offers high-quality lossy compression.

When we select the Vorbis option in Unity, we also have a quality slider. This allows us to decide how much we want to reduce audio quality which will, of course, also reduce the size of the file.

Interestingly, if we go back to our royalty-free music file for a quick comparison, Vorbis with 100% quality is actually bigger than ADPCM.

With ADPCM our file is just 18% the size of the original
With Vorbis 100 our file is nearly 21% the size of the original

Let’s see what happens to the file size when we reduce the quality to 70%:

How about 40%?

What happens if we bring it all the way down to 1%?

Advantages & Disadvantages

Vorbis actually does an impressive job of reducing file size while retaining sonic quality in the audio data that it compresses. This is great for our game because it reduces file size without compromising too much quality.

The downside to this is that it requires significantly higher CPU resources to decompress the audio for playback.

By default, Unity sets all audio assets to Vorbis. At first, this seems like an attractive setting because all the files are much smaller. However, this combination requires a lot of precious CPU resources for decompression and makes load times significantly higher.

MP3

MP3 is another efficient audio codec for lossy compression which most of us have probably heard of.

In many ways, MP3 is similar to Vorbis. It can compress audio to a very small size without much loss in quality.

One major difference between MP3 and Vorbis is that MP3 cannot loop seamlessly. If you want a sound in your game to loop, such as music or ambience, this is something you need to be aware of.

Generally, we recommend choosing Vorbis over MP3 when possible because Vorbis offers more efficient coding at the same bitrate, meaning you will get more quality for the same file size.

Listening Examples

OK, that was a lot of theory. Let’s do a little listening to compare the effects these different compression formats have on our sound effects.

Each of the following examples changes compression format when it loops. The formats change in the following order:

PCM, ADPCM, Vorbis 70%, Vorbis 40%, Vorbis 10%, and Vorbis 1%.

Final Words

Let’s summarize what we’ve learned about the Unity’s standard audio compression options:

  • PCM is lossless compression and, while light on the CPU, has a much larger file size
  • ADPCM has a fixed compression ratio of about 3.5 and, while a good compromise between PCM and Vorbis/MP3, can sometimes cause unwanted noise (quantization distortion) in audio files with lots of high-frequency content
  • Vorbis is a very efficient audio codec that offers high-quality lossy compression but requires more CPU resources for decompression
  • MP3 also offers high-quality lossy compression but causes problems for audio assets that should loop

Generally, as sound designers, we always recommend audio to stay uncompressed as a PCM file wherever possible but we also know that this is nearly impossible to do in game development because of space and performance requirements.

How do we choose which compression format to use for our audio assets? We’ll discuss some recommendations in the next tutorial because this decision is also dependent on Unity’s Load Type options as well as the Preload Audio Data and Load in Background settings.

Link to our “Load Type” and “Preload Audio Data/Load in Background” blog posts coming soon

That’s it! We hope this tutorial has helped you to understand the difference between audio compression formats in Unity’s Audio Import Settings and why setting the right compression type is important for your game.

If you want to learn more about how audio functions in Unity, be sure to check out our other tutorials (linked below). If you have a question, leave it in the comments or contact us directly through our website:

--

--