15.5 Summary

15.5 Summary#

  • A codec consists of a coder, which compresses audio into codes, and a decoder, which reconstructs it. Codecs trade off information rate (bits per second) against distortion (the error of the round trip). CD-quality audio has a rate of \(1411\) kbps, and a codec’s compression factor compares the size of its input to the size of its codes.

  • Psychoacoustics studies our perception of sound. Pitch and loudness are roughly logarithmic in frequency and amplitude. We hear from about \(20\) Hz to \(20\) kHz, across about \(100\) dB, but equal-loudness contours show that our sensitivity varies with frequency.

  • Rational just intervals like \(3{:}2\) are consonant. 12-EDO tuning approximates them to within about \(1\%\) with just \(12\) steps per octave.

  • Lossy codecs like MP3 remove frequencies that are inaudible due to critical bands, masking, and the threshold of hearing, and then losslessly compress the resulting sparse spectrogram, achieving compression factors around \(10\times\).

  • Lossless codecs exploit predictability. Entropy is the lower bound on bits per outcome. Huffman coding approaches it by giving likely outcomes short codewords. FLAC predicts samples with quantized LPC and compresses the residual with Rice coding.

  • Semantic compression stores only meaningful information, such as a score. MIDI encodes real-time Note On and Note Off messages in \(3\) bytes each, with compression factors in the thousands. pq.Score.from_midi exposes each note’s program, and other messages like control changes.