forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 552edc4cede0dfd9bebbc4e344242802802d15ccFiltered to crates/ec-aac/src/sbr_payload.rsClear filter

2026-08-21

2026-08-20

fix(aac-sbr): delta-time envelope base mapped across freq-res changes; locator gains target-vs-reference per-band rows; WIP audio readout for the 3 dB booksAhmet Kaan Gümüş · 46f3447
fix(aac-sbr): delta-time envelope base mapped across freq-res changes; locator gains target-vs-reference per-band rows; WIP audio readout for the 3 dB books

- sbr_payload: a DT-coded envelope whose resolution differs from the one it is
  coded against now takes its base band-mapped (high<-containing low band,
  low<-high band at the same edge) instead of index-for-index (the top half of
  such a high-res row read base 0). reeln locator: +0.01 corr/level above
  7 kHz, full-band unchanged.
- sbr_env/noise_fraction_table: 4th column = realised |Y|^2 per QMF band, so
  realised/target is readable (it is 1.00 everywhere: the adjuster hits its
  target; the residual HF tilt is target-side).
- locator: EC_AAC_SBR_LOCATOR_FILE points it at any file; TARGET rows print
  target vs reference PCM per band.
- ROOT CAUSE FOUND, NOT YET FIXED: sbr_tables.rs ENV30_F/ENV30_T/ENVB30_F/
  ENVB30_T carry 0 for every positive delta (32/32/13/13 entries) -- the
  range-check learner cannot see a positive 3 dB delta (6-bit raw field,
  7-bit check ceiling). ENV30_T also holds duplicate codewords. Envelopes can
  only fall across bands -> the measured -5.5 dB/oct vs reference -2.5 dB/oct
  HF tilt on pink noise and the 0.6 HF level on reeln. sbrvalues_audio.py
  is the audio-readout replacement, decoding probe frames to PCM; it does not
  work yet (the probe's SBR payload reads one byte longer than written and the
  decoder drops SBR).
fix(aac-sbr): coupled balance raw values count in double steps (centre 6/12), pan offset and alpha from the frame's amp_res; FIXFIX-only single-envelope amp_res overrideAhmet Kaan Gümüş · e6128af
fix(aac-sbr): coupled balance raw values count in double steps (centre 6/12), pan offset and alpha from the frame's amp_res; FIXFIX-only single-envelope amp_res override

reeln coupled CPE: full-band corr ch0 0.998652 -> 0.999210, ch1 0.996600 -> 0.999176.
Adds sbr_residual_locator (per-band complex-STFT corr/level, Parseval-exact) which
showed the previous ch1 HF level at 0.35-0.45 of the reference.
fix(aac-sbr): spec-structured envelope adjuster (per-subband gains, limiter/boost with S_M and Q_M, V-table noise, sinusoid phases, slot smoothing, l_A/delta, 6-slot tHFAdj alignment, class-correct noise border, coupled noise dequant)Ahmet Kaan Gümüş · 363af1c
fix(aac-sbr): spec-structured envelope adjuster (per-subband gains, limiter/boost with S_M and Q_M, V-table noise, sinusoid phases, slot smoothing, l_A/delta, 6-slot tHFAdj alignment, class-correct noise border, coupled noise dequant)

reeln full 0.9927/0.9918 -> 0.9953/0.9946, above-5k 0.9868/0.9918 -> 0.9985/0.9984, lag 385 -> 1.
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.

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.