forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 03dc6e9978cbbbba112bf5c6ad925845ede8c744Filtered to crates/ec-aac/src/sbr_payload.rsClear filter

2026-08-19

fix(aac): uncoupled SBR CPEs read envelope+noise as two channel passesAhmet Kaan Gümüş · 3745d45
fix(aac): uncoupled SBR CPEs read envelope+noise as two channel passes

sbr_channel_pair_element()'s envelope/noise interleave depends on
bs_coupling: the coupled form reads sbr_envelope(ch)/sbr_noise(ch)
interleaved per channel, but the uncoupled form reads two separate
passes -- both channels' envelopes, then both channels' noise floors.
The parser (and the fixture rig's writer) read both forms the same,
per-channel-interleaved way. Total bit count is order-invariant, so
byte-accounting fixtures never caught it; content desyncs every field
after channel 0's envelopes whenever the channels' envelope (6/7-bit)
and noise (5-bit) field counts differ -- exactly the shape round-11
pinned to channel 1's second envelope going to garbage.

A synthetic uncoupled CPE (ch0 FIXVAR 4-env loud HF, ch1 FIXFIX 2-env
quiet HF -- the real failing shape) decoded to real PCM confirms the
fix: writing the two candidate orders and decoding both, the separated
(spec) order reproduces the coded amplitude cleanly while the
interleaved order desyncs it. Fixed the parser and the rig's CPE
writer together, regenerated CPE_UNCOUPLED_BODY (bits unchanged: order
is still byte-count-invariant).

reeln real-file sweep: ch0 full 0.9726 (unchanged), ch1 full
0.7716 -> 0.9705, ch1 above-crossover 0.0055 -> 0.7227. FMJ's separate
pre-SBR bug is unaffected and still queued last.
fix(aac-sbr): clamp envelope and noise rows to their field's own widthAhmet Kaan Gümüş · d1237c2
fix(aac-sbr): clamp envelope and noise rows to their field's own width

Defensive: a corrupt DT delta chain could previously snowball without
bound inside one frame. Measured zero effect on the real-file bar --
the implausible values there are legal within the field width, a
separate open defect.
fix(aac): SBR frames without a fresh FIL payload now reuse the last envelopeAhmet Kaan Gümüş · f505821
fix(aac): SBR frames without a fresh FIL payload now reuse the last envelope

The windowed lag-drift diagnostic (new EC_AAC_SBR_DRIFT test knob) showed
discrete lag PLATEAUS jumping by exactly 1024 samples -- the core frame
length -- rather than a smooth per-sample drift. Root cause: raw_data_block
only doubled an SCE/CPE's plane when its immediately-following FIL element
carried a fresh SBR payload this frame; any access unit whose FIL was
missing, non-SBR, or failed to parse silently left that one AU at core
(1024-sample) length, permanently shifting every sample after it out of
alignment with a reference that stayed at doubled rate throughout. 67 such
skips were happening across the two-file sweep.

SbrChain now caches each element's last successfully parsed SbrData and
apply_last() re-runs the chain with it whenever a frame's own payload is
unavailable (Amd 4.6.18's documented "hold state" behavior), so every AU
still doubles.

reeln ch0: -0.034 -> 0.973 full-band, 0.995 below crossover (bar 0.999
full / 0.9999 below still open). ch1: 0.014 -> 0.772 full-band (plateau
structure now flat, remaining gap not yet root-caused). FMJ unchanged
(separate pre-existing 11/1500-AU decode failure, documented dead end,
left for last per the queue).

Added a unit test (sbr_chain::tests) that runs two adjacent synthetic AUs
through one SbrChain element and asserts both double to the full 2048
samples with no discontinuity at the junction -- the coverage hole the
continuous-stream QMF round trip never exercised.
fix(aac-sbr): the missing bs_pointer field and FIXVAR's reversed freq_resAhmet Kaan Gümüş · 7dabfff
fix(aac-sbr): the missing bs_pointer field and FIXVAR's reversed freq_res

FIXVAR/VARFIX/VARVAR sbr_grid() all carry a bs_pointer field (width
ceil(log2(num_env+1))) between the relative borders and bs_freq_res, which
this parser never read -- and FIXVAR alone transmits bs_freq_res in reverse
time order (envelopes are numbered from the trailing variable border
backwards). Confirmed against a reference decoder's own byte accounting on
a non-uniform freq_res list (scripts/aac-tables/sbrgrid_probe.py) -- a
uniform list hid both bugs, which is why the byte-exact fixtures never
caught them. The missing pointer field also explains the standing "VARVAR
num_env==3 reads one byte fewer" mystery: ptr_bits(3)=2 crosses a byte
boundary.

bs_pointer also drives the noise floor's middle time border (ISO/IEC
14496-3 Sec 4.6.18.3.3), which this parser was deriving with a
nearest-midpoint heuristic instead; Grid::new now follows the spec formula.

Adds a plausibility clamp on the carried DT state (last_env/last_noise) as
containment against any still-undiscovered desync, not a fix for one.

Regenerates the FIXVAR/VARFIX/VARVAR fixtures from the corrected wire
format (all still oracle-verified byte-exact).
fix(aac-sbr): apply the envelope gain before noise injection, not afterAhmet Kaan Gümüş · 90930dd
fix(aac-sbr): apply the envelope gain before noise injection, not after

sbr_env::adjust injected the transmitted noise floor into the HF QMF
signal before measuring the (envelope, band) cell's current energy and
computing the gain toward the transmitted target -- so gain was
computed from signal+noise together and then rescaled both, distorting
the noise/signal split by however much noise dominates a given cell.
Move noise injection after the gain loop (signal only informs gain,
noise is added at its own transmitted amplitude afterward), matching
the spec order. Real-file sweep correlation barely moved from this
alone (0.019/0.834 and 0.005/0.0001 before and after), so it is a
real but non-dominant contributor to the residual failure; see the
localization note left for the next pass.

Also added an EC_AAC_SBR_ENV_DEBUG-gated dump in decode_envelope that
pinpointed the dominant remaining defect: multi-envelope real-file
frames occasionally carry a raw (non-delta) envelope whose absolute
value is inconsistent with every neighbouring envelope's magnitude in
the same frame (observed: FMJ ch0 frame 24's envelope 3 reads raw=43
right after envelopes 0-2 all sit at 8-10, and the frame's own core
PCM never exceeds ~9600 in this domain, so a target energy of 2^43 is
unreachable by any correctly functioning HF patch of that content).
That corrupted value then persists and grows across frames via the
cross-frame DT envelope prediction (self.state[ch].last_env), which
does no plausibility check on what it carries forward. Root bit-level
cause not yet found: env0-2 in the same frame decode plausibly, ruling
out a bit-count bug in bs_data_extra/bs_coupling/sbr_grid/sbr_dtdf/
sbr_invf that would already have desynced env0. Next step: instrument
whether this specific raw envelope's df_env bit is being read at the
position the FIXVAR/VARFIX/VARVAR grid class actually places it, since
these real files exercise those unverified border-value grid classes
(sbr_payload.rs's honest gap) far more than the byte-exact FIXFIX
fixtures.
feat(aac): wire SBR HF gen + envelope adjustment into the decode chainAhmet Kaan Gümüş · 5206266
feat(aac): wire SBR HF gen + envelope adjustment into the decode chain

sbr_chain.rs ties sbr_payload/_hf/_env/_qmf together per element: a
FIL element's sbr_extension_data (explicit ASC signaling only, no
implicit ADTS detection yet) drives 32-band analysis of the preceding
SCE/CPE's core PCM, HF generation, envelope adjustment, and 64-band
resynthesis, replacing that element's plane with double-rate PCM.

SbrSupport gains a V1 variant (PS still reports CoreOnly);
output_sample_rate now reports the extension rate for a reconstructed
stream. sbr_is_reported_not_silently_upsampled is updated (not
deleted) to pin the new contract, plus a PS case.

Not yet exercised: real-file oracle correlation (next commit),
implicit ADTS SBR signaling (deferred, named follow-up per charter),
filterbank delay compensation for packet timestamps (open -- see
report).
feat(ec-aac): the SBR payload parser -- bitstream to dequantized envelope/noise intsAhmet Kaan Gümüş · 6a3d21e
feat(ec-aac): the SBR payload parser -- bitstream to dequantized envelope/noise ints

sbr_payload.rs parses sbr_header (persisted across frames) and sbr_data for
SCE and CPE (coupled and uncoupled), all four grid classes, dt/df envelope
and noise coding through the twelve Huffman books, and extension payloads by
their own length. Stops at exact integer scalefactors/noise floors -- no
QMF, no gain application.

Field widths and grid-class bit layout checked against a reference
decoder's own byte accounting via scripts/aac-tables/sbrpayload_fixtures.py
(same method as sbrtables.py's codebook derivation), which also generates
the byte-exact test fixtures embedded in the module's test module.