forge
Explore
Log in

Don't you dare go Hollow

diag(sbr): fix source-band placement math to 32 bins/band, surface a deeper SBR-engagement blocker

Browse files at this commit

7049a6cc304b5b36e7c07ea71129164c467f35b5Ahmet Kaan GümüşParent: a913c84
sbrpatchmap.py's probe placed its isolated tone at k = p*16 + offset,
assuming a source (low) QMF band is 16 core-MDCT bins wide. It is 32
(1024-bin core MDCT / 32 core bands). Fixed to k = p*32 + 16 (band
center, lands cleanly on a group boundary so no fractional-offset
trick is needed).

Calibrating that fix against the unambiguous header-A anchor
((13, 42, 1), a width-1 patch) surfaced a deeper, blocking problem:
ffprobe shows these synthetic ADTS probe streams never engage the
reference decoder's SBR/HE-AAC upsampling at all (sample_rate=22050,
no HE-AAC profile, decoded PCM length exactly core-rate), unlike the
real reeln fixture (profile=HE-AAC, sample_rate=44100). The "No
quantized data read for sbr_dequant." warning's raw occurrence count
(fires once per 26-frame stream) reads as benign by the charter's own
heuristic but is not: an env0 power sweep shows the predicted target
window is flat while a large, smoothly-scaling, envelope-driven signal
appears well outside it, and never flips the decoder into HE-AAC
output. Reproduces for both tone_core and broadband_core_bits content,
so it's a property of the shared frame/extension-payload construction,
not either core-spectrum writer -- a generalization of round-27's
tone_core-specific dead-end.

