VxMusic

Back to Log
Audio Engineering15 min read

Understanding Lossless Audio: FLAC vs ALAC

March 15, 2025

"High Fidelity" is a term often thrown around in marketing materials, usually accompanied by gold badges and higher subscription tiers. But what does it actually mean physically and mathematically? Let's deconstruct digital audio.

The Basics: Sampling Theorem

To understand digital audio, you must understand the Nyquist-Shannon sampling theorem. It states that to perfectly reconstruct a continuous analog signal, you must sample it at a rate at least twice the highest frequency component.

Human hearing ranges roughly from 20Hz to 20kHz. Therefore, a sample rate of 40kHz is theoretically sufficient to capture everything we can hear. This is why CDs settled on 44.1kHz.

Bit Depth: The Vertical Resolution

If Sample Rate is the resolution of time (horizontal), Bit Depth is the resolution of amplitude (vertical).

  • 16-bit audio offers 65,536 levels of volume. This gives a dynamic range of 96dB.
  • 24-bit audio offers 16,777,216 levels of volume. This extends the dynamic range to 144dB.

For context, 144dB is the difference between a pin drop and a jet engine taking off next to your ear. While 24-bit is "better" on paper, 16-bit is sufficient for 99.9% of listening environments. The noise floor of your quiet room is likely 30-40dB, making the bottom end of 24-bit audio physically inaudible.

Lossy vs. Lossless

Lossy Compression (MP3, AAC, OGG):
These algorithms use "psychoacoustic modeling." They look for sounds that are likely masked by louder sounds (e.g., a quiet flute during a loud drum crash) and simply delete data for those quiet sounds. They also cut off frequencies above 16kHz or 18kHz.

Lossless Compression (FLAC, ALAC):
Think of this like a ZIP file for audio. It looks for mathematical redundancies (patterns) in the waveform and compresses them. 00000000 becomes 8x0. When unpacked, the data is bit-perfect to the original source.

FLAC vs. ALAC

FLAC (Free Lossless Audio Codec) is the open-source standard. It is faster to decode and compress, supports better error checking, and is supported by almost everything except Apple's legacy ecosystem.

ALAC (Apple Lossless Audio Codec) is Apple's version. It does the exact same thing but is wrapped in an M4A container.

VxMusic prefers FLAC because the decoding complexity is lower, which translates to slightly better battery life on mobile devices.

The Android Audio Stack

Playing High-Res audio on Android is tricky. By default, the Android mixer resamples everything to 48kHz. Even if you play a 192kHz file, Android might downsample it before it hits the DAC (Digital-to-Analog Converter).

To bypass this, VxMusic uses the AAudio API in "Exclusive Mode." This attempts to lock the audio stream to the device's native burst rate and sample rate, bypassing the system mixer entirely.

// Kotlin/C++ Pseudocode for AAudio setup AAudioStreamBuilder builder; builder.setDirection(AAUDIO_DIRECTION_OUTPUT); builder.setSharingMode(AAUDIO_SHARING_MODE_EXCLUSIVE); // Critical for Hi-Res builder.setSampleRate(96000); builder.setFormat(AAUDIO_FORMAT_PCM_FLOAT);

When Exclusive Mode engages, you might notice other apps (like notifications) go silent. This is the price of sonic purity.