forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

aacdecmulti.report.md84 lines, 4.7 KiBHistoryRawDownload
1# lane aacdecmulti: ec-aac multichannel parity against ffmpeg
2
3Base: `f5eb855b` (main), branch `lane/aacdecmulti`.
4
5## Goal
6
7DONE.md ec-aac decode criterion: AAC-LC mono, 5.1 and 7.1, raw and ADTS, must reach
8per-channel correlation >= 0.999 against ffmpeg's decode.
9
10## Changes
11
12- `crates/ec-aac/tests/multichannel_parity.rs` (new). Generates fixtures at test time with
13 ffmpeg (no media committed): an `aevalsrc` multitone with a distinct frequency per
14 channel, encoded to ADTS (`.aac`) and to mp4 (`.m4a`, raw access units plus ASC). Each
15 fixture is decoded by ec-aac and by ffmpeg (f32le, same channel count), aligned on the
16 best integer lag, then each channel's correlation must be >= 0.999. For 5.1 and 7.1 the
17 channel order is also checked (our channel k must correlate best with ffmpeg channel k).
18 `EC_AAC_PARITY_DEBUG=1` prints the RMS per channel and the full correlation matrix.
19- `crates/ec-aac/src/config.rs`: program_config_element is parsed into per-element
20 speakers (`Speaker`, `PceElement`). Front runs centre-out (SCE = FC, outermost pair =
21 FL/FR, inner pair = FLC/FRC), side pair = SL/SR, back pair = BL/BR, back SCE = BC, LFE.
22 `AudioSpecificConfig` gains `pce: Vec<PceElement>` (set when channelConfiguration is 0).
23- `crates/ec-aac/src/decode.rs`: raw_data_block records each plane's speaker when the PCE
24 names every element; `plane_order` returns the output order in FFmpeg mask-bit order
25 (FL FR FC LFE BL BR FLC FRC BC SL SR). Without a PCE, the old channel-config order is used.
26- `crates/ec-aac/src/lib.rs`: decode uses `plane_order` when present.
27- Struct literal updates for the new `pce` field: `examples/adts_to_pcm.rs`,
28 `examples/wrap_sbr.rs`, `tests/sbr_real_library/chunk_b.rs`.
29
30## Root cause found
31
32ec-aac ignored the PCE and used bitstream element order. The fdk 7.1 stream signals
33channel_configuration 0 with a PCE (front: SCE, CPE, CPE; back: CPE; LFE), so the
34second front pair is FLC/FRC, not SL/SR. ffmpeg outputs in the `7.1(wide)` order, and the
35m4a copy of the same stream keeps the PCE only in the ASC, which the decoder also needs.
36The native ffmpeg `aac` encoder writes channel_configuration 7 and was already correct.
37
38## Verify
39
40Run on host a via `scripts/remote-run.sh aacdecmulti --host a`:
41
42- `cargo test --release -p ec-aac --test multichannel_parity -- --nocapture`: PASS
43 (16 cases: 4 layouts x 2 containers x 2 encoders). Every per-channel correlation is 1.000000.
44- `cargo clippy -p ec-aac --all-targets -- -D warnings`: clean.
45- `cargo test --release -p ec-aac`: all binaries pass except
46 `sbr_real_library::chunk_a::full_chain_low_band_matches_own_core`. It fails identically on
47 base `f5eb855b` (checked with the changes stashed). It reads `/home/user/Music/reeln.mp4`, a machine-local file, and is unrelated to PCE.
48
49## Correlation table (per channel, lag from the search)
50
51| layout | container | encoder (profile) | channels | correlation per channel |
52|---|---|---|---|---|
53| mono | adts | aac (AAC-LC) | 1 | 1.000000 |
54| mono | m4a | aac (AAC-LC) | 1 | 1.000000 |
55| stereo | adts | aac (AAC-LC) | 2 | 1.000000, 1.000000 |
56| stereo | m4a | aac (AAC-LC) | 2 | 1.000000, 1.000000 |
57| 5.1 | adts | aac (AAC-LC) | 6 | 1.000000 x6 |
58| 5.1 | m4a | aac (AAC-LC) | 6 | 1.000000 x6 |
59| 7.1 | adts | aac (AAC-LC) | 8 | 1.000000 x8 |
60| 7.1 | m4a | aac (AAC-LC) | 8 | 1.000000 x8 |
61| mono | adts | libfdk_aac (AAC-LC) | 1 | 1.000000 |
62| mono | m4a | libfdk_aac (AAC-LC) | 1 | 1.000000 |
63| stereo | adts | libfdk_aac (AAC-LC) | 2 | 1.000000, 1.000000 |
64| stereo | m4a | libfdk_aac (AAC-LC) | 2 | 1.000000, 1.000000 |
65| 5.1 | adts | libfdk_aac (AAC-LC) | 6 | 1.000000 x6 |
66| 5.1 | m4a | libfdk_aac (AAC-LC) | 6 | 1.000000 x6 |
67| 7.1 | adts | libfdk_aac (AAC-LC, PCE) | 8 | 1.000000 x8 |
68| 7.1 | m4a | libfdk_aac (AAC-LC, PCE in ASC) | 8 | 1.000000 x8 |
69
70Before the fix, the fdk 7.1 rows had channels 0,1,6,7 wrong (0.0 against ffmpeg, with
71the front pairs swapped). Channel order for 5.1 and 7.1 matches ffmpeg in every row.
72
73## Not covered, and why
74
75- HE-AAC v1/v2: this ffmpeg's libfdk_aac fails with "Unable to set the AOT 5/29" for every
76 profile and rate, and the native `aac` encoder has no SBR. HE fixtures were not
77 generated. The existing HE-AAC files under `crates/ec-aac/tests/data` are stereo only
78 and already covered by other tests.
79- Channel configuration 12: no encoder available here emits it, and
80 `channels_for_config` still returns 0 for 12. Unverified and unchanged.
81- PCE in the ASC is handled for the mp4 path. A PCE that appears only inside a raw block
82 with no ASC is handled too, but only the in-band one is exercised by the matrix.
83- Lag search is an integer search over +/-4096 samples. A steady tone repeats at its
84 period, so the search scores the near-tied candidates over the full overlap.