Skip to main content

Module flac_codec

Module flac_codec 

Source
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

OrderResidual formula
0r[i] = s[i]
1r[i] = s[i] - s[i-1]
2r[i] = s[i] - 2*s[i-1] + s[i-2]
3r[i] = s[i] - 3*s[i-1] + 3*s[i-2] - s[i-3]
4r[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§

FlacEncoderConfig
FLAC encoder configuration.
FlacFrameHeader
FLAC frame header.
FlacStreamInfo
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.