edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
lane aachev1: ec-aac HE-AAC v1 (SBR) and v2 (PS) decode vs ffmpeg
Goal
DONE.md ec-aac decode: HE-AAC v1 (SBR) and v2 (PS), mono to 5.1, ADTS and m4a, match ffmpeg at per-channel correlation >= 0.999.
Base
- Worktree
~/.cache/wt/aachev1, branchlane/aachev1. - Original base
f3e6c7fa;git merge main(main8936fe06) done first.
Commits
30f73cd4lane/aachev1: HE-AAC v1/v2 parity fixtures and test; LFE doubled through the SBR QMF with the SBR lag, mono HE output duplicated to stereo as ffmpeg doese60027dclane/aachev1: decode_he fuzz target seeded from the HE-AAC fixtures; clippy-clean collapse of the LFE bypass hook- (this commit) lane/aachev1: report, with the 1 h fuzz result
Changes
- Fixtures,
crates/ec-aac/tests/data/he/(generated byscripts/aac-tables/make-he-fixtures.sh, libfdk from~/.cache/aacps-ref/fdk):he_v1_mono(32k, 2 s),he_v1_stereo(48k, 2 s),he_v1_51(160k, 0.6 s),he_v2_stereo(32k, 2 s), all at 22.05 kHz core input, so the decoded rate is 22050 Hz.- Each as
.aac(ADTS) and.m4a, plus the FFmpeg reference decode.s16. - Synthetic content only: sine/chirp/pink-noise mixes, one distinct signal per channel.
- Sizes: mono 224 KB, stereo 233 KB, 5.1 255 KB, v2 233 KB (each set under 300 KB).
crates/ec-aac/tests/he_parity.rs: decodes each fixture from ADTS and from m4a (viaec_mp4), checks channel count and rate against FFmpeg, and checks each channel's correlation at the best lag. No FFmpeg or fdk is needed at test time.- Decoder fixes (found by the new test):
- LFE in SBR streams (
sbr_chain.rsbypass_plane, hook indecode.rs): the LFE carries no SBR payload, so its plane stayed at core length. Output was then misaligned and zero after the first access unit, which is why the 5.1 LFE channel failed (corr ~0.01). The LFE now goes through the same 32-band analysis and 64-band synthesis with the high bands empty, and is held backHF_ADJslots (384 samples) to match the SBR planes. It was 384 samples early before that. - HE mono (
lib.rs): when SBR is reconstructed and the frame has one plane, the plane is duplicated to two identical channels. FFmpeg does this ("Treating HE-AAC mono as stereo"; its L and R are bit-identical, and ours equals its values, ratio 1.0000).
- LFE in SBR streams (
- Fuzz target
decode_he(crates/ec-aac/fuzz/fuzz_targets/decode_he.rs, bin entry infuzz/Cargo.toml).fuzz/seed.shcopies the HE fixtures intocorpus/decode_he.
Deviations from the brief (and why)
- References are s16le, not f32le. f32 at 22.05 kHz breaks the 300 KB cap for stereo and 5.1. The reference is FFmpeg's own decode; the comparison is in f32 after dividing by 32768.
- Lag search is symmetric,
-4096..=4096, on a window (8192 samples at 4096) and then the full-overlap correlation at the best lag. The brief said 0..=4096. Every row came out at lag 0. - The 5.1 LFE tone is 40 Hz, not 120 Hz. At 120 Hz the encoder's LFE cutoff leaves the LFE almost silent (about 0.005 rms against 0.16 in LC). The 120 Hz fixture was measured only before the LFE length fix, so it has not been re-measured since.
- Mono reference is two channels. FFmpeg outputs HE mono as stereo, so the test expects two.
Correlation table (cargo test --release -p ec-aac --test he_parity -- --nocapture)
All rows: 51200 frames (stereo, mono), 18432 frames (5.1), 53248 frames (v2). Channel count and rate match FFmpeg. Lag 0 in every row.
| fixture | container | channels | min corr | per-channel corr |
|---|---|---|---|---|
| he_v1_mono | adts | 2 (FFmpeg dup) | 0.999976 | 0.999976, 0.999976 |
| he_v1_mono | m4a | 2 | 0.999976 | 0.999976, 0.999976 |
| he_v1_stereo | adts | 2 | 0.999990 | 0.999990, 0.999993 |
| he_v1_stereo | m4a | 2 | 0.999990 | 0.999990, 0.999993 |
| he_v1_51 | adts | 6 | 0.999997 | 0.999999, 0.999999, 1.000000, 1.000000, 0.999997, 0.999997 |
| he_v1_51 | m4a | 6 | 0.999997 | 0.999999, 0.999999, 1.000000, 1.000000, 0.999997, 0.999997 |
| he_v2_stereo | adts | 2 | 0.999991 | 0.999991, 0.999996 |
| he_v2_stereo | m4a | 2 | 0.999991 | 0.999991, 0.999996 |
Fuzz: decode_he (1 CPU-hour, host a, detached)
- Command:
cargo +nightly fuzz run decode_he -- -max_total_time=3600 -print_final_stats=1(on host a,~/lanes/aachev1/edith_codecs/crates/ec-aac/fuzz, log~/aachev1-gen/fuzz_he.logon host a, copy at~/.cache/aachev1-gen/fuzz_he.log). - Result:
Done 59976 runs in 3601 second(s),cov: 3602 ft: 15218 corp: 811/3891Kb, peak RSS 495 MB,EXIT rc=0, 0 crashes, 0 artifacts. - CPU: sampled 5 times across the run at 99.1-99.3% (one core).
- Coverage was still rising: cov 3000 at 1 min, 3424 at 13 min, 3541 at 31 min, 3602 at 60 min. It is not a flat plateau, but the rate is low (16 exec/s, since each input is a 2 s HE stream).
- The binary was built before the clippy-only collapse commit (
e60027dc). That change does not touch the decode path.
Verify commands and results (all on host a via scripts/remote-run.sh aachev1 --host a)
cargo test --release -p ec-aac --test he_parity -- --nocapture: 1 passed (after the 0.6 s fixture).cargo test --release -p ec-aac(after the final decoder change): all pass. lib 48, he_parity 1, implicit_sbr 4, reelh_per_frame 1, multichannel_parity 1, no_panic 2, obs_real_content 1, oracle 15 (1 ignored, as before), ps_mp4 1, ps_oracle 1, sbr_real_library 16.cargo clippy -p ec-aac --all-targets -- -D warnings: clean (exit 0).cargo +nightly fuzz build decode_he: builds.
Not covered / left
- Edith routing (symphonia replacement,
engine/src/audio.rs) and the HE-AAC v2 refusal check in mp4 are not in this lane. - The 120 Hz LFE variant is not re-measured (see Deviations).
- Fuzz coverage is still climbing at 1 h. A longer run would give a better number.
Status
- Fixtures and the parity test: MET (every row >= 0.999, channel count and rate match FFmpeg).
- Decoder: MET for the rows above. Deviations listed above.
- Fuzz: MET as a clean 1 CPU-hour run with 0 crashes and real coverage (cov 3602).
- Gates: MET (
cargo test --release -p ec-aac,clippy -p ec-aac --all-targets -D warnings).