An MPEG audio codec in Zig that decodes Layers I, II and III and encodes Layers II and III.

Add an MP3 decoder

MPEG-1, MPEG-2 LSF and MPEG-2.5 Layer III, all nine sampling frequencies and every channel mode. Decoding only; encoding is not a goal. The core is a streaming decoder that is fed bytes and reports what it did with them, since Layer III spreads a frame's data backwards across its predecessors through the bit reservoir and frames cannot be decoded independently. decodeAll wraps it for a whole file in memory. Every stage walks the same list of scalefactor band widths, which is what keeps long, short and mixed blocks from each needing their own code path. Huffman tables become a 9-bit lookup table at compile time, with a tree for the code words too long to fit. The constant tables are generated by tools/gen_tables.py, which reads them out of two public domain references and cross-checks them against each other and against the standard. Those checks found a typo in PDMP3's own table of table offsets. Verified against ffmpeg's decoder over nineteen combinations of version, sampling frequency, bit rate and channel mode: all agree to within one least significant bit of a 16-bit sample. 76 tests, including whole-stream comparisons against committed reference decodings. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TzKTzcZxD6h1TY6UVD6TMo


Author jcollie.dev
Co-author Claude Opus 5 (1M context) Date Commit