Expand description
Simplified FLAC codec using fixed linear prediction + Rice coding.
This module implements a lightweight FLAC-style encoder/decoder based on fixed predictors (order 0-4) rather than full LPC analysis. It is useful for educational purposes and lightweight lossless audio compression.
§Fixed predictor formulas
| Order | Residual formula |
|---|---|
| 0 | r[i] = s[i] |
| 1 | r[i] = s[i] - s[i-1] |
| 2 | r[i] = s[i] - 2*s[i-1] + s[i-2] |
| 3 | r[i] = s[i] - 3*s[i-1] + 3*s[i-2] - s[i-3] |
| 4 | r[i] = s[i] - 4*s[i-1] + 6*s[i-2] - 4*s[i-3] + s[i-4] |
§Rice coding
Residuals are zigzag-folded (signed → unsigned) then split into a unary
quotient and binary remainder using a Rice parameter k.
Structs§
- Flac
Encoder Config - FLAC encoder configuration.
- Flac
Frame Header - FLAC frame header.
- Flac
Stream Info - FLAC stream info metadata.
Functions§
- decode_
flac_ frame - Decode a FLAC-style frame back to i16 samples.
- encode_
flac_ frame - Encode i16 samples into a single FLAC-style frame.