edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
Lane mp2a: Layer I/II (MP1/MP2) decode
Branch lane/mp2a (one commit on 2fcdcdb5). Worktree /home/user/.cache/wt/mp2a.
What was built
crates/ec-mp3/src/layer12.rs: Layer I and Layer II decode behind the existingMp3Reader,Mp3DecodeandMp3Decoder(the header picks the layer; output is interleaved f32 in [-1, 1], same as Layer III).- Layer II: allocation tables 3-B.2a..d plus the LSF table, table selection by sample rate and bitrate per channel, scfsi, scalefactors, grouped 3/5/9-level samples, requantisation, joint-stereo intensity bound, dual channel, CRC over allocation + scfsi.
- Layer I: allocation, scalefactors, bound, CRC over allocation.
- MPEG-1, MPEG-2 LSF (16/22.05/24) and MPEG-2.5 headers.
header.rsnow has the per-layer bitrate tables (it used the Layer III table for everything), per-layersamples_per_frame, andcrc16_bits. - Polyphase bank for Layers I/II is f64 with the exact window (the measured Layer III window rounded to
multiples of 2^-16, which is what the standard's
D[i]are). Layer III code path and filterbank untouched. - Multichannel (5.1 BC) extension ignored: stereo base decodes. Free format refused by name ("free-format MPEG audio").
- Tables were measured from the oracle, in the Layer III style:
scripts/mp2-tables/measure.py(allocation field widths from where single-bit probes stop reacting; quantiser size per code from the steady-state level against a Layer I calibration). Result: 3-B.2a/b sb0-2 {3,7,15,...,65535}, sb3-10 {3,5,7,9,15,...,8191,65535}, sb11-22 {3,5,7,9,15,31,65535}, sb23+ {3,5,65535}; 2c/2d sb0-1 {3,5,9,15,...,32767}, rest {3,5,9,15,31,63,127}; LSF sb0-3 {3,5,7,9,15,...,16383}, sb4-10 {3,5,9,...,127}, sb11-29 {3,5,9}. ec-core:CodecId::Mp2andCodecId::Mp1(two variants, not one: Layer I needs its own id for TS/MKV mapping), namesmp2/mp1, media type audio, and the registry test count 26 to 28.ec-probedecoder seat:Mp3 | Mp2 | Mp1all go toMp3Decoder.ec_mp3::layer_codec_parameters(layer, rate, ch)added.ec-mpegts: stream types 0x03/0x04 now yieldMp1/Mp2/Mp3by the first frame's layer; the layer refusal (note_refusals) is removed; lib/codec docs updated;h264_mp2parity case now compares MP2 packets with ffprobe, plus newmp2_in_ts_is_exposed_as_mp2.lanes/mpegts.report.mdleft as the historical record.DONE.md: new "ec-mp3 Layer I/II decode" section; ec-mpegts section no longer lists MP2 as refused.
Numbers (oracle: ffmpeg -c:a mp2float / mp1float, f32le; synthetic sources only)
| set | streams | max abs error vs ffmpeg float |
|---|---|---|
ffmpeg mp2 / mp2fixed encoder: 16/22.05/24/32/44.1/48 kHz, mono+stereo, 8-384 kbit/s, sine/pink noise/chirp |
13 | 5.2e-6 |
| libtwolame: joint stereo (several bounds, 24-384k), stereo, dual channel, mono, with and without CRC | 12 | 6.2e-6 |
| hand-built random-payload Layer I and II, MPEG-1/2/2.5, every table, stereo/joint(ext 0-3)/dual/mono, CRC on/off | 336 | 3.85e-5 |
- The first two rows meet the 1e-5 bar. The third does not: those frames are full-scale noise in every band
(peaks of 4-6 in float), and a single active band already shows 3e-6 against ffmpeg float. My f64 pipeline agrees with
ffmpeg's fixed-point decoder (
mp2/mp1, s16) to within 1 LSB on every stream, 75-89 percent of samples identical, so the residual is ffmpeg's float synthesis precision, not a table or dequant error. I did not prove which side carries it (no independent high-precision reference). The test threshold for that set is 4e-5. A bit-exact s16 match is not achievable against ffmpeg's integer path; the 1 LSB agreement is reported by the test. - Quirk met: ffmpeg's demuxer drops a leading frame whose header differs from the next ones (twolame toggles stereo/joint per frame); the twolame test aligns on that.
- Layer I: ffmpeg has no MP1 encoder and no clearly licensed MP1 file was at hand, so Layer I is tested only on the
hand-built frames (
mp1floatoracle). Say so in any claim about Layer I coverage. - ffmpeg float mishandles nothing I could find for forbidden codes (scalefactor 63, group codes >= L^3, Layer I allocation 15); the tests do not generate them. Mine: sf 63 uses the formula, bad group codes decode modulo, Layer I allocation 15 is a corrupt-frame error.
Tests and gates
- New:
crates/ec-mp3/tests/mp2_matrix.rs(encoder matrix, twolame matrix, 336 random-payload streams, CRC detection, free-format refusal,Mp3Decoderpackets, damaged/truncated no-panic). Skip convention:EC_REQUIRE_FIXTURES=1makes a missing ffmpeg a failure; a missing libtwolame is a skip. All generated at test time, nothing committed, only synthetic audio. - server host b,
EC_REQUIRE_FIXTURES=1 cargo test -p ec-mp3 -p ec-mpegts -p ec-core --release --no-fail-fast: see the final status line below. Existing Layer III tests (decode_matrix, encode_matrix, unit) pass untouched. - No fuzz target:
ec-mp3has nofuzz/directory. The damaged/truncated test is the smoke run.
Merge notes for the mpeg2v lane
ec-core/src/registry.rs: I addedMp2,Mp1afterMp3in the enum, themedia_typeaudio arm,name(), and the test list;assert_eq!(all.len(), 28)will textually collide with their count change. After both merges the count is 26 + 2 + their additions.ec-mpegts/src/track.rs: theStreamKind::MpegAudioparams block and the removednote_refusalsare the only edits; a video-side change from mpeg2v should merge cleanly.- Not done: Matroska
A_MPEG/L2/L1mapping,ec-proberaw.mp2file sniffing, MP2 in MP4 (mp4a0x6B).
Final status
Committed on lane/mp2a (not pushed). server host b, EC_REQUIRE_FIXTURES=1 cargo test -p ec-mp3 -p ec-mpegts -p ec-core --release --no-fail-fast: every test binary ok (ec-core 44, ec-mp3 unit 22 + decode_matrix 1 + encode_matrix 5 +
mp2_matrix 7, ec-mpegts 11 + 2 + 16 parity + 2 robust + 9 synthetic + committed). server host c,
cargo clippy --workspace --all-targets -- -D warnings: clean.