forge
Explore
Log in

Don't you dare go Hollow

Tone_core's pulse/tns/gain flags sat after spectral data, not before

Browse files at this commit

23f057e2d13593f68f2f4078ea11ce1a022f6113Ahmet Kaan GümüşParent: e3a8adf
  • fix
    • tone_core's pulse/tns/gain flags sat after spectral data, not before
Show full message
fix(sbr-probe): tone_core's pulse/tns/gain flags sat after spectral data, not before

tone_core() (scripts/aac-tables/sbrchirp.py) is the isolated-single-MDCT-line
probe writer used by sbrpatchmap.py's patch-map fingerprinting; it desynced
the reference decoder on every real-header probe ("channel element X.Y is not
allocated" / "buffer exhausted before END"). Byte-accounted against sce_core's
proven field order: the `pulse_data_present/tns_data_present/gain_control_
data_present` 3-bit field must precede spectral_data(), not follow it -- the
misplaced write shifted every bit after it. Core-only round-trip is now
byte-clean (0 errors) and the real reeln header/grid shape (kx=14/k2=43)
decodes to nonzero PCM instead of 0.

Also fixes sbr_hf.rs's `real_file_tables()` test fixture, whose stop_freq=3/
xover_band=2 guess was wrong (gave kx=16/k2=29); the real value read off the
file's own bitstream is stop_freq=8/xover_band=0 (kx=14/k2=43) -- confirmed
build_patches() on the corrected header exactly matches sbrpatchmap.py's
independently-ported prediction: [(0,14,14),(3,28,11),(0,39,3),(13,42,1)].

Running the full three-header patch-map sweep against both the reference and
our own decoder (adts_to_pcm) surfaced a new blocker, not fixed here: our own
decoder's *measured* map disagrees with build_patches' own prediction (empty
for source band 0, a constant band range for every other source band) even
though build_patches itself is proven correct in isolation -- the runtime HF
generation/envelope path or the probe's PCM analysis is unverified, not
build_patches. Per the probe's own sanity rule this blocks trusting the
reference's measured map until resolved.
crates/ec-aac/examples/adts_to_pcm.rsmodified+3 -1
@@ -5,7 +5,9 @@
5 use std::io::Write;5 use std::io::Write;
6 6
7 fn main() {7 fn main() {
8- let path = std::env::args().nth(1).expect("usage: adts_to_pcm <file.aac>");8+ let path = std::env::args()
9+ .nth(1)
10+ .expect("usage: adts_to_pcm <file.aac>");
9 let data = std::fs::read(&path).expect("file readable");11 let data = std::fs::read(&path).expect("file readable");
10 // Plain `AacDecoder::new()` never enables SBR (it only turns on from an12 // Plain `AacDecoder::new()` never enables SBR (it only turns on from an
11 // explicit AudioSpecificConfig's `sbr_present`, per `with_config`) --13 // explicit AudioSpecificConfig's `sbr_present`, per `with_config`) --
crates/ec-aac/src/sbr_hf.rsmodified+6 -6
@@ -354,12 +354,12 @@ mod tests {
354 use crate::sbr_bands::freq_tables;354 use crate::sbr_bands::freq_tables;
355 355
356 fn real_file_tables() -> BandTables {356 fn real_file_tables() -> BandTables {
357- // The rig's own header params for ~/Music/reeln.mp4's SBR357+ // The real file's actual SBR header, read straight off the
358- // element (44100 Hz extension rate, core-Nyquist crossover ~5 kHz):358+ // bitstream (round-27/28: start_freq=5 stop_freq=8 xover_band=0
359- // freq_scale=2, alter_scale=1, noise_bands=2, start/stop/xover taken359+ // freq_scale=2 alter_scale=1 noise_bands=2 -> kx=14 k2=43 n_q=3;
360- // from the mid-range defaults `EXTRA1_DEFAULTS` documents when a360+ // the previous stop_freq=3/xover_band=2 guess gave a smaller,
361- // stream omits bs_header_extra_1/2.361+ // wrong kx=16 k2=29 header).
362- freq_tables(44100, 5, 3, 2, 1, 2, 2).expect("valid header for the real file's rate")362+ freq_tables(44100, 5, 8, 2, 1, 0, 2).expect("valid header for the real file's rate")
363 }363 }
364 364
365 #[test]365 #[test]
scripts/aac-tables/sbrchirp.pymodified+4 -1
@@ -87,6 +87,10 @@ def tone_core(w, sfb_idx, group_active, gain=200):
87 w.w(3, 4)87 w.w(3, 4)
88 w.w(1, 5)88 w.w(1, 5)
89 w.w(P.HCB_SF[60][1], P.HCB_SF[60][0]) # scalefactor delta 089 w.w(P.HCB_SF[60][1], P.HCB_SF[60][0]) # scalefactor delta 0
90+ w.w(0, 3) # pulse/tns/gain-control absent -- MUST precede spectral_data()
91+ # (round-28 fix: this write sat AFTER the spectral loop below, shifting
92+ # every bit that followed and desyncing the reference decoder on every
93+ # probed band -- byte-accounted against sce_core's proven field order.)
90 ngroups = (swb[sfb_idx + 1] - swb[sfb_idx]) // 494 ngroups = (swb[sfb_idx + 1] - swb[sfb_idx]) // 4
91 for i in range(ngroups):95 for i in range(ngroups):
92 quad = (2, 0, 0, 0) if i == group_active else (0, 0, 0, 0)96 quad = (2, 0, 0, 0) if i == group_active else (0, 0, 0, 0)
@@ -95,7 +99,6 @@ def tone_core(w, sfb_idx, group_active, gain=200):
95 w.w(code, length)99 w.w(code, length)
96 for _ in signs:100 for _ in signs:
97 w.w(0, 1)101 w.w(0, 1)
98- w.w(0, 3) # pulse/tns/gain-control absent
99 return w102 return w
100 103
101 104