Skip to main content

Module encode

Module encode 

Source
Expand description

MP3 encode pipeline (the inverse of decode, plus a psychoacoustic model).

 PCM ─▶ analysis filterbank ─▶ MDCT ─▶ psychoacoustic model ─▶
 quantize (inner rate loop + outer distortion loop) ─▶ Huffman ─▶
 bitstream (side info + main data + reservoir) ─▶ frame

The psychoacoustic model and the two-loop quantizer are the quality-defining bricks — they decide block type and how to shape quantization noise under the masking threshold, the way LAME does. Everything else is mechanical.

Modules§

antialias
Forward alias reduction (encode) — the inverse of decode/antialias.rs.
bitstream
Frame assembly + the encoder-side bit reservoir, and the side-info / scalefactor serializers (bricks B5, B6, B7, B8).
fft
Brick Q2 (core) — a radix-2 Cooley–Tukey FFT, the psychoacoustic model’s analysis transform. Pure in-house, no dependencies. Scalar Rust; this is the single biggest cycle sink in a perceptual encoder and is flagged as a SIMD hotspot (lab::bricks::accel → SIMD), but the scalar path is the reference the SIMD twin will be checked against.
filterbank
Brick L1 — the analysis polyphase filterbank, the inverse of decode’s synthesis stage (decode/synthesis.rs).
huffman
Huffman encoding of the quantized spectrum — the inverse of decode’s spectrum decode (decode/huffman.rs). Bricks B1–B4 (+ N8 linbits and N9 region maps, both reused from the decode side).
mdct
Brick L2 — the forward (analysis) MDCT, the TDAC inverse of decode’s hybrid IMDCT (decode/imdct.rs).
prof
Lightweight stage profiler (near-zero cost; read via prof::dump). Used to find the real encode hotspots instead of guessing — the basis of the optimization plan’s measurements.
psychoacoustic
Psychoacoustic model — the quality brain (bricks Q1–Q4).
quantize
The two-loop quantizer — rate control + noise shaping.
shortblock
Short-block coding (brick Q5) — the forward reorder and the short-block quantizer.
stereo
Mid/side joint-stereo encoding (the R1+ enhancement) — the forward of decode/stereo.rs.

Structs§

Mp3Encode
Persistent encoder state across frames.