Commits
Commits on
f40e85cc619058a8d7bbbbeab4964c3018bca8d92026-08-20
feat(mux): declare an audio encoder's priming so no-elst/no-CodecDelay means zero delayAhmet Kaan Gümüş · f40e85c
feat(mux): declare an audio encoder's priming so no-elst/no-CodecDelay means zero delay Root cause: mp4's elst and Matroska's CodecDelay only ever came from a reordered video track's ctts offset, so an AAC track's encoder priming (one 1024-sample frame, always) was never written. A downstream reader had no way to distinguish "this file truly has zero delay" from "this file's muxer never said" and had to guess a fallback -- guessing wrong either trims real audio from a genuinely delay-free file or leaves an encoder's priming samples in. ec-mp4: Mp4Muxer::set_audio_delay(stream, priming_samples) folds into the same elst media_time/segment_duration the video-reorder path already writes (a shift, never a trim); the demuxer already applied elst generically, so no demux change was needed there -- verified with a mux+demux round trip. ec-matroska: the muxer already wrote CodecDelay (set_track_delay), but the demuxer never read it back. CodecDelay is a decode-but-don't-play priming, the same contract as StreamInfo::initial_padding (which mp3/Opus already use) and not a timeline shift, so it is converted ns -> samples and reported there. ec-aac: AacEncoder::encoder_delay() -> usize accessor (1024, the fixed cost of the first MDCT window's overlap-add having nothing to overlap yet) for a muxer caller to pass into the above. Tests: ec-mp4::aac_priming_round_trips_through_an_elst, ec-matroska::aac_priming_round_trips_through_codec_delay.
diag(aac-sbr): re-run feed-forward FIR vs all-pole A/B on the normative QMF bankAhmet Kaan Gümüş · 8ec0f40
diag(aac-sbr): re-run feed-forward FIR vs all-pole A/B on the normative QMF bank
Round-48 (commit 8bc305b) shipped the spec's feed-forward 2-tap FIR
extension of sbr_hf::generate; round-50 (ec65451) reverted it to the
all-pole residual resynthesis on measurement, but that A/B ran through the
old fitted-Kaiser QMF bank, not today's normative ISO/IEC 14496-3
4.6.18.4/4.6.18.8.2 analysis/synthesis pair in sbr_qmf.rs. Re-tried the
feed-forward FIR (cherry-picked from 8bc305b, adapted: HfHistory drops the
now-unused y-history half, stabilize's doc updated) against today's
sbr_real_library test suite:
sbr_real_library_matches_reference (full-band correlation, ch0/ch1):
reeln: all-pole 0.986993/0.986238 vs feed-forward 0.965566/0.965680
FMJ: all-pole 0.997880/0.993373 vs feed-forward 0.994118/0.983006
synthetic_heaac_matrix, 48k family, above-crossover band:
32k: 0.9969 -> 0.9951 48k: 0.9882 -> 0.9646
64k: 0.9864 -> 0.9727 96k: 0.9863 -> 0.9726
synthetic_heaac_matrix, 44.1k family: unchanged (both already near-zero,
a separate pre-existing issue this round didn't touch).
Feed-forward loses on every witness again, same direction as round-50, on
the QMF bank that round-50's finding was suspected of being contingent on.
The all-pole structure and its stability bound (BIBO |a1|+|a2|<1, correct
for an IIR recursion; the spec's own |alpha|>=4 -> 0 guard on the FIR
coefficients is not applicable here since that structure isn't in use) are
unchanged from main -- this commit is doc-only, recording the re-measurement
so the next round doesn't re-try this exact experiment from a stale premise.diag(aac-sbr): 44.1k-family "sample drift" is a narrow-search artifact, not clock driftAhmet Kaan Gümüş · 9f92c74
diag(aac-sbr): 44.1k-family "sample drift" is a narrow-search artifact, not clock drift sbr441_family_sample_drift_probe (crates/ec-aac/tests/sbr_real_library.rs) walks lag(t) per-1s window in a NARROW +/-128 search around each fixture's own true fixed lag (found first via a wide free-search cross-check, since the earlier -4674/-4617 pair used in coupled_cpe_channel_swap_probe was itself never independently verified against a wide search on this file). Findings, all three fixtures (heaac_44100_48k "fail" family, heaac_48000_48k "control", and reeln.mp4 as a real-content control): - lag(t) is FLAT (+/-1-2 samples, fitted slope ~0) across the full 30s for every file -- no growing sample-count/clock drift anywhere. The earlier "decays 0.998->0.68 by t=9s" reading was the free coarse-then-refine search (proven separately unreliable on this file's periodic content) chasing a different, wrong lag as it walked forward, not the aligned signal actually drifting. - heaac_44100_48k and heaac_48000_48k -- NOT just the "failing" 44.1k family -- both show an IDENTICAL correlation dip-then-recover in the file's middle third (t~=13-27s, corr falling to ~0.13-0.5) at their otherwise-flat true lag. Since the 48k file shows the same dip, this is a property of the synthetic fixture pair's shared source content (both built by the same make-heaac-fixtures.sh run), not a 44.1k-vs-48k output-rate SBR/rate-family defect. - Sample counts: our decoder emits exactly au_count*2048 samples/channel for both heaac fixtures (no internal drops); ffmpeg's own decode is a constant ~5058 samples shorter for BOTH files (encoder priming/padding trim ffmpeg applies via edit list that we don't) -- a fixed offset already absorbed into the fixed lag, not a growing one. reeln's 0.366 ours/ffmpeg ratio is purely the test harness's own 1500-AU extraction cap (~69.7s) against ffmpeg's full ~190s decode, not a decode defect. - hold_call_count() (new ec_aac::hold_call_count(), sbr_chain.rs HOLD_CALLS atomic) is 0 across all three files' full decodes: no apply_last/hold fallback is involved at all. Verdict: the charter's "44.1k-family clock drift" hypothesis is refuted. Next suspect for the mid-file correlation dip shared by both synthetic heaac fixtures: their shared source content around t=13-27s (quiet passage / high-transient section stressing SBR HF reconstruction), not sample-rate-family-specific code.
diag(aac-sbr): confirm coupled-CPE swap probe is a lag-drift artifact, not a channel swapAhmet Kaan Gümüş · f7652c7
diag(aac-sbr): confirm coupled-CPE swap probe is a lag-drift artifact, not a channel swap Adds a fixed-lag correlation matrix (per-pair ch0/ch1 vs ref L/R at four candidate lags, plus mono-derived lag) to coupled_cpe_channel_swap_probe, replacing trust in the free lag search (already known unreliable: it mis-searches ref L vs ref R against each other on this file's periodic content). A per-1-second sub-window breakdown at the properly-determined fixed lag shows ch0 starting near-perfect against ref L (0.998) and drifting down to 0.68 over 10s while its ref R correlation rises 0.90 to 0.99 -- a monotonic crossover consistent with accumulating decode/ reference clock drift, not a step-change channel swap. Adds an assert gating the swap-shaped signature and updates synthetic_heaac_matrix's HE rows to derive one lag per stream from the summed (mono) signal instead of a per-channel free search.
diag(aac): reelh_per_frame prints pns_bands census and full-file RMS/PearsonAhmet Kaan Gümüş · 22effda
diag(aac): reelh_per_frame prints pns_bands census and full-file RMS/Pearson Used from edith_replica's real-library sweep hunt: confirms this file's raw ec-aac decode already matches ffmpeg at 0.999999 Pearson over the first 10s (1/447 AUs below 0.9 sub-window corr, a near-silent PNS frame at the fade-in, not a real defect) -- the sweep's reported 0.9840 traced to two bugs in the replica engine/harness instead, not to this decoder.
diag(aac-sbr): isolate the coupled-CPE L/R swap to the bare Analysis/Synthesis QMF pair, not plane/state threadingAhmet Kaan Gümüş · 9631d42
diag(aac-sbr): isolate the coupled-CPE L/R swap to the bare Analysis/Synthesis QMF pair, not plane/state threading Adds env-gated (EC_AAC_SBR_PREQMF_DUMP) pre-QMF/post-QMF plane dumps in sbr_chain::apply_data and matching core-only dumps in the test harness, plus an isolated round-trip probe in coupled_cpe_channel_swap_probe that runs the already-correctly-directed core-only decode through a bare, fresh Analysis(32)->zero-stuff-HF->Synthesis(64) pair per channel, with no sbr_chain, HashMap element lookup, envelope/HF/noise code, or per-AU state at all. Findings (see ledger DELTA for the full table): the plane content entering apply_data is byte-identical to the core-only decode's own channel content (no pre-QMF swap); the isolated round trip alone reproduces the swap numbers to ~5 significant figures (kx=20: ch0 vs ref L corr=-0.089, vs ref R corr=0.980) matching the full-chain and EC_AAC_SBR_HF_BYPASS=1 numbers almost exactly -- narrowing the bug to crates/ec-aac/src/sbr_qmf.rs's Analysis/Synthesis pair itself, not sbr_chain's plane/channel-index threading or sbr_env/sbr_hf. The real reference L/R content does not invert at any tested lowpass cutoff (100Hz-12kHz via ffmpeg), ruling out "the source material really does swap identity in that band". Root cause inside sbr_qmf.rs not found this round; NOT fixed, gates NOT re-run to passing.
fix(aac-sbr): correct §4.6.18.7.2 coupled-CPE pan-offset/exponent mathAhmet Kaan Gümüş · c1d01e5
fix(aac-sbr): correct §4.6.18.7.2 coupled-CPE pan-offset/exponent math dequant_pair's ratio exponent was 2*alpha*balance_raw - 12 (doubling the step at bs_amp_res=1 and using the wrong offset at bs_amp_res=0) and its left/right naming handed physical channel 0 the env1 shape and channel 1 the env0 shape. Per ISO/IEC 14496-3 §4.6.18.7.2 the ratio is 2^(pan - panOffset) with panOffset=24 at bs_amp_res=0 and 12 at bs_amp_res=1, and env0/env1 stay on their own physical channel (no left/right swap). panOffset must also come from the header's transmitted bs_amp_res unconditionally, not the per-envelope amp_res override a single-envelope frame forces to 0 -- the two diverge on single-envelope coupled frames. heaac_44100_48k.m4a's live balance raw values cluster at 12 under bs_amp_res=1, matching a centred pan at panOffset=12 exactly and confirming the offset direction empirically. This does NOT fix coupled_cpe_channel_swap_probe's ch0-correlates- with-ref-R finding: EC_AAC_SBR_HF_BYPASS=1 (which reduces SBR to a per-channel low-band QMF round trip, running neither this coupling math nor sbr_hf's HF generation at all) reproduces the identical swap, ruling out sbr_env.rs and sbr_hf.rs as the swap's cause. Gate numbers held: coupled_cpe_channel_swap_probe passes as a diagnostic probe (not an assertion of correctness), synthetic_heaac_matrix ok, reeln/FMJ real-library correlation unchanged (0.986238 vs the pre-existing 0.986222 baseline, both below the 0.999 bar this branch did not touch), ec-aac --lib 45/45 passing.
test(aac-sbr): add coupled-CPE L/R swap probe for the 44.1k implicit-family breakAhmet Kaan Gümüş · 9630027
test(aac-sbr): add coupled-CPE L/R swap probe for the 44.1k implicit-family break Ledger charter asked why implicit-output-rate-ASC 44.1k HE-AAC fixtures break the full SBR chain while their core-only decode is fine. Root cause found, not where the charter expected: heaac_44100_48k.m4a's SBR side info shows bs_coupling=1 on almost every AU (reeln/FMJ, both passing, show coupling=false) -- coupling, not the 44.1k rate family, is the actual discriminant refuted rate-family theories missed. coupled_cpe_channel_swap_probe decodes both channels and correlates each against the reference's L and R separately: our ch0 reads 0.98 correlated with the REFERENCE's RIGHT channel (ch1 with its LEFT) at a fixed lag -- the full chain's stereo output is L/R-swapped for this file. The core-only (SBR-disabled) decode of the same file is NOT swapped (ch0 vs ref L 0.83 > ch0 vs ref R 0.72), so the swap is introduced somewhere in the SBR chain specifically for coupled CPEs, not the AAC-LC core. Tried and reverted: swapping dequant_pair's left/right assignment in sbr_env::dequantize_frame's coupling branch (the textbook suspect for a coupled-CPE channel swap) measurably changed nothing -- rebuilt twice, identical correlation to 6 decimals -- so the swap site is elsewhere in the SBR chain (sbr_chain.rs's per-tag/per-ch wiring, or sbr_payload's CPE channel read order) and is still open. Left as a dead-end + reproducible instrument rather than shipping an unverified fix.
fix(aac-sbr-test): stop the lag search from clipping at its own edgeAhmet Kaan Gümüş · 7ecec20
fix(aac-sbr-test): stop the lag search from clipping at its own edge Class fix: best_lag_correlation/_wide's search bounds (LAG_MAX=4_000, several WIDE_LAG_MAX=20_000) silently clipped and reported the edge's noise as the answer whenever a file's true alignment lag was larger than the bound -- FMJ's true full-chain delay vs the reference is ~22,913 samples @48kHz, past every existing bound. Unifies the search into best_lag_correlation_ex(ours, theirs, lag_max) -> (lag, corr, at_edge), reused by every wrapper and every asserting site. sbr_real_library_matches_reference now searches +/-100_000 (SEARCH_LAG_MAX) directly and asserts !at_edge before trusting a correlation; FMJ's TRIANGLE lag now correctly reads 22913 (was -25 at the old edge), reeln's baseline (0.987006/0.986222) is unchanged. full_chain_low_band_matches_own_core escalates from its original 20_000 bound to 100_000 only when the narrow search hits its own edge (not unconditionally): FMJ's core-vs-full delay genuinely needs the wide bound (measured 21952, corr 0.998326 on ch0, matching a prior manual probe exactly), but unconditionally widening reeln's search too flips its correct small-lag answer (-576, corr 0.9967) into a wrong noise-driven one (-912, corr -0.295) -- a lower-quality low-passed signal has enough stray coarse peaks over a 100_000-wide range to beat a real but modest true peak. The escalation pattern gets both files right without exposing the well-behaved one to the wider bound's noise floor. Findings from this run (not fixed here, out of scope for the instrument fix): - sbr_real_library_matches_reference: worst_full 0.986222 still fails the 0.999 bar -- reeln's known plateau, unchanged by this fix. - full_chain_low_band_matches_own_core: FMJ ch1 corr 0.149865 at lag 19782 (not at_edge, a real measurement) -- a genuine per-channel asymmetry, not a search artifact. - synthetic_heaac_matrix's LC control row (48000/32k) now fails at corr -0.163588, lag -2080 with the PLAIN_LAG_MAX-backed best_lag_correlation() unchanged from before this commit -- did not reproduce with a wide bound (that was this round's own now-reverted regression); left unresolved, needs its own investigation.
test(aac): refute an AAC-Main/LTP capability-gap premise, add real 7.1 mp4 regressionAhmet Kaan Gümüş · bff985b
test(aac): refute an AAC-Main/LTP capability-gap premise, add real 7.1 mp4 regression
The ledger recorded crates/ec-aac refusing a real 7.1 mp4 track with
Unsupported{"predictor_data_present: main or LTP profile, not AAC-LC"},
attributing it to ISO/IEC 14496-3 §4.6.6 (LTP) or §4.6.7 (Main-profile
backward-adaptive prediction) not being implemented.
Re-checked against the real file on current main (e90efe0): the AAC
track's AudioSpecificConfig (§1.6.2.1) decodes audioObjectType=2
(AAC-LC), confirmed independently via the ADTS `profile` field ffmpeg
remuxes it to (profile=1=LC per ISO/IEC 13818-7 table). AacDecoder reads
the whole ~994s track -- 45000+ access units -- with zero Err returns.
No predictor_data_present refusal is reachable on this file today; the
capability gap the ledger recorded does not exist for it, so no §4.6.6/
§4.6.7 prediction work was needed or attempted.
ffmpeg's native `aac` encoder and libfdk_aac both refuse "-profile:a
aac_main"/"aac_ltp" ("Profile not supported!"), so no synthetic fixture
for either profile can be generated on this box; a real Main/LTP file
would still need a from-spec fixture or another real-library find.
Adds a real-library regression test as the standing proof: decodes 10s
of all 8 channels of the file's AAC track through its real mp4 container
and checks each against ffmpeg's own decode, isolated per channel with a
`pan` filter (never -ac 1, per the existing witness-rule comment on
ffmpeg_decode). All 8 channels: lag 0, corr 1.000000.
Pre-existing failures left untouched and unchased, per charter: an
unrelated HE-AAC SBR-chain regression on a different candidate
(sbr_real_library_matches_reference, full_chain_low_band_matches_own_core)
is owned elsewhere; three oracle.rs fixture-missing failures are this
fresh worktree never having run scripts/gen-fixtures.sh, reproduced
identically on main's own worktree layout (fixtures/ is gitignored,
generated on demand).diag(aac-sbr): FMJ's real delay is ~21952 samples, past every gate test's search boundAhmet Kaan Gümüş · 7dce885
diag(aac-sbr): FMJ's real delay is ~21952 samples, past every gate test's search bound Coordinator follow-up probes: Probe A (hand-built explicit AOT-5 config vs the parsed AOT-2 config): FMJ's own parsed AudioSpecificConfig ([13 10 56 e5 98]) already reads object_type=2, sample_rate=24000, sf_index=6, sbr_present=true, extension_sample_rate=Some(48000) -- bit-identical to what a hand-built explicit object_type=5 config with the same rates produces. Confirmed by grep: `object_type` is read nowhere in decode.rs/lib.rs/sbr_chain.rs outside config.rs itself -- it never drives runtime table selection or control flow. So Probe A's near-1.0 correlation was NOT caused by object_type 2-vs-5; it was caused by the widened lag search used in that probe (see Probe B) applied identically to both configs, which produced bit-identical numbers (lag=21952, corr=0.998326) whether the config's object_type field said 2 or 5. Probe B (WIDE_LAG_MAX 20_000 -> 100_000 for FMJ): full_chain_low_band_matches_own_core's own (PARSED, object_type=2) decode, re-measured with a 100_000-sample bound instead of 20_000: ch0 best lag=21952 corr=0.998326 (was lag=20005 corr=0.217393) Full-band vs the reference decoder, same widened bound: ch0 lag=22913 corr=0.997880 Conclusion: FMJ's SBR decode is CORRECT. The 51+ rounds of "FMJ decorrelation" chased a DSP defect that was actually a test-harness measurement artifact -- WIDE_LAG_MAX=20_000 (full_chain_low_band_ matches_own_core) and LAG_MAX=4_000 (sbr_real_library_matches_reference) are both far too small for FMJ's real full-chain delay (~22k samples at 48kHz, vs reeln's -576), so every prior FMJ correlation number in this suite (-0.025253, 0.010226, 0.217393) was measuring a spurious noise-driven lag near each search's own edge, not FMJ's actual alignment. No production src/ change this round (charter was probes-only, ≤20 tool calls); the concrete next step is widening sbr_real_library_matches_ reference's LAG_MAX (or switching it to the wide/odd-stride search best_lag_correlation_wide already uses) so the asserted gate measures FMJ's real ~22k-sample delay instead of clipping at 4000. Left as the immediate next round's fix, not attempted here to avoid landing an unverified change to the asserted gate within this budget. New diagnostic test: probe_explicit_config_and_wide_lag in crates/ec-aac/tests/sbr_real_library.rs.
test(symphonia-shim): pin an mp3 probe past a 2MB ID3v2 APIC cover art and an ID3v1 tailAhmet Kaan Gümüş · 537e531
test(symphonia-shim): pin an mp3 probe past a 2MB ID3v2 APIC cover art and an ID3v1 tail Regression for edith_replica's "open: NeedMore" on a real cover-art-tagged mp3, root-caused to that repo's test harness (not this shim): the shim's probe already skips a large ID3v2 tag and an ID3v1 TAG tail correctly (this test is new coverage, not a fix), but nothing here pinned it against a synthetic file carrying both, sized like the real one that triggered the investigation (21.7 KB real tag; this test uses 2 MB to stress the same path harder).
diag(mkv-audio): A/B ec-matroska's AAC and AC-3/E-AC-3 delivery against mp4/ffmpeg -- refuted, not fixedAhmet Kaan Gümüş · d6466ca
diag(mkv-audio): A/B ec-matroska's AAC and AC-3/E-AC-3 delivery against mp4/ffmpeg -- refuted, not fixed Two mkv-audio-timing tests exercise ec-matroska's own packet stream, decoded through ec-aac/ec-ac3 exactly as the consumer does, against the sibling mp4 leg of the same OBS recordings and against ffmpeg: - mkv_vs_mp4_aac_pipeline: 3 real OBS mkv/mp4 pairs. ASC bytes identical, packet counts and byte totals identical, mkv pts strictly monotonic with no duplicates. Decoded PCM (ours-vs-ours and each vs ffmpeg) correlates at 1.0000, lag 0, for the two pairs with real signal; the third pair's near- silent audio (5180 bytes over 852 packets) reads 0.0 on every leg including mp4-vs-ffmpeg, which is a zero-variance correlation floor, not a defect. - mkv_51_channel_order: the two real-library 5.1 mkv rows the consumer sweep flagged (ReelF, E-AC-3; ReelG, AC-3). Our channel 0 matches ffmpeg's channel 0 at lag 0, corr 0.9999 and 0.9955 -- no channel-order mismatch. Root cause: neither of the charter's two ec-matroska-side hypotheses (lace/ pts damage to AAC packet delivery, 5.1 channel order) holds against real files -- this crate's demux and the shared ec-aac/ec-ac3 decode of it are byte- and sample-correct here. No code fix lands in ec-matroska because there is nothing wrong to fix in it for these files. The 0.06-0.34 mkv-leg correlation the consumer sweep saw, if still real, has to come from edith_replica's own consumption of these same packets (SymTrack's pts -> samples_at conversion, priming, or channel folding in crates/engine/src/audio.rs) rather than from container demux or codec decode -- reported, not fixed, since that file is out of this repo.
fix(aac): run PNS noise substitution before M/S and intensity stereoAhmet Kaan Gümüş · 7efd1d7
fix(aac): run PNS noise substitution before M/S and intensity stereo ISO/IEC 14496-3 §4.6.13 fills a PNS band's spectral coefficients with scaled noise; §4.6.8.1 M/S and §4.6.8.2 intensity stereo then combine those coefficients like any other spectral data. BlockDecoder::finish ran M/S and intensity stereo first, then filled PNS bands afterward, so any band coded as PNS in one channel still read zero when the stereo tools combined it -- the pre-fill zero got mixed into the other channel's coefficient (M/S) or copied outright (intensity), corrupting a real channel's data whenever the encoder mixed PNS with stereo coding on the same band. Reordered to match every reference decoder's decode order: PNS -> M/S -> intensity stereo -> TNS. Diagnostic path: chased a consumer sweep's finding of 0.76-0.92 (and one 0.0) whole-file correlation on a set of AAC-in-mp4 screen recordings against ffmpeg. Direct ec-mp4-demux -> ec-aac-decode measurement (crates/ec-aac/tests/obs_real_content.rs), lag-searched per the existing sbr_real_library.rs pattern, reads corr=1.0000 on every non-silent file both before and after this fix -- these files' PNS usage (1-13 AUs) apparently never lands on a band the M/S mask also marks, so the reorder is a real spec-order bug but not what produced that sweep's numbers; the sweep's own method likely lacked a wide-enough lag search and caught this file family's ~1024-sample (~21ms, one AAC frame) container/decode alignment offset instead. The single 0.0000 file is genuine digital silence in both decoders. Also chased a second repro (a real AAC-LC-in-mp4 download, sequential single-decoder scan, crates/ec-aac/tests/reelh_per_frame.rs): per-AU correlation reads 1.0000 across the whole 10.4s file except one near-silent intro AU where both decoders read ~0 RMS and the correlation ratio is numerically meaningless -- no reproducible mid-stream collapse found in this file at this crate's decode layer, with or without this fix. Added crate-level tool-usage side info (EC_AAC_TOOL_SIDEINFO_DEBUG, mirroring sbr_chain's SbrSideInfoRow pattern) and five ffmpeg tool-isolation fixtures (-aac_pns/-aac_is/-aac_ms/-aac_tns, one at a time and one with all four) wired into oracle.rs, all passing at >=0.999 correlation, to pin the fixed decode order and give any future PNS/IS/M-S/TNS regression a per-tool fixture to land on.
diag(aac-sbr): per-AU divergence starts at AU 0, not a per-frame triggerAhmet Kaan Gümüş · 4f80aee
diag(aac-sbr): per-AU divergence starts at AU 0, not a per-frame trigger New sbr_real_library.rs test per_au_low_band_divergence: decodes the same AU list through the core-only decoder and the full SBR chain, tracks each AU's own output sample range on both sides (so a per-AU decode failure does not desync the mapping), aligns the two streams ONCE using the same upsample+lowpass convention full_chain_low_band_matches_own_core already trusts (validated: reproduces reeln's known -576 lag / 0.996713 corr exactly), then reuses that single lag per AU. Findings: - reeln (PASSING baseline, 22050->44100 core/full): global align lag=-576 corr=0.996713 (matches ledger exactly -- harness calibrated). First AU below the per-AU 0.9 bar is AU 3, not AU 0 -- short (2048-sample) windows are just noisier than the whole-file 200k-sample window the passing gate uses, not a real per-frame break. - FMJ (FAILING, 24000->48000 core/full, implicit AOT2+syncext ASC [13 10 56 e5 98]): divergence starts at the very first AU with any output (AU 0) -- confirms this is a per-STREAM setup mismatch between the two decode paths, not a per-frame trigger. Global align lag lands at 20005, one past WIDE_LAG_MAX=20000's own coarse-search edge -- FMJ's true full-chain delay is apparently larger than every existing wide search in this file allows, unlike reeln's -576. - Synthetic heaac_44100_48k.m4a (FAILING, same 22050->44100 core/full pair as the PASSING reeln): also diverges from its first real AU. This refutes the "44.1k core/full rate pair itself is broken" reading of the synthetic matrix -- reeln uses the identical rate pair and passes, so the break tracks the STREAM, not the rate family. Config-diff hand-trace (task 2): parsed cfg (object_type/sample_rate/ sf_index/sbr_present/extension_sample_rate) is bit-identical in content between the explicit-SBR-object ASC form (AOT 5, e.g. the PASSING 48000 kbps=64k/96k synthetic rows, asc=[2b,11,88,00]) and the backward-compatible sync-extension form (AOT 2, e.g. FMJ and the 44100 fixtures, asc=[13,10,...]/[12,10]) for matching core/ext rates -- config.rs's two branches converge on the same AudioSpecificConfig struct. Both AacDecoder::with_config paths set sf_index from the same field either way, so table selection is not observably different at that layer. The earlier "explicit vs implicit signaling" and "core table fed the wrong rate" hypotheses this round's charter proposed are NOT supported by this trace; root cause remains open. No production fix landed this round -- 51+ prior rounds' worth of hypotheses (QMF convention, HF generation, zero-stuffing gain, kx geometry) are already dead-ended in the ledger, and this round's new evidence (divergence from AU 0, FMJ's true lag likely >20000) narrows but does not by itself localize the remaining bug within budget. GATE (unchanged from before this diff, confirming no regression from adding a diagnostic-only test): - sbr_real_library_matches_reference: FAILS as before, FMJ ch0 full -0.025253, ch1 full 0.010226 (baseline -0.025/0.010, unchanged) - full_chain_low_band_matches_own_core: FAILS as before, FMJ ch0 corr 0.217393 at lag 20005 (baseline 0.217393, unchanged) - synthetic_heaac_matrix: passes (LC control rows >=0.999) - ec-aac --lib: 45 passed, 0 failed
fix(mp3): propagate real decode errors from Mp3Reader::take, and fix a test comparison that never saw themAhmet Kaan Gümüş · cc3e0e3
fix(mp3): propagate real decode errors from Mp3Reader::take, and fix a test comparison that never saw them Root cause of the "open: NeedMore" symptom on this file was never in ec-mp3's per-packet frame/reservoir bookkeeping — that already decodes this cover-art-tagged, CRC-less 192kbps/48kHz stream correctly one frame per packet, matching ffmpeg sample-for-sample once the LAME encoder's lead-in is accounted for (measured lag 2210 interleaved samples = 1105 stereo frames = exactly StreamInfo::initial_padding). Two real bugs, both now fixed: - Mp3Decoder::take() used `while let Ok(frame) = self.reader.next_frame()`, so any real decode error (corrupt CRC, unsupported layer) — not just the expected "nothing more yet" NeedMore/Eof — was silently dropped instead of reaching send_packet's caller. take() now returns Result and only swallows NeedMore/Eof. - The new real-file regression test compared decoded audio against ffmpeg without accounting for initial_padding: ffmpeg trims the LAME/Xing encoder's lead-in from its PCM output; ec-mp3's raw decoder intentionally does not (registry.rs: callers must count and drop it themselves). The mismatch alone produced corr=0.53; trimming `initial_padding * channels` off the front before comparing gets corr>0.999.
feat(ec-hw): route coded-size-mismatched encode_frame sources through VPP region copyAhmet Kaan Gümüş · 58e23aa
feat(ec-hw): route coded-size-mismatched encode_frame sources through VPP region copy Encoder::encode_frame refused any source whose coded_size differed from the encoder's block-rounded one (HEVC rounds to 32, so a 3840x2160 source's 2160 stayed unrounded while the HEVC coded height became 2176). Add Vpp::convert_region (crates/ec-va/src/vpp.rs) — a VAProcPipelineParameterBuffer submission with explicit surface_region/output_region rectangles, no scaling — and route both 10-bit (P010) and now 8-bit coded-size-mismatched sources through it into the encoder's own NV12 pool, placed at (0,0) using frame.display_size. Encoder's own SPS conformance window / frame_cropping (already sized from EncoderConfig.width/height, independent of the source frame) makes the produced stream report the true visible size, not the padded coded one. The pool is painted black/neutral-chroma once on creation (Encoder::fill_black) so the padding rows a region copy never touches are deterministic rather than driver-fresh-allocation garbage. Real 4K HEVC Main10 mkv (3840x2160): - encode_frame_accepts_p010_via_vpp: HEVC now accepted and round-trips (worst Y inf dB, worst UV 96.2 dB vs the CPU path; H264 worst Y/UV inf dB), and ffprobe confirms the produced stream is 3840x2160 for both targets. - p010_zero_copy_encode_is_realtime (--release): H264 zero-copy 6.52 ms/frame median (CPU path 18.80), HEVC zero-copy 5.29 ms/frame median (CPU path 16.95) — both under the 20 ms/frame target. cargo test -p ec-va -- --test-threads=1: 13 + 6 doctests, all green. cargo test -p ec-hw --release --test gpu -- --test-threads=1: 27 passed.
fix(scan): leave the editor's own *.export*.mp4 artifacts out of the real-library manifestAhmet Kaan Gümüş · f9940e1Browse files
fix(aac-sbr): key SbrChain per-element state by (tag, is_cpe), not tag aloneAhmet Kaan Gümüş · 2a9df8d
fix(aac-sbr): key SbrChain per-element state by (tag, is_cpe), not tag alone
ISO/IEC 14496-3 §4.4: element_instance_tag is a namespace per syntactic
element type, so an encoder may legally give an SCE and a CPE in the same
access unit the same tag value (routine in a 5.1 SCE+CPE+CPE+LFE stream).
SbrChain::elements was a HashMap<u8, Element> keyed by the bare tag, so a
same-tagged SCE and CPE silently aliased one Analysis/Synthesis/HF/noise
state -- the CPE's parse/apply would read and mutate the SCE's element
state and vice versa. Rekeyed to (tag, is_cpe); decode.rs's three
sbr.apply/apply_last call sites now pass is_cpe through from `pending`.
Also stopped LFE (raw_data_block id 3) from ever becoming a pending SBR
target: §4.6.18.1 never applies SBR to the LFE channel (no FIL follows
it), so treating it like an SCE for `pending` could let a stray fallback
branch stretch the LFE plane to double rate using a held SBR payload that
belongs to a different, same-tagged element.
New regression test `an_sce_and_a_same_tagged_cpe_do_not_share_state`
proves an SCE at tag 0 is untouched by a same-tagged CPE's apply() call
in between two of the SCE's own calls; it fails without this fix.
Diagnostic finding: the assumption that motivated this investigation --
that the failing real-file test candidate (a BluRay-rip HEVC/mkv with a
real 6-channel HE-AAC track, tests/sbr_real_library.rs candidates(),
aac_stream=1) actually exercises that 6ch stream -- is WRONG. That
candidate's AudioSpecificConfig (asc=[13,10,56,e5,98]) decodes to
audioObjectType=2 (AAC LC), channelConfiguration=2 (stereo), sf_index=6
(24000 Hz core, SBR to 48000). ffprobe confirms the container's global
stream 1 is the real 6ch AAC track and global stream 3 is a separate 2ch
AAC track, but extract_aac_track's stream_index=1 (this test's
aac_stream) resolves to the 2ch track, not the 6ch one -- our_decode's
own debug output ("2 ch, 48000 Hz") already showed this before any
digging. This real-file failure is therefore NOT a multichannel/SBR-state
bug: this fix does not move sbr_real_library_matches_reference's
correlation for that file (unchanged at -0.025253/0.010226) or
full_chain_low_band_matches_own_core (unchanged at 0.217393). The other
real fixture (a stereo HE-AAC file, same-shape stream) stays at its prior
0.987006/0.986222 -- no regression.
GATE numbers (this commit):
sbr_real_library_matches_reference: stereo fixture 0.987006/0.986222;
the mislabelled candidate's SBR full-band bar 0.999 still fails,
unchanged from baseline -0.025253/0.010226
full_chain_low_band_matches_own_core: stereo fixture 0.996713/0.996842
(pass); mislabelled candidate 0.217393 (fail, unchanged from baseline
0.22)
ec-aac --lib: 45 passed (44 prior + 1 new regression test)test(ec-va,ec-hw): verify VPP filter probe, struct layout, and P010 zero-copy encode against a real 4K HEVC HDR fileAhmet Kaan Gümüş · cffd9af
test(ec-va,ec-hw): verify VPP filter probe, struct layout, and P010 zero-copy encode against a real 4K HEVC HDR file
ec-va/tests/gpu.rs: vpp_filters_probe (vaQueryVideoProcFilters on the real
display — radeonsi advertises only VAProcFilterDeinterlacing (2), no
HighDynamicRangeToneMapping) and vpp_converts_p010_to_nv12 (Vpp::convert
end to end).
ec-va/src/sys.rs: a const size_of/offset_of assert block for
VAProcPipelineParameterBuffer against va_vpp.h:886 (224 bytes on this
target, field offsets checked through va_reserved) plus
VAProcColorProperties — the layout was already correct, this just pins it.
ec-hw/tests/gpu.rs, against a real HEVC Main10 P010 4K HDR mkv:
- encode_frame_accepts_p010_via_vpp: encode_frame (zero-copy, P010 via VPP)
vs to_i420()+encode (CPU path), decoded back and compared. H.264: worst Y
and UV PSNR both infinite (byte-identical after decode). H.265 is refused
by encode_frame's own documented contract ("frame's coded size does not
match this encoder's ... the VPP conversion pass does not resize") because
this file's SPS pic_height_in_luma_samples (2160) is a multiple of the
H.264 encode block size (16) but not the HEVC one (32) — an existing,
intentional design choice, not a defect this round touched.
- p010_zero_copy_encode_is_realtime: median 6.14 ms/frame for
decode+encode_frame (H.264, the target that isn't refused on this file)
vs 22.55 ms/frame for decode+to_i420+encode — zero-copy is ~3.7x faster
and well inside the 20 ms budget.
cargo test -p ec-va -- --test-threads=1: 13 passed (+2 doctests, +4
compile-fail doctests).
cargo test -p ec-hw --release --test gpu -- --test-threads=1: 27 passed, 0
failed (most non-P010 tests skip: no generated bitstream fixtures on this
checkout).diag(aac-sbr): add a header/frame-feature discriminator table; fix two self-check instruments' stale/wrong lag conventionsAhmet Kaan Gümüş · 2b4d691
diag(aac-sbr): add a header/frame-feature discriminator table; fix two self-check instruments' stale/wrong lag conventions Task A: sbr_header_feature_table (tests/sbr_real_library.rs) prints one row per stream (reeln, FMJ, all 8 synthetic HE fixtures) of sbr_header()/ frame-level features (kx/k2, xover/start/stop freq, freq_scale, alter_scale, noise_bands, limiter_bands/gains, interpol_freq, smoothing_mode, per-frame num_env histogram, invf modes seen, add_harmonic usage, df_env/df_noise delta-coding rate, patch geometry) next to each stream's pass/fail correlation. Needed df_env/df_noise plumbed through SbrChannel and header params + patch lengths added to SbrSideInfoRow (src change, no behaviour change). Key finding: FMJ (fail, corr 0.036) and synth-48000-64k (pass, corr 1.000) share IDENTICAL kx/k2 (27/59), IDENTICAL header config, and IDENTICAL patch geometry [26,1,5] -- the only differences in the table are per-frame entropy (envelope-count histogram, invf-mode diversity), which is exactly what differing real-vs-synthetic CONTENT should produce on its own. This directly refutes "a per-stream SBR header/config feature separates pass from fail" (the standing hypothesis this task was chartered to test): no such feature exists in what sbr_header()/sbr_data() actually carries. Whatever breaks FMJ must be in the payload's numeric content or the container/extraction path, not the SBR sideinfo shape. Task B: full_chain_low_band_matches_own_core no longer hardcodes a stale QMF delay (-897); it now runs the same wide lag search `synthetic_heaac_matrix` uses and asserts corr >= 0.99 at the MEASURED lag. Confirms reeln's true lag is -576 (matches the ledger) at corr 0.997, and turns FMJ's already-known low-band self-inconsistency (round-51) into a real failing assertion instead of a silent print. synthetic_heaac_matrix's `ours_v_core`/`core_v_ref` columns: replaced the naive 2x-nearest-neighbor-upsample-then-lowpass-at-full-rate convention (which read a flat ~-0.12 regardless of file) with the native-core-rate decimate/`ffmpeg_decode_at_rate` convention `core_only_matches_reference` already trusts. This measurably fixed the 44100 family (core_v_ref now 0.44-0.995, proving the core decode itself is correct there even though the full chain fails at 0.07) but the 48000 family's core_v_ref is still flat/ negative despite `full`/`below` proving near-perfect correctness at native rate -- left open, most likely a remaining artifact in this resampling- domain comparison itself (ffmpeg's -ar downsample phase vs the wide-lag search), not a real SBR defect, since `below` already disproves it at the rate that matters. Correcting the charter's premise: core_v_ref did NOT read 0.9999 before this fix (measured 0.22-0.40 on 48000, near 0 on 44100) -- both self-check columns were broken, not one healthy one to copy.
feat(ec-hw): P010 encode_frame goes through a GPU-resident VAProfileNone/VideoProc VPP pass, not CPU read-backAhmet Kaan Gümüş · 67c8428
feat(ec-hw): P010 encode_frame goes through a GPU-resident VAProfileNone/VideoProc VPP pass, not CPU read-back encode_frame previously refused any 10-bit (P010) frame outright, forcing a consumer's HDR->proxy export onto to_i420()+re-upload for the whole path. This adds ec_va::Vpp (Config/Context/Buffer/Picture — all the existing generic VA-API machinery, no new unsafe outside ec-va) wrapping VAProfileNone/VAEntrypointVideoProc, and wires a lazily-built 2-surface NV12 pool + Vpp into ec_hw::Encoder: a 10-bit frame is converted P010->NV12 on the GPU (VAProcPipelineParameterBuffer, whole-surface, no filters) and then submitted through the exact same encode_surface() path as an 8-bit frame. radeonsi capability check (vainfo): VAProfileNone/VAEntrypointVideoProc is advertised on this GPU, confirming the entrypoint this crate now uses is real hardware support, not a driver gap. HDR->SDR tonemap (VAProcFilterHighDynamicRangeToneMapping) was NOT wired: sys.rs carries the filter-type constants and Vpp::filters() (vaQueryVideoProcFilters) to check for it, but the charter's own gpu.rs tests (PSNR/bench harness) were not written this round — see the ledger DELTA for the honest state of that gap. Scoped compiles green: `cargo check -p ec-va[--tests]`, `cargo check -p ec-hw[--tests]`. The 23-test `ec-hw --test gpu` regression and a live P010 decode+encode_frame+decode-back PSNR run were NOT executed this round (budget) — next round's first move.
fix(ec-matroska): derive laced-frame pts from the codec's own frame duration when the file states noneAhmet Kaan Gümüş · 73735ec
fix(ec-matroska): derive laced-frame pts from the codec's own frame duration when the file states none DefaultDuration absent on a track (e.g. an A_OPUS track laced 8 frames per SimpleBlock) collapsed every frame in a lace onto the block's base pts, so a seek landing mid-lace reported a pts up to ~145ms early. emit_block now steps each laced frame by, in order: DefaultDuration, an even split of BlockDuration, or a codec-derived duration (Opus TOC byte per RFC 6716, AAC's fixed 1024-sample frame) -- falling back to 0 only when none apply. Also fixes a distinct scale bug this surfaced: emit_block was dividing a codec-derived nanosecond duration by TimeBase::num(), which TimeBase reduces against 1e9 and is not the file's raw TimestampScale; the real TimestampScale is now kept on MatroskaDemuxer itself.
fix(aac-sbr): port the numpy-verified normative 64-band QMF bank into sbr_qmf.rs; delete the fitted Kaiser bankAhmet Kaan Gümüş · ddccd80
fix(aac-sbr): port the numpy-verified normative 64-band QMF bank into sbr_qmf.rs; delete the fitted Kaiser bank
Part (A)/(B) bisection (numpy, scripts/aac-tables/qmf_check.py):
zero-stuffing 32 core samples into the VERIFIED 64-band analysis
(x64[2m]=2*x32[m], odd=0), keeping bands 0..32 and dropping the
zero-stuffing image in bands 32..64, reaches corr=0.9994 against an
ideal band-limited 2x upsample (scipy resample reference) -- short of
the 0.9999 numpy target but a real, spec-traceable near-PR bank. The
per-k ratio probe (Analysis32 vs zero-stuff+Analysis64) showed the two
converge to a near-constant per-band complex factor after a few slots'
transient, consistent with the charter's predicted decimation identity,
but does not by itself explain Analysis32's/Synthesis32Downsampled's own
0.70-corr ceiling in isolation -- left as an open dead end, sidestepped
per charter option (B) instead of chased further.
crates/ec-aac/src/sbr_qmf.rs: `Analysis` and `HfAnalysis` now share one
`QmfAnalysis64` core (ISO/IEC 14496-3 4.6.18.4, the window-checksum-pinned
640-tap table from `sbr_qmf_window`); `Analysis` zero-stuffs its 32 core
samples into a 64-sample slot before running the shared core and keeps
the low 32 bands. `Synthesis` is the verified 4.6.18.8.2 64-band bank
directly. Deleted: `prototype`/`theta`/`modulation_tables`/
`analytic_gain`/`bessel_i0`/`sinc`/`KAISER_BETA`/`SYNTH_TRIM` (the fitted
Kaiser-window machinery this design used to build coefficients from).
crates/ec-aac/src/sbr_hf.rs: `band_shift_correction` returns 0
unconditionally -- the normative bank carries its own correct phase from
the spec equations directly, no per-slot quarter-turn patch-site
correction needed.
Removed 7 unit tests that encoded the fitted bank's own assumptions
(flat per-band synthesis gain, a specific band-index-to-frequency
mapping, the old patch-rotation convention) and no longer apply to the
literal spec equations' own indexing; kept/added: window checksum
(`qmf_window_checksum_matches_the_pinned_source`),
`round_trip_reconstructs_the_passband` (noise round-trip, unchanged,
still clears its native >=0.9999 bar for the multitone-passband case),
`synthesis_energy_gain_for_{white_noise,lowpassed_noise}_excitation`,
patch-map determinism (`sbr_hf::patch_map_is_deterministic_...`). Did
NOT add the charter's requested standalone "all-k passthrough tone" and
"patch p->p+8 coherence" tests -- out of this round's remaining budget,
left as a gap (see ledger).
GATE (cargo test -p ec-aac --lib): 44/44 pass (down from 50/50 pre-round;
6 net removed, see above).
GATE (cargo test -p ec-aac --test sbr_real_library):
reeln ch0 full-band corr 0.972474 -> 0.987006 (IMPROVED)
reeln ch1 full-band corr 0.969785 -> 0.986222 (IMPROVED)
FMJ ch0 full-band corr -0.024 -> -0.025253 (unchanged, pre-existing
documented defect per ledger round-46, unrelated to this bank)
full_chain_low_band_matches_own_core: PASS
sbr_real_library_matches_reference: FAILS on FMJ's worst_full>=0.999
bar (pre-existing, not caused or fixed by this round)
Did not merge main / run synthetic_heaac_matrix -- out of this round's
remaining tool-call budget; next round should do that first.feat(hw): expose HEVC prefix-SEI HDR peak and VUI colour tags on Frame/DecoderAhmet Kaan Gümüş · 7669974
feat(hw): expose HEVC prefix-SEI HDR peak and VUI colour tags on Frame/Decoder
edith's replica needs MaxCLL/MaxFALL for HDR films whose container never
carried them (they live only in HEVC content_light_level/mastering_display
SEI) — ec-hw's decode() dropped every SEI NAL on the floor. HevcDecoder now
merges ec_core::color::hevc_sei_light per access unit (sticky across frames
that carry none) and resolves VUI colour tags from the SPS; H264Decoder
resolves VUI tags only (no SEI parsing for that codec yet); VP9/AV1 report
None (not implemented). New Frame::colour()/Decoder::colour() surface it,
bundled as ec_hw::frame::Colour{description, light} over the existing
ec-core ColorDescription/ContentLight types.
Tests: hdr_film_light_level_sei_is_exposed pins MaxCLL/MaxFALL 1230/419 and
primaries/transfer/matrix 9/16/9 against the real ReelD rip;
sdr_h264_colour_never_panics proves the VUI-only path doesn't panic on an
SDR fixture (skips when no fixtures generated, same convention as the rest
of gpu.rs).fix(h264): drop leading pictures after a seek's open-GOP recovery pointAhmet Kaan Gümüş · 03dc6e9
fix(h264): drop leading pictures after a seek's open-GOP recovery point Root cause (crates/ec-h264/src/dpb.rs, crates/ec-h264/src/decoder.rs; mirrored in crates/ec-hw/src/dec/dpb264.rs, crates/ec-hw/src/dec/h264.rs): an open-GOP I picture is not an IDR — it is a plain I slice whose predecessors in decode order can still be referenced by pictures that follow it. A decoder started fresh at that I (exactly what a seek does) has none of those earlier references, so `build_ref_lists` pads the missing entries with whatever it has. The old code decoded and output those leading pictures anyway, handing back frames predicted from padded (garbage) references before the stream ever reaches a picture whose references are all real. Annex D.2.8 defines a `recovery_point` SEI whose absence (the common case, and this fixture's case) defaults `recovery_frame_cnt` to 0: the recovery point is the RAP's own POC, i.e. only pictures with a POC at or after the leading I's own POC are guaranteed fully referenced. The SEI itself is deliberately not parsed — the default already gives the correct threshold for the case that matters (mid-GOP seek), and a real non-zero `recovery_frame_cnt` is out of scope for this fix. `build_ref_lists` now returns whether it had to pad a list ((lists, padded)); `Decoder`/`H264Decoder` OR that per-slice into `cur_ref_padded`/`Current::ref_padded`, latch the first post-reset picture's POC into `recovery_poc` on `end_picture`/`finish_picture`, and compute `output_ok = !(ref_padded && poc < recovery_poc)`. `Dpb::store` takes that flag and marks the picture `Mark::Unused`-eligible for output gating (`pic.output = output_ok`) — it still joins the DPB as a reference and for bookkeeping, but a gated picture is never handed to a caller. `reset_pictures` clears `recovery_poc` so a later seek gets its own threshold. New test `h264_seek_matches_linear_open_gop` in both suites drives this through the real entry surface: fixtures/video/h264-open-gop.mp4 (x264 open-GOP, generated via scripts/gen-fixtures.sh) primes a fresh decoder with the leading IDR's parameter sets, resets picture state (a seek's exact contract), feeds it from the open-GOP I access unit before display frame 30, and asserts the first decoded picture matches a linear decode of frame 30. Confirmed failing before this fix (forcing output_ok true reproduces the mismatch) and passing after, on both the software decoder (crates/ec-h264/tests/conformance.rs) and the VA-API path (crates/ec-hw/tests/gpu.rs, real hardware). cargo test -p ec-h264: 70 lib + 23 conformance + 8 encode passed, 0 failed. cargo test -p ec-hw --test gpu -- --test-threads=1: 19 passed (18 pre-existing + the new one), 0 failed.
diag(aac-sbr): bisect the 0.62 cross-family QMF corr with same-rate 64->64 and 32->32 round-trips; cross-checks T1/T2/T3 refutedAhmet Kaan Gümüş · 4de6175
diag(aac-sbr): bisect the 0.62 cross-family QMF corr with same-rate 64->64 and 32->32 round-trips; cross-checks T1/T2/T3 refuted
64->64 (4.6.18.4 analysis, x of 640, newest at x[0] reversed, Z[n]=x[n]*c[n],
u folded by 5x128, X[k]=sum u[n]*exp(j*pi/128*(k+0.5)*(2n-1)) -> the existing
4.6.18.8.2 synthesis unchanged) round-trips at corr=0.999999, amp_ratio~1.0,
confirming the ORIGINAL hand-written equations (no sign flip, +j, (2n-1),
(2n-255), 1/64 scale) are correct for that pairing. This is exactly the
convention the first round already had.
Cross-check T1 (shift direction: both x/v buffers growing at the TOP,
forward-order new samples, vs the charter's reverse/newest-at-index-0) and
T2 ((2n+1) modulation index instead of (2n-1)/(2n-255)) are both REFUTED
under the 64->64 witness: every T1 (forward-shift) variant collapses to
corr 0.03-0.05 regardless of T2; every T2 (2n+1) variant with the correct
T1 shift stays close (0.9998-0.9999) but never beats the baseline (2n-1)/
(2n-255) config. T3 (drop the 1/64 synthesis scale) only rescales energy
(amp_ratio jumps to ~64x) and does not change corr, as expected -- the
window does NOT carry the normalization; the 1/64 factor is required.
32->32 downsampled (4.6.18.8.3: v of 640, shift 64, pi/64*(2n-63), w=g*c[2n])
tops out at corr=0.702744 (amp_ratio 0.807, energy 0.631) with the SAME
newest-at-x[0]/c[2n]/(2n-1) convention that gave 64->64 a clean pass --
i.e. the 32-band analysis or 32-band downsampled-synthesis half of the
bank (the c[2n]-subsampled / 320-tap path) is itself imperfect, not just
the 32-band-analysis-into-64-band-synthesis pairing.
Feeding 32-band analysis output (bands 0..31) into the CONFIRMED-correct
64-band synthesis (zero bands 32..63) drops further, to corr~0.05, across
every scale_k in {1,2,0.5,sqrt2} and both conjugate/non-conjugate X[k] --
worse than the earlier same-round ad-hoc 0.624 best (which used a
non-normative ssign/re_only combination, not this confirmed-correct
synthesis). The zero-stuffing-gain hypothesis (charter step 3) is REFUTED
under the correct-64-synthesis witness: scaling alone does not fix it.
Net: the 64-band same-rate pairing is spec-correct and verified; the
32-band analysis and/or 32-band downsampled-synthesis equations
(4.6.18.4.1 / 4.6.18.8.3, both built on the c[2n]/320-tap subsampled
window) are the remaining open defect, and the 32-band-analysis-into-
64-band-synthesis cross-family bridge used by real SBR HF generation is
not simple zero-padding -- something in the 32<->64 band correspondence
itself needs a different treatment than tested here. Still below the
0.999 numpy gate; no Rust changes this round either.diag(hw): bench + verify the 4K 10-bit frame path, no source defect foundAhmet Kaan Gümüş · a6922c1
diag(hw): bench + verify the 4K 10-bit frame path, no source defect found
Root-caused the four consumer symptoms against the real ReelD HDR film:
1. Frame-path speed (ec-hw/tests/gpu.rs::ten_bit_4k_frame_path_is_realtime):
120-frame bench, decode-only / +to_i420 / +to_i420_16 / +export_prime,
pending-4 back-pressure. In --release: decode+to_i420_16 median 10.36 ms
(39 ms budget, 3.8x headroom); export_prime 1.25 ms confirming sync()
itself isn't the cost. In debug (unoptimized): 139.88 ms -- most of the
consumer's 1352.5 ms/frame is optimization level plus consumer-side work,
not a defect in Frame::to_i420_16/to_i420/with_planes, which already do
the cached-vaGetImage, row-at-a-time, no-vaDeriveImage things the charter
asked to check for.
2/3. P010 chroma correctness (ec-hw/tests/gpu.rs::ten_bit_4k_chroma_is_not_grey):
3 real frames, to_i420 and to_i420_16 vs `ffmpeg -pix_fmt yuv420p{,10le}`,
Y and UV PSNR measured separately. Both bit-exact (Y and UV both inf dB)
at 8- and 10-bit -- the "grey chroma" symptom is not in frame.rs's P010
unpack on this file.
4. Colour metadata (ec-matroska/tests/matroska.rs::
real_hdr_film_container_states_no_light_metadata): the Matroska Colour
element for this file states primaries/transfer/matrix correctly
(bt2020/smpte2084/bt2020nc, matching ffprobe) but genuinely carries no
MaxCLL/MaxFALL/MasteringMetadata children -- confirmed against
`ffprobe -show_entries stream=side_data_list`, which is also empty.
ffprobe's 1230/419 comes from a `content_light_level_information` HEVC SEI
message on frame 0, not the container. ec-matroska is reading the
container correctly; the gap is that nothing in this workspace calls the
existing `ec_core::color::hevc_sei_light` reader (only self-tested in
ec-h265-syntax) from a real decode path -- named here, not implemented,
since ec-hw exposes no colour/light metadata surface at all today and
building one has no reachable consumer in this repo.
cargo test -p ec-hw --test gpu -- --test-threads=1: 20/20 green.
cargo test -p ec-matroska --lib: 9/9 green (the 3 --test matroska failures
are pre-existing missing-fixture errors, `scripts/gen-fixtures.sh` not run;
unrelated to this diff, the new matroska test passed).test(aac-sbr): split core-decode-wrong from SBR-scrambles-good-core in synthetic_heaac_matrixAhmet Kaan Gümüş · 5f50798
test(aac-sbr): split core-decode-wrong from SBR-scrambles-good-core in synthetic_heaac_matrix Adds core_v_ref (our core-only decode, 2x upsampled, vs the reference decoder, below crossover only, wide lag search) and its own lag, plus core_rate/full_rate (our_decode_core_only's vs our_decode's reported output rate) to every HE row -- core_v_ref lands at 0.99+ only when the SBR chain alone is guilty; near 0 when our own core decode of the fixture is already wrong, independent of any SBR machinery.
diag(aac-sbr): numpy round-trip of the normative 4.6.18.4.1/4.6.18.8.2 32/64-band QMF exhausts all listed carrier variants, dead endAhmet Kaan Gümüş · 93d147f
diag(aac-sbr): numpy round-trip of the normative 4.6.18.4.1/4.6.18.8.2 32/64-band QMF exhausts all listed carrier variants, dead end
scripts/aac-tables/qmf_check.py implements the analysis (32-band, ISO/IEC
14496-3 4.6.18.4.1) and synthesis (64-band, 4.6.18.8.2) equations exactly as
specified against the checksum-pinned 640-tap window, then round-trips 8192
white-noise samples through analysis -> zero-upper-32 -> synthesis and
correlates the decimated-by-2 output against the original at the best lag.
Impulse-response probe confirms the cascade is not garbage (a clean
symmetric twin-peak decaying kernel centred near the expected group delay),
but the broadband round-trip correlation tops out at 0.624 (newest-sample-
at-x[0], Z[n]=x[n]*c[2n], across both analysis and synthesis phase-sign
choices, Re-only vs Re+Im) -- far under the 0.999 gate. All four binary
alternatives from the charter (newest-sample position, c[2n] vs c[n],
analysis exp sign, synthesis Re-vs-both) were cross-producted (32 trials,
full table in run output); "scaling" is correlation-invariant so not a
separate axis. Output energy ratio is also off (~0.5x input energy where a
true PR interpolator should read ~2x), pointing at a real normalization/
equation bug beyond the four listed axes, not a coefficient tie-break.
Per the charter's gate ("only once numpy >=0.999: port to Rust"), this
round does not touch sbr_qmf.rs / sbr_hf.rs -- no Rust changes, no test
gate re-run. Recorded as a dead end for the next round.test(aac-sbr): widen synthetic_heaac_matrix's lag search past its own LAG_MAX edgeAhmet Kaan Gümüş · 93d654a
test(aac-sbr): widen synthetic_heaac_matrix's lag search past its own LAG_MAX edge best_lag_correlation's LAG_MAX=4000 bound was landing every HE-AAC row's winning lag right at its own edge (-3634..-3882); adds best_lag_correlation_wide (±20000, odd-stride coarse pass + full-WINDOW refine, mirrors wide_lag_search_full_chain's shape) and uses it for the full/below/ours_v_core columns plus a new ovc_lag column. Also fixes the `above` band, which was comparing o[..n]/t[..n] with no lag offset at all (only valid by accident at lag 0) -- now re-slices at the winning lag first, same convention sbr_real_library_matches_reference uses. Adds a delay-probe printout on two named rows testing candidate total HE-vs-reference delays.
diag(aac-sbr): normative 640-tap QMF window embedded, checksum-pinned; bank replacement reverted, dead end recordedAhmet Kaan Gümüş · 2928bfe
diag(aac-sbr): normative 640-tap QMF window embedded, checksum-pinned; bank replacement reverted, dead end recorded
Charter: replace sbr_qmf's fitted Kaiser bank with the normative ISO/IEC
14496-3 4.6.18.4/4.6.18.8 analysis/synthesis pair built from the provided
640-tap prototype table.
Embedded the table verbatim as crate::sbr_qmf_window::QMF_WINDOW with a
checksum test (sum/sum-of-squares/max/argmax) -- passes, table transcription
confirmed correct.
Implemented and empirically tried, in order, against a broadband-noise
round-trip correlation probe (independent of any real file):
1. The literal folded reading of 4.6.18.4/4.6.18.8 an external spec review
produced (320-sample analysis buffer folded 5-way to 64 taps, carrier
exp(j*pi/64*(k+0.5)*(2n-1)); 1280-sample synthesis overlap-add, carrier
exp(j*pi/64*(k+0.5)*(2n-255)), synthesis window built by mirroring the
640-tap table to 1280 samples) -- broadband round-trip correlation
plateaued at ~0.03-0.05 regardless of a grid search over analysis/
synthesis phase-intercept sign and offset (tried +-1, +-63, +-65, +-127,
+-129, +-255, +-511, 0) and an alternating-sign fold variant. Not a
near-miss: this structure does not reconstruct at all.
2. The prior fitted bank's own direct (unfolded) 640-tap-dot-product
structure, with the real QMF_WINDOW table substituted for the fitted
Kaiser prototype (no fold, theta = omega_step*(k+0.5)*(n+offset), one
omega_step per bank) -- best found ~0.697 correlation (offset=bands/2,
omega_step=pi/64 analysis / pi/128 synthesis, the fitted bank's own
convention), well short of the fitted bank's own 0.9998 achieved only
through its Kaiser-beta + cutoff fit. A grid over omega_step in
{pi/64, pi/128} x2 banks and offset in {+-16, +-32} never exceeded ~0.70.
Both avenues ruled out a fold-based reading of the reviewed equations
outright, and showed the review's exact phase-intercept constants (-1,
-255) are not simply a typo away from working with either window-derivation
guess. Given no access to the literal ISO text (only a review's paraphrase,
itself flagged "review, not ground truth") and no reference decoder's QMF
internals to cross-check against, further correction is a guess-and-check
search over an open constant space, not a bounded fix.
Reverted crates/ec-aac/src/sbr_qmf.rs and sbr_hf.rs to HEAD (4346f31) to
avoid shipping a QMF pair that round-trips at ~0.03-0.70 in place of one
that round-trips the passband at ~0.9998 -- verified unchanged real-file
numbers below.
DONE-GATE, unchanged from baseline (revert confirmed exact):
cargo test -p ec-aac --lib: 51 passed (50 baseline + 1 new window
checksum test), 0 failed.
reeln (44.1k): ch0 full-band corr 0.972474, ch1 0.969785 (both
unchanged); below 5000Hz 0.992799/0.992329, above 5000Hz
0.761967/0.746352; whole-file windowed mean 0.955717/0.951577.
FMJ (48k, kx=27): ch0 full-band corr -0.024069, ch1 0.010887 (both
unchanged, pre-existing catastrophic decorrelation, separately tracked).
sbr_qmf_window.rs's QMF_WINDOW is not wired into sbr_qmf (module doc there
states why); kept for the next attempt, which needs either the literal ISO
text or a reference decoder's QMF stage to check phase/window hypotheses
against instead of guessing.feat(ec-hw): zero-copy decode-to-encode surface path, VUI colour descriptionAhmet Kaan Gümüş · fc705c7
feat(ec-hw): zero-copy decode-to-encode surface path, VUI colour description Encoder::encode_frame submits a Frame's decoded VA surface directly as the encoder's source picture, with no to_i420 CPU read-back and no re-upload — what the consumer's previous backend did for a decode-then-encode pipeline. Refuses a cross-Display frame, a 10-bit (P010) source (no Main10 profile is built here), or a coded-size mismatch with a typed Error. EncoderConfig::colour(primaries, transfer, matrix, full_range) reaches the VUI of both the H.264 and HEVC packed SPS writers (video_signal_type_present_flag / colour_description_present_flag), so an HDR or BT.709 export stops reading back as "unspecified". Live-GPU tests in gpu.rs cover both: encode_frame vs the CPU-path baseline on the same decoded frames (PSNR compared, further: they came back byte identical on this driver), and ffprobe reading BT.2020/PQ/BT.2020nc back off a written stream while the no-colour-set case stays deterministic.