How Does Audio Compression Work, and What Is “Lossless” Audio?

How Does Audio Compression Work, and What Is “Lossless” Audio? Featured Image

Just this week, Spotify began testing “lossless” audio files. But what is “lossless” audio, exactly, and how does digital audio compression work?

How Does Audio Compression Work?

audio-compression-rackmount

The goal in audio compression is to reduce the number of bits required to accurately reproduce an analog sound. The first process we’ll look at is called “lossy.” Lossy compression is a one-way technique that throws away non-critical data to save space. These techniques are the most common methods used to compress audio files, showing up in MP3, AAC and WMA files alike. There are two places that lossy codecs look to save bits: bit rate and psychoacoustics.

Bit Rate

audio-compression-quantized-signal

Bit rate measures the amount of bits used to encode a single second of audio. For example, if we use low-quality, 8 kilobit-per-second (kbps) encoding, our algorithm is limited to using only 8 kilobits of data to describe each second of audio. That’s like trying to describe a full-color photograph with only a few hundred pixels. You might get the broad strokes right, but overall you’ll be looking at a severely degraded image. If we use a higher-quality bit rate like 192 kbps, we have plenty of room to cover nuanced details. To return to our photographic example, we now have enough pixels to describe the various lights, darks and colors in an image. A high bit rate doesn’t determine the quality of a recording on its own, but a low bit rate can severely limit output quality.

Psychoacoustics

512px-psm_v14_d076_auditory_canal_bones

Psychoacoustics is the science of how the brain understands sounds. By manipulating known quirks in the way humans perceive sound, compression algorithms can cleverly remove details that most human ears won’t miss. The goal is to “round off” information that won’t change the perceived audio quality of a track, judiciously removing only unimportant information.

For example, you might know the typical range of human hearing is between 20Hz and 20kHz. Obviously, sounds outside that range can be removed. Furthermore, the most detailed range of human hearing is between 100Hz and 4kHz, and removing quiet sounds outside those frequency ranges does minimal damage to the quality of a recording. We can do a similar trick with highly contrasting sounds. If a very loud sound and a very quiet sound play at the same time, the quiet sound is much harder to perceive than it would be on its own. Encoders take advantage of this “sound masking” to remove the quiet sound, saving bits in the process.

Frequency can also impact how well we perceive sounds. For example, a persistent, low-frequency drum beat tends to drown out the more delicate, higher-frequency harmonics of melodic instruments. And sound masking is especially effective above 15kHz, where human hearing is typically less sensitive to begin with.

Common audio compression schemes like MP3 take advantage of the full range of compression possibilities while attempting to remain as faithful to the original recording as possible. Of course, some folks feel like removing these frequencies does serious damage to the recording. That’s why lossless compression standards exist.

What Is “Lossless” Audio?

audio-compression-headphones

Lossless audio compression’s goal is to reduce file size while leaving the original audio untouched. These codecs don’t use any of the permanent compression techniques above, focusing instead on fully-reversible data compression methods. They use lossless compression techniques borrowed from file-compression algorithms like ZIP to remove redundant data while preserving the integrity of the underlying information. Two popular lossless audio codecs – FLAC and Apple Lossless (ALAC) – both use schemes based on ZIP compression.

Focusing on data compression only means preserving many of the details that MP3 and other lossy standards would obliterate. If you have sharp ears and a high-quality listening setup, the difference can be palpable.

Lossless compression isn’t only good for listening, though: it’s also a great storage tool. Just like you wouldn’t want a 72dpi JPG to be the sole digital copy of Ansel Adam’s photographs, we don’t want only 128kbps MP3s of “Kind of Blue.” Lossless standards like FLAC allow us to store audio efficiently without throwing away potentially valuable data. They also make remastering and redistributing that audio easier, since starting with uncompromised masters means a higher quality finished product.

Conclusion: Can You Tell the Difference?

Lossless audio formats allow for better sounding recordings. But sometimes the differences between a high-quality MP3 and a lossless file are nearly imperceptible, especially to the untrained ear. If you want to see if your headphones (and ears) are keen enough to tell the difference, NPR has a fun test; just keep in mind that cheap headphones and laptop speakers won’t be able to reproduce the subtle differences between lossless audio and MP3s. For a more serious analysis of codecs, check out SoundExpert’s encoder ratings.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Alexander Fox Avatar

Read next

When Frank Maixner’s team reconstructed Ötzi the Iceman’s 5,300-year-old stomach bacterium in 2016, the Helicobacter pylori strain looked less like modern Europe’s hybrid form than Asian lineages common today in South and Central Asia, leaving a migration signal no pot or stone tool could have shown
When Cingular chief Stan Sigman backed the original iPhone before its 2007 unveiling, he accepted terms American carriers usually refused: no logo on the device, no control over its software, no preloaded apps, and a share of monthly subscriber revenue flowing back to Apple, after signing on without seeing a prototype
Every year, roughly two billion new smartphones, laptops, and tablets ship with a key arrangement designed in the 1870s to prevent slender metal arms from colliding inside a machine that has been obsolete for decades, a piece of 19th-century mechanical engineering quietly embedded in the muscle memory of about five billion people.
Tristan Harris, Google’s former design ethicist, told the US Senate that the pull-to-refresh gesture on nearly every app works like the lever of a Las Vegas slot machine, and he has long warned that we now reach for our phones around 150 times a day without ever calling it gambling
In 1969, László Bélády and two IBM colleagues published a paging-machine anomaly showing FIFO could make four memory frames suffer ten page faults after three frames suffered nine, leaving generations of operating-systems students staring at the moment more memory became the wrong answer
When Bell Labs engineer Karl Jansky pointed a rotating antenna at the sky in 1932 looking for sources of transatlantic radio static, he kept picking up a faint hiss that peaked every 23 hours and 56 minutes, and he eventually realized he had become the first human to hear the center of the Milky Way.
The colour magenta does not exist anywhere in the spectrum of visible light, and your brain manufactures it on the spot whenever red and blue cones fire together, inventing a hue to fill a gap that physics never bothered to provide.
On 28 May 2009, Google demoed a product called Wave on stage at I/O for 80 minutes and got a standing ovation from developers who had no idea what they had just watched, and 15 months later the company quietly shut it down because almost nobody could explain to a friend what it was actually for