Search guides and the APICtrl K
  1. API reference
  2. Files and codecs

flac_encode.h

Writing FLAC.

#include <sonore/flac_encode.h>
  • 1type
  • 7other declarations
On this page

Design notes

We already decode FLAC ourselves; this is the other half. It is worth owning for the same reason: the format is simple enough to be provable, and a lossless encoder can be checked the only way that counts: encode, decode, compare SAMPLE FOR SAMPLE, and then have a completely independent decoder (ffmpeg) do the same.

Fixed predictors only, no LPC. The four fixed predictors are successive differences, they cost nothing to compute, and on real material they get most of what LPC would: an encoder that spends ten times the CPU for another five percent is the wrong trade for a plugin exporting a render. The output is fully compliant either way: a decoder cannot tell which predictors an encoder chose to use.

Offline: allocates and writes files.

Types 1

MSB-first bit writer. FLAC is bit-packed, and a writer that flushes a partial byte at the wrong moment produces a file that decodes as garbage from that point on.

Bits are gathered in a word and go out a byte at a time as they fill one. This wrote every bit on its own -- a shift, a count and a branch each -- and a four-minute render is half a billion bits. The bytes are the same: a write still puts the low bits bits of its value down, highest first, after everything written before it.

Functions 7

↑↓ to move↵ to openEvery public name in the headers, and every guide