forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on fcd7dac5964d9ca6eefea63c84f3cfc133c2e6d6Filtered to scripts/mp3-tables/emit_tables.pyClear filter

2026-08-14

feat(mp3): Layer III decoder and encoder, tables measured not copiedAhmet Kaan Gümüş · 1325107
feat(mp3): Layer III decoder and encoder, tables measured not copied

ec-mp3 decodes MPEG-1, MPEG-2 LSF and MPEG-2.5 Layer III and encodes CBR
MPEG-1 Layer III, and shims/rusty_mp3 carries the incumbent's name, version
and call shape over it.

Layer III's Huffman code tables and its 512-tap polyphase window are
normative data no formula produces. Instead of copying them out of an
existing implementation, scripts/mp3-tables measures them against a
reference decoder: it writes legal frames whose main-data bits it chooses,
decodes them with ffmpeg, and reads the answer back through a model of the
decode chain. Every code tree is walked to its leaves and checked for a
Kraft sum of exactly 1, complete coverage of its value grid and no
duplicates; the window is least-squares fitted to a 1.6e-6 residual, the
f32 noise floor of the decoder measured. The same rig produced the MPEG-1
long scalefactor band widths, which came out equal to the published
layouts, and it corrected two things a description would not have: the
MPEG-2.5 11.025 and 12 kHz short-block layouts are the 16 kHz ones, and the
short-block region boundary is three scalefactor bands rather than the
fixed 36 lines that only holds where those bands are four wide.

Decoder: header and CRC, side info, scalefactors (MPEG-1 with scfsi and the
LSF partition scheme), all Huffman tables, requantisation, mid/side and
intensity stereo, short-block reorder, alias reduction, IMDCT with the four
block windows, and a DCT-based polyphase bank from ec-dsp. ID3v2 and the
Xing/LAME/VBRI header frame are skipped, junk is resynced over, and
free-format is refused by name rather than guessed at.

Encoder: polyphase analysis (the synthesis bank's adjoint, reconstructing
to its -85 dB design limit), MDCT with block switching, an FFT-based
masking model whose gaps are stated in the module docs, inner rate and
outer distortion loops, Huffman table and region selection, and a bit
reservoir that emits frames one behind so a granule can start inside the
previous frame's payload.

Measured, all against ffmpeg:
- decode: 47 fixtures (nine sample rates, mono/stereo/joint/simple, CBR and
  VBR) at correlation 1.000000, 333-3232x realtime
- encode: at or above rusty_mp3 0.6.1 on the same corpus and metric at
  128/192/320 kbit/s, mono and stereo, every stream decoding without an
  ffmpeg warning