Commits
Commits on
03dc6e9978cbbbba112bf5c6ad925845ede8c744Filtered to crates/ec-aac/src/sbr_env.rsClear filter2026-08-20
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.