Commits
Commits on
8dbd683068d7f87f21dcc4ed1dfdca786d82c52bFiltered to crates/ec-aac/src/sbr_env.rsClear filter2026-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): native 32-band QMF analysis replaces the zero-stuffed bridge; drop ENV_DOMAIN_SCALEAhmet Kaan Gümüş · b61d50e
fix(aac-sbr): native 32-band QMF analysis replaces the zero-stuffed bridge; drop ENV_DOMAIN_SCALE The bridge (64-band bank on the core zero-stuffed at the even phase) equals the 32-band bank times 2*exp(j*pi/64*(k+0.5)*1.5) per band: 2x gain and a 1.5-output-sample delay. The low band never saw it (synthesis undoes both) but the HF generator copies band p into band k, so the per-band phase became a constant carrier error on every patched band against the reference. Carrier offset is -0.5 (reference-measured; the literal -1 lands the reference half a sample off, 0.984 above 5 kHz vs 0.9997). Real-library: reeln full 0.9964/0.9956 -> 0.9987/0.9966, above-5k 0.9990/0.9987 -> 0.9997/0.9993; second file full 0.9979/0.9935 -> 0.9999/0.9993. synthetic_heaac_matrix: every HE row up (44.1k/32k full 0.9376 -> 0.9823, 48k 64k/96k above 0.9857 -> 0.9999), LC rows unchanged. Envelope energies now dequantize in the spec domain directly; the 2x the spec 32/64 pair loses is restored once at the chain output.
fix(aac-sbr): spec patch construction (4.6.18.6.3) + 64x domain scale on E_orig; per-QMF-band ours-vs-reference instrumentAhmet Kaan Gümüş · 40bfd30
fix(aac-sbr): spec patch construction (4.6.18.6.3) + 64x domain scale on E_orig; per-QMF-band ours-vs-reference instrument Patches were a local heuristic copying DC/bass bands into the top patch, starving every limiter band (per-band coherence 0.05, HF 20-35 dB low). reeln full 0.9953/0.9946 -> 0.9964/0.9956, per-band coherence 0.87-0.90, level within 2 dB.
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+fix(aac-sbr): per-limiter-band LIMDUMP audit + spec-correct Yule-Walker AR(2)Ahmet Kaan Gümüş · 190e8e3
diag+fix(aac-sbr): per-limiter-band LIMDUMP audit + spec-correct Yule-Walker AR(2) Round-57 audit (ISO/IEC 14496-3 4.6.18.7.5/.7.6), heaac_48000_64k.m4a: Added EC_AAC_SBR_CELLDUMP-gated per-limiter-band trace (sbr_env.rs `adjust`): one LIMDUMP line per (envelope, limiter band j) with the exact aggregate quantities the spec's two equations operate on -- E_orig_mapped[j], E_curr[j], G_max[j]=limGain*sqrt(ratio), capped_cells/total, E_actual[j], G_boost[j]. Confirms the ledger's task-3 suspect directly: limiter band j=1 ([42,59), the patch-width-1 cell's band) has E_curr inflated to 1e10-1e11 against an E_orig_mapped of 1e4-1e6 nearly every frame (not just the t=18s/24s cliff window) -- capped_cells stays 5/6 and G_boost pegs at BOOST_MAX (1.584893) almost continuously, meaning that band structurally never reaches its transmitted target by ~3-10dB. One outlier cell's astronomically large `cur` poisons the AGGREGATE cap for every other cell sharing its limiter band (spec-correct aggregate behavior, applied to a defective per-cell energy estimate). Root cause traced to `lpc2` (sbr_hf.rs): it solved an unwindowed covariance-method normal-equation system for the AR(2) whitening/ resynthesis filter, which -- unlike the spec's Levinson-Durbin/ autocorrelation method -- carries no built-in BIBO-stability guarantee. Replaced it with the Yule-Walker/autocorrelation-method solve (Hermitian Toeplitz R, always PSD, so the resulting AR(2) poles are unconditionally inside/on the unit circle by construction) -- this is the exact upgrade path the module's own `stabilize()` doc comment already named. `sbr_hf::tests::lpc_recovers_the_poles_of_a_synthetic_ar2_process`'s tolerance widened 0.05->0.2 to match the (expected, smaller) finite- window estimation bias this method trades for the stability guarantee; all sbr_hf/sbr_env lib tests pass. Measured effect: E_curr for the poisoned limiter band did NOT drop by orders of magnitude post-fix (still 1e10-1e11) -- the resonance there is apparently a genuinely near-unity-but-stable pole on real tonal content, not an actual instability the old covariance solve was mis-estimating, so this is a real correctness fix (unconditional stability, matching the spec's own method) but not the cliff's root cause. `EC_AAC_SBR_HF_BYPASS` A/B confirms the t=18s/24s cliff itself is unrelated to SBR HF content (corr near-identical with HF zeroed: 0.0546->0.0546, 0.0589->0.0586, both essentially unchanged after this fix too) -- that cliff's cause is still open, outside SBR HF/limiter entirely. Gate (crates/ec-aac, EC_AAC_HEAAC_FIXTURES set): - sbr_hf::/sbr_env:: lib tests: pass (4+6/4+6) - sbr_real_library_matches_reference: reeln full 0.9875/0.9866, above-5kHz 0.9741/0.9797 (baseline 0.987/0.973-0.980) -- held/slightly improved. FMJ full 0.9979/0.9935, below-5kHz 0.99997/0.99993, above-5kHz 0.9923/0.9738 -- consistent with prior runs, no regression. Test still fails its aspirational 0.999 full-band bar (pre-existing, not introduced here). - sbr_hf_window_band_probe: t=14s corr=0.999944 (unchanged); t=18s/24s cliff corr=0.054661/0.058584 (baseline 0.054601/0.058942) -- unchanged, confirming the cliff is a separate, still-open defect. - synthetic_heaac_matrix: 48k HE rows full/below/above 0.988-0.9999 / 0.994-1.000 / 0.988-0.997, matching prior baseline shape (44.1k rows not fully re-measured this round, test run truncated for budget after representative 48k family confirmed no regression).
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.
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.
fix(sbr): correct the QMF in-band measurement bug, box-car the injected noise drawAhmet Kaan Gümüş · 3b60454
fix(sbr): correct the QMF in-band measurement bug, box-car the injected noise draw sbr_qmf's synthesis_energy_gain_for_white_noise_excitation measured its in-band FFT window at k0/SYNTHESIS_BANDS; band k's passband is actually centred at (k+0.5)*omega_step with omega_step = pi/(2*SYNTHESIS_BANDS), half that fraction of Nyquist, so the window sat on the alias image, not the signal -- the round-43 "~0% in-band survival" reading was this bug, not a Synthesis defect. Corrected, a raw i.i.d.-per-slot draw already lands ~0.49 of its own energy in-band; a 2-slot boxcar (sbr_env::NoiseGen) raises that to ~0.61 while staying noise-like (spread across the band, not a residual tone). Re-measuring the real-file whole-HF realized noise fraction after shipping the boxcar shows it barely moves (0.1787 -> 0.1770): that metric sums energy across the whole swept HF spectrum, and energy an i.i.d. draw aliases to a neighbouring QMF band still lands inside that same sweep, so it was never actually excluded. The ~0.38 bookkept vs ~0.18 actual gap is therefore a genuine energy shortfall plus a content defect (measured coherence sits well below even the actual-fraction ceiling), not the noise-sequence-shape problem round-43 diagnosed. Tightens sbr_actual_noise_fraction's regression floor from 0.15 to 0.17, the level both before and after this fix.
debug(ec-aac): EC_AAC_SBR_CELLDUMP per-(envelope,band) noise-realization dumpAhmet Kaan Gümüş · 79dc3f6
debug(ec-aac): EC_AAC_SBR_CELLDUMP per-(envelope,band) noise-realization dump Round-43 Task 1: env-gated dump in sbr_env::adjust printing target/ signal_target/noise_here/cur/raw+capped gain/boost/namp and the actually- injected (and post-addition) sample energy per absolute QMF band, so the noise-realization gap can be read directly off real content instead of guessed at.
fix(aac-sbr): boost accounting conserved signal-only against the full envelope target, and noise_amps divided per-sample energy by width a second timeAhmet Kaan Gümüş · f737a34
fix(aac-sbr): boost accounting conserved signal-only against the full envelope target, and noise_amps divided per-sample energy by width a second time adjust()'s limiter boost pass accumulated lim_e_orig from the cell's FULL transmitted target (signal+noise) but measured lim_e_actual from the capped SIGNAL gain alone, driving the boosted signal all the way up to the cell's total budget as if no noise share existed. Matched against the reference algorithm's known E_orig/E_curr+Q_M boost ratio: lim_e_actual now folds the noise share back in so both sides conserve the SAME total. Separately, noise_amps divided the already-per-sample noise_here by the cell's QMF-band width, shrinking injected noise variance by 1/width on top of everything else -- worst at the wide high-frequency sfb cells, which is exactly where the realized-vs-bookkept gap was largest. reeln whole-HF realized noise fraction (EC_AAC_SBR_NOISE_ANCHOR): 0.1325 -> 0.1787 against a ~0.38 bookkept split. Two residual defects (named, not fixed here): three loud harmonic-dominated bands still realize ~0.001-0.015, and bands above ~8.5kHz decay toward 0 with rising frequency -- both are separate from this accounting mismatch. Also fixes sbr_actual_noise_fraction's own band_hz->QMF-band lookup, which used bin_level_conviction's internal FFT-band scale (rate/256) instead of the true QMF band width (rate/128), silently doubling every looked-up band index and making every real band above roughly half of k2 read back a false 0.0 bookkept fraction -- the round-42 charter's "noise coverage gap above 7.4kHz" was this test bug, not a decoder defect.
fix(aac-sbr): NoiseGen was DC-biased and under-scaled, realizing ~1/6-1/9 of the transmitted noise splitAhmet Kaan Gümüş · 64cc642
fix(aac-sbr): NoiseGen was DC-biased and under-scaled, realizing ~1/6-1/9 of the transmitted noise split
Round-41 Task 1 (instrument anchor): bin_level_conviction reads exactly
1.0 on ours-vs-ours and reference-vs-reference-through-remux, and
0.995+ up to 14.8kHz on a reference-vs-itself 64-sample-offset control
(only degrading in the near-silent >15kHz tail) -- the coherence
instrument is not the story behind reeln's ~0.15-0.25 HF readings.
Round-41 Task 2 (round-24 contradiction): measured actual injected
noise as output energy (decode twice, noise on vs EC_AAC_SBR_NOISE_ZERO,
per-band energy delta) instead of trusting either side. Two real bugs
in NoiseGen found and fixed:
- next()'s divisor was one bit short (1<<23 instead of 1<<24), so it
was actually uniform on [-0.5, 1.5) (mean +0.5, DC-biased) rather
than the intended zero-mean [-0.5, 0.5).
- complex_unit()'s two components then had E[|z|^2] = 1/6, not 1, so
adjust()'s namp*z scaling only ever realized ~1/6 of noise_here.
Both fixed; new unit tests pin complex_unit()'s statistics directly.
Measured effect: actual/bookkept noise fraction in noise-covered bands
0.095 -> 0.171 average (bookkept ~0.38, still short -- the limiter/
boost pass's lim_e_orig accumulates the FULL envelope target while its
gain is computed from signal_target alone, a separate pre-existing
mismatch not fixed here). Round-24's "zeroing changes corr by <0.001"
was independently reproduced (0.000957, now 0.001421 post-fix) and
was never in contradiction with the bookkept split once actual
realized energy is measured directly instead of assumed equal to it.
Also gates the O(windows*4001*4096) whole-file drift search in
sbr_real_library_matches_reference behind EC_AAC_SBR_TIMELINE (was
unconditional, ~4min/channel); default path now reuses the established
global lag with no per-window search for the same mean/min summary.fix(aac): SBR limiter caps per limiter-band aggregate, not per empty cellAhmet Kaan Gümüş · 0a60b22
fix(aac): SBR limiter caps per limiter-band aggregate, not per empty cell sbr_env::adjust's gain cap was per-CELL: limiter_max*sqrt((noise+current)/current), which is infinite as current->0 -- every content-empty target cell (a patch boundary with no source energy) amplified numeric dust to the full transmitted envelope. Replaced with the spec-shaped limiter (Sec 4.6.18.7.2/.7.5): a limiter band table (sbr_hf::limiter_band_table, union of f_low borders and patch target boundaries, thinned to ~1/2/3 bands/octave by bs_limiter_bands) with an AGGREGATE cap sqrt(E_orig/E_curr)*limgain per band, so an empty cell inherits its band's cap instead of blowing up alone, plus gain-boost compensation (+4dB ceiling) applied to gains/noise/sinusoids so a capped band still reaches its transmitted total when the population isn't actually starved. Verification (round 33): - Probe sanity gate (scripts/aac-tables/sbrpatchmap.py, headers A/B/C): STILL FAILS -- our decoder's measured target map still does not match build_patches' prediction, and does not collapse to a per-source-varying map. The convicted "infinite per-cell gain" mechanism is fixed, but is not the probe cluster's sole/primary cause; a separate defect remains (HF patching/frequency placement or QMF synthesis), not chased further this round. - Real file (reeln.mp4, EC_AAC_SBR_HF_CONVICTION=1): full-band ch0 0.973->0.9718, ch1 0.972->0.9680; whole-file mean ch0 0.9585->0.9565, ch1 0.954->0.9512; below-crossover ch0 0.993->0.9926, ch1 ~0.993->0.9916; HF bin coherence (TASK2 direct-match mean) ~0.2 baseline -> ~0.08 (ch0) / ~0.14 (ch1), i.e. LOWER, not higher. The correctness fix does not move this file's bar upward -- reported honestly, not chased into further guessing this round. limiter_caps_a_pathological_gain renamed/rewritten to limiter_stays_finite_on_a_uniformly_starved_band: a semantics change, not a bound weakening -- the old assertion (uniform starvation stays capped near the raw HF estimate) is mathematically wrong under a correct aggregate cap+boost (boost legitimately undoes a uniform cap when nothing in the band needs protecting from disproportion, since cap and boost read the same aggregate population); the new test checks the actual invariant this round fixes (finite/bounded, not literally unbounded) and a new test (a_content_empty_cell_inherits_its_limiter_bands_aggregate_cap) asserts the crux: an empty cell next to a loud cell inherits the band cap, not infinity. lib 42/42 green, fmt/clippy -D warnings clean. FMJ candidate still fails outright (separate pre-existing issue, not this round's scope).
2026-08-19
sbr: env-gated parameter-sensitivity sweep instruments (round-22)Ahmet Kaan Gümüş · 0fb1dc2
sbr: env-gated parameter-sensitivity sweep instruments (round-22) EC_AAC_SBR_BW_SCALE (chirp/inverse-filter target scale, clamped <1), EC_AAC_SBR_CHIRP_SMOOTH=none|swap (attack/release curve), EC_AAC_SBR_GAIN_LERP (per-slot gain interpolation toward the next envelope), and EC_AAC_SBR_LIMITER_OFF probe whether real-content correlation is sensitive to these knobs. All zero-cost when unset; default behavior unchanged (40/40 lib tests, reeln baseline bit-identical). EC_AAC_SBR_SWEEP_SEGMENT=1 lets the real-file test measure the second half of a file for stability checks. Sweep result: BW_SCALE shows a small monotonic response (best at scale=0, i.e. no chirp resonance at all -- ch1 delta 0.0023, just past the 0.002 material bar) but a two-segment stability check was inconclusive (the file's second half has near-zero baseline correlation for both candidate and default, invalidating the comparison), so the default is NOT changed. Chirp-smoothing curve and limiter are flat (eliminated). Gain-lerp catastrophically regresses (full-band 0.97->0.07) and is eliminated.
fix(aac-sbr): noise-floor dequant is a signal-relative ratio, not an absolute energyAhmet Kaan Gümüş · 5537fae
fix(aac-sbr): noise-floor dequant is a signal-relative ratio, not an absolute energy Round-21 Task 1: a reference-decoder probe (scripts/aac-tables/sbrnoise.py) sweeping the noise-floor raw value q_q at a fixed envelope target shows total HF-band output power staying nearly flat across the whole q_q range, not scaling additively with dequant_noise(q_q) as our own decoder assumed. That's the signature of the envelope target being split signal=target/(1+Q_div), noise=target*Q_div/(1+Q_div) with Q_div=dequant_noise(q_q), not noise added independently on top of the full target. adjust() now computes that split per (envelope, band) cell and injects noise there directly, replacing the old separate noise-grid pass that treated dequant_noise's return value as a standalone absolute energy comparable to dequant_env's unrelated unit scale. On the real-file bar (reeln) this moves correlation only slightly (ch0 0.9726->0.9732, ch1 0.9705->0.9716): real transmitted q_q values apparently keep Q_div small regardless of interpretation, so the noise-floor circularity hypothesis still doesn't explain this file's HF correlation gap -- but the fix itself is now unit-consistent with the measured reference behavior and is kept as a correctness fix.
diag(ec-aac): SBR noise-fraction ceiling hypothesis, measured and refutedAhmet Kaan Gümüş · 2cccf17
diag(ec-aac): SBR noise-fraction ceiling hypothesis, measured and refuted Round-17 Task 1: EC_AAC_SBR_NOISE_FRACTION_DEBUG accumulates per-QMF-band transmitted signal vs. noise energy (from our own dequantized envelope/ noise data) during decode; the real-file test prints the predicted sqrt(1-f_noise) correlation ceiling alongside per_band_lag_search's measured curve. On reeln ch0 the noise energy fraction is ~1e-7 in every HF band (predicted ceiling flat at 1.0000) while measured |corr| declines smoothly 0.999->0.85 -- the curves do not match. EC_AAC_SBR_NOISE_ZERO corroborates: zeroing our injected noise entirely leaves the measured per-band correlation bit-for-bit identical, so our noise generator is not in the causal path for the decline either. Hypothesis not convicted; no noise-table derivation follows per the charter's stop condition.
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(sbr): limiter clamp actually caps gain instead of always no-oppingAhmet Kaan Gümüş · 407561c
fix(sbr): limiter clamp actually caps gain instead of always no-opping sbr_env::adjust's limiter cap used `.max(gain.min(limiter_max))`, which is always >= the intended cap and so the .min() around it never restricted anything -- flagged in the ledger as likely backwards, now confirmed and fixed: the cap is limiter_max * sqrt((noise+current)/current), matching Sec 4.6.18.7.5's headroom shape (a cell with zero transmitted noise floor still gets the plain limiter_max ceiling). Zero measured effect on the two real-file fixtures (limiter rarely the binding constraint there), but lib tests 38/38 and this closes a genuine correctness gap flagged for two rounds. Also tried and reverted in this same pass: per-subband bs_interpol_freq gain interpolation (a centre-frequency lerp across sfb gains) regressed reeln ch0 full-band 0.972756 -> 0.960561, so it's left as a documented corner-cut rather than shipped -- header.interpol_freq/smoothing_mode stay parsed but unapplied.
fix(aac-sbr): coupled envelope de-mix ratio needed a -12 offset, not raw balanceAhmet Kaan Gümüş · 81915ce
fix(aac-sbr): coupled envelope de-mix ratio needed a -12 offset, not raw balance Pinned empirically by writing coupled CPE payloads with known (channel0, balance) raw pairs through a decodable HE-AAC stream and fitting the left/right PCM energy split against the balance raw value for both bs_amp_res=0 and 1. Both collapse to the same `2*alpha*raw - 12` exponent (previously used `alpha*raw`, uncentred). Real-file sweep still misses the bar: below-crossover (pure core, no SBR) correlation for the second channel is already near zero on both real files, meaning the dominant remaining fault is upstream of sbr_env, in core-level channel-pair decode -- not a de-mix convention issue. See ledger for the swap/cross-channel correlation evidence.
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(aac): SBR HF generation and envelope adjustment, unwiredAhmet Kaan Gümüş · 49f840b
feat(aac): SBR HF generation and envelope adjustment, unwired
sbr_hf.rs: patch construction (copy-up from below kx into [kx,k2)
aligned to f_high borders), order-2 complex covariance LPC per source
subband, and bandwidth-expanded ("chirped") whitening driven by
bs_invf_mode with fast-attack/slow-release smoothing.
sbr_env.rs: envelope/noise dequantization (including a best-effort
symmetric coupled-CPE balance de-mix, corner-cut noted -- no real-file
fixture exercises it yet), per-(envelope,band) gain toward the
transmitted energy with a noise-floor-relative limiter, noise
injection and add_harmonic sinusoids.
Neither module is wired into the decoder yet (next commit); both carry
their own unit tests and compile clean.