oss

How FLAC can guess wrong and play the right note

5 sources 2 primary sources November 18, 2026

Loading reads and saves…
Text

Suppose a CD drive delivers four consecutive samples from one channel of a recording. Their values are 1000, 1003, 1006 and 1020. A programmer trying to save space might spot the steady rise, predict 1009 for the fourth sample, and miss by eleven. FLAC, the open-source audio codec, can make exactly this mistake and still play back 1020. The trick is what the encoder writes down when its prediction fails. [1][2]

A gold compact disc sitting read side up in an open lift-lock case.
The line reflected in this gold CD is the meeting of a wall and a ceiling. FLAC’s input comes a step later, once a drive has read the disc. Photograph by Blenheimears. [3]

Eleven belongs in the recording

Try one of FLAC’s fixed predictors on those four numbers. It takes the difference between the last two samples and assumes the next step will be the same size. To get started, the encoder stores 1000 and 1003 in full. From that pair, the decoder can already work out a guess of 1006. The encoder needs to send only the correction for that third sample, which is zero. For the fourth it sends eleven. A decoder following the same rule adds eleven to 1009 and lands on 1020. Its next guess will use the recovered 1020. [1]

The corrections have a name, residuals. If a passage yields many small residuals, FLAC can spend very few bits on the common values and longer codes on occasional surprises. A drummer can strike as hard as the recorded sample allows. A large surprise costs space, and the drummer keeps the accent. The four numbers above illustrate reconstruction. Over so short a run, even a good guess might save too few bits to pay for describing how the samples were encoded. [1]

Give each frame a fresh start

A track gives the encoder many chances to choose. FLAC divides the incoming samples into blocks and writes a frame for each block. Within a frame it can encode a channel that stays at a single value by storing that value once. It can choose a predictor for a changing signal, or store a stretch of samples verbatim when prediction buys too little. The initial samples needed by a predictor travel inside its own subframe. A player that seeks into the middle of a concert can start decoding at a frame boundary without reconstructing every note since the overture. [1]

This also explains the compression setting on the command line. Give the reference encoder the same input with flac -0 and with flac -8, and the second setting lets it spend more effort looking for a compact representation. Both files decode to the same samples. Someone comparing the two by ear is listening for a difference the settings cannot introduce. File size and encoding time are where the choice shows up. [2][4]

Which copy passed the test?

Imagine a click on the fourth beat of a quiet passage ripped from a scratched disc. Run flac -t track.flac years later and the file may pass. The command decodes the stream, checks for errors and, when the stream carries an audio MD5 signature, compares it with the digest of the recovered samples. If the drive delivered that click on the day of the rip, faithfully returning it is precisely how the decoder passes. [1][4]

A ripper using AccurateRip can ask a different question while the disc is still on the desk. It compares a checksum for the extracted track with results in a database of other rips. Agreement supplies evidence about the drive’s reading of that particular track. A track absent from the database leaves that question open. Years later, the FLAC file can tell you whether its samples survived storage. The ripping log records the chance you had to check what came off the disc. [4][5]

Sources

  1. M. van Beurden and A. Weaver, RFC 9639, Free Lossless Audio Codec. Sections 5 and 9 describe blocking, prediction and residual coding.
  2. Xiph.Org Foundation, FLAC FAQ. Project background and the effect of compression levels on audio quality.
  3. Blenheimears, Gold CD in a lift-lock case. Photograph and original description, Wikimedia Commons.
  4. Xiph.Org Foundation, FLAC command-line tool. Compression presets and integrity testing.
  5. AccurateRip, Perfect Digital Audio Extraction. How the service verifies a ripped track against other extractions.
Previous How to write a comma with four fingers Next Where XTide gets the two low tides in an Anchorage day

Recommended In oss

Matched by subject and format