Sanity gate (our decoder's map == build_patches prediction) and the
reference-map read are both gated on fixing that engagement bug first;
sbr_hf.rs is left untouched pending it. crates/ec-aac --lib: 40/40.
scripts/aac-tables/sbrpatchmap.pymodified+65 -27
@@ -36,30 +36,59 @@ reference's stderr for "No quantized data read for sbr_dequant." -- if
3636 present the run used a shape that leaves the SBR gain stage unengaged and the
3737 decode is not trustworthy.
3838
39-STATUS (round-29): the sanity gate still FAILS after two real fixes landed
40-this round (see the ledger's round-29 facts): (1) `sbr_bits_full`'s `slot()`
41-default (`T.FILL`, 24 raw zero bits) desyncs the bitstream whenever a
42-multi-band delta run is used -- ENV30_F/NOISE_F's shortest codeword (the one
43-"0" bits actually decode as) is only 1 bit, so 23 excess zero bits per slot
44-leak into every field transmitted after it; `stream_one_band` now supplies
45-exactly enough real 1-bit zero-delta codewords instead (fixed, confirmed via
46-`EC_AAC_SBR_DEBUG`: `e_q[1]`/`q_q[1]` now read back the intended raw values,
47-were silently zeroed before). (2) The tone's fractional-offset placement
48-(`GROUP_OFFSET`) is unaffected by that fix. What remains OPEN: `k = active_p
49-* 16` (the MDCT-bin-per-QMF-band assumption every prior round's readout used,
50-inherited unchanged here) does not track the true source-band placement --
51-calibration by sweeping raw bin `k` and reading which target band lights up
52-shows a clean *32*-bin-per-band slope (not 16) locally, but with an offset
53-that is NOT a fixed constant across headers (k=64 lands on `target == kx`
54-for headers A and C, whose `patches[0]` happens to have `source_start == 0`,
55-but for header B -- `xover_band=1`, whose `patches[0]` has `source_start ==
56-2` -- k=64 *also* lands on `target == kx`, meaning it tracked `source_start`
57-itself, not a fixed `p`). The low/source band index space is not a simple
58-`p*N + offset` function of MDCT bin position; it needs deriving from the
59-tables' own low-band structure rather than assumed, which this round did not
60-reach. Sanity gate: DO NOT trust `measured(ref)` output below until this is
61-resolved -- Task 2/3 (reading and acting on the reference's map) are blocked
62-on it.
39+STATUS (round-30): the bin-per-band placement math is now fixed -- a source
40+QMF band is 1024/32 == 32 core-MDCT bins wide, not 16, so `stream_one_band`
41+places its probe tone at `k = active_p * 32 + 16` (the band CENTER, which
42+also lands exactly on a 4-bin group boundary, so no fractional-offset trick
43+is needed; `D` is 0.5, not 0.25). That fix, however, could NOT be calibrated
44+against the header-A anchor `(13, 42, 1)`, because a DEEPER, BLOCKING defect
45+was found first: the reference decoder is not actually engaging its SBR
46+upsampling path for ANY of these synthetic ADTS probe streams at all, for
47+either `tone_core` or `broadband_core_bits` content, regardless of header
48+shape (A's kx=14/k2=43 and the round-19 DEFAULT shape both affected
49+identically) --
50+
51+ - `ffprobe` on a probe stream built by `stream_one_band`/`stream` reports
52+ `codec_name=aac`, NO `profile=HE-AAC`, `sample_rate=22050` (the bare
53+ core/ADTS-declared rate) -- vs. the real `~/Music/reeln.mp4`
54+ fixture (round-19's working baseline), which reports
55+ `profile=HE-AAC sample_rate=44100`. Decoded PCM length for a 26-frame
56+ probe is exactly `26 * 1024` samples, i.e. literally core-rate output,
57+ never doubled -- this is not just a metadata-reporting quirk, the actual
58+ decoded sample count proves SBR upsampling never ran.
59+ - This is NOT visible from the `"No quantized data read for sbr_dequant."`
60+ warning's raw occurrence count alone: it fires only ONCE across a
61+ 26-frame stream (24 of them real SBR frames with `header=1` every
62+ frame) -- by the charter's own "once-or-twice = benign" heuristic this
63+ reads as a clean, engaged run. It is NOT: an envelope-value sweep
64+ (`env0` raw 3..63, `amp_res=1`) shows the power *inside* the
65+ `[kx*BAND_HZ, k2*BAND_HZ)` window our own table math predicts is
66+ completely FLAT (no order-of-magnitude movement -- fails the charter's
67+ own engagement test outright), while a huge, smoothly env0-scaling
68+ power increase (orders of magnitude, from ~18 to ~6e9) shows up OUTSIDE
69+ that window, concentrated roughly 9-15 kHz and tailing out past 20 kHz
70+ -- i.e. real envelope-driven energy exists, but not where our table
71+ math says the SBR target band should be, AND it never causes the
72+ decoder to report itself as HE-AAC/44100 the way the real file does.
73+ The likely explanation: without an out-of-band MPEG-4 `AudioSpecificConfig`
74+ (which the real `.mp4` fixture's container carries and our bare `.aac`
75+ ADTS files do not), the reference decoder's *implicit* SBR detection
76+ from frame 1's fill element is deciding "no SBR" once, on the very
77+ first payload frame, and locks the whole stream's output rate to
78+ core-only from then on even though later frames carry ostensibly valid
79+ bits -- consistent with, and a generalization of, round-27's dead-end
80+ (`tone_core` "does not round-trip" against the real header/grid shape),
81+ now shown to affect `broadband_core_bits` identically, so it is a
82+ property of the shared frame/extension-payload construction in
83+ `stream()`/`stream_one_band()`, not of either core-spectrum writer.
84+
85+Sanity gate: DO NOT trust `measured(ref)` output below -- it is not reading
86+genuine SBR-patched content at all, in either the old or new placement math.
87+Task 2/3/4 (reading and acting on the reference's map) remain BLOCKED, now
88+on getting the synthetic ADTS fixture writer to genuinely engage the
89+reference's implicit SBR/HE-AAC upsampling path (matching the real file's
90+`profile=HE-AAC sample_rate=44100`), not on the placement-math bug this
91+round set out to fix.
6392 """
6493 import os
6594 import subprocess
@@ -79,8 +108,17 @@ SF_INDEX = 7
79108 RATE = 44100
80109 OUR_DECODER = os.path.expanduser("~/.cache/cargo-target-sbr/debug/examples/adts_to_pcm")
81110 BAND_HZ = RATE / 128 # QMF band width, both source and target index units
82-D = 0.25 # fractional offset (of one band width) the probe tone is placed at
83-GROUP_OFFSET = 4 # bins: 4/16 == D, the finest offset tone_core's grouping allows
111+# Round-30 fix: a source (low) QMF band is 32 core-MDCT bins wide (1024-bin
112+# core MDCT / 32 core bands), not 16 -- every prior round's k = p*16 + offset
113+# was reading the wrong bin for band p entirely, not just the wrong in-band
114+# offset. Placed at the BAND CENTER (bin 16 of the 32), which lands exactly
115+# on a 4-bin group boundary (16 % 4 == 0) so tone_core's grouping needs no
116+# fractional-offset trick. A center tone's fractional position within its
117+# 32-bin source band is 0.5; patches translate by whole band widths, so the
118+# translated line keeps frac == 0.5 in its target band too (or 1-0.5 == 0.5
119+# under mirroring -- indistinguishable at the center, which is fine, this
120+# probe only needs the TARGET BAND INDEX, not direct/mirror discrimination).
121+D = 0.5 # fractional offset (of one band width) the probe tone is placed at
84122 NO_QUANT_WARNING = "No quantized data read for sbr_dequant."
85123
86124
@@ -142,7 +180,7 @@ def stream_one_band(cfg, tables, active_p, n_frames=24, invf_mode=0):
142180 group (offset `D` of a band width into the band, not the ambiguous
143181 boundary bin), held fixed; invf NONE, no harmonics."""
144182 swb = P.SWB_LONG[SF_INDEX]
145- k = active_p * 16 + GROUP_OFFSET
183+ k = active_p * 32 + 16
146184 found = bin_to_sfb_group(k, swb)
147185 assert found is not None, f"band {active_p} bin {k} not in SWB_LONG[{SF_INDEX}]"
148186 sfb_idx, group_active = found