forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on ca4790ff3ec50db2bcffb1751a3cbbc29771cd7eFiltered to crates/ec-aac/src/lib.rsClear filter

2026-08-21

2026-08-20

diag(aac-sbr): 44.1k-family "sample drift" is a narrow-search artifact, not clock driftAhmet Kaan Gümüş · 9f92c74
diag(aac-sbr): 44.1k-family "sample drift" is a narrow-search artifact, not clock drift

sbr441_family_sample_drift_probe (crates/ec-aac/tests/sbr_real_library.rs)
walks lag(t) per-1s window in a NARROW +/-128 search around each fixture's
own true fixed lag (found first via a wide free-search cross-check, since
the earlier -4674/-4617 pair used in coupled_cpe_channel_swap_probe was
itself never independently verified against a wide search on this file).

Findings, all three fixtures (heaac_44100_48k "fail" family,
heaac_48000_48k "control", and reeln.mp4 as a real-content
control):
- lag(t) is FLAT (+/-1-2 samples, fitted slope ~0) across the full 30s for
  every file -- no growing sample-count/clock drift anywhere. The earlier
  "decays 0.998->0.68 by t=9s" reading was the free coarse-then-refine
  search (proven separately unreliable on this file's periodic content)
  chasing a different, wrong lag as it walked forward, not the aligned
  signal actually drifting.
- heaac_44100_48k and heaac_48000_48k -- NOT just the "failing" 44.1k
  family -- both show an IDENTICAL correlation dip-then-recover in the
  file's middle third (t~=13-27s, corr falling to ~0.13-0.5) at their
  otherwise-flat true lag. Since the 48k file shows the same dip, this is
  a property of the synthetic fixture pair's shared source content (both
  built by the same make-heaac-fixtures.sh run), not a 44.1k-vs-48k
  output-rate SBR/rate-family defect.
- Sample counts: our decoder emits exactly au_count*2048 samples/channel
  for both heaac fixtures (no internal drops); ffmpeg's own decode is a
  constant ~5058 samples shorter for BOTH files (encoder priming/padding
  trim ffmpeg applies via edit list that we don't) -- a fixed offset
  already absorbed into the fixed lag, not a growing one. reeln's
  0.366 ours/ffmpeg ratio is purely the test harness's own 1500-AU
  extraction cap (~69.7s) against ffmpeg's full ~190s decode, not a
  decode defect.
- hold_call_count() (new ec_aac::hold_call_count(), sbr_chain.rs
  HOLD_CALLS atomic) is 0 across all three files' full decodes: no
  apply_last/hold fallback is involved at all.

Verdict: the charter's "44.1k-family clock drift" hypothesis is refuted.
Next suspect for the mid-file correlation dip shared by both synthetic
heaac fixtures: their shared source content around t=13-27s (quiet
passage / high-transient section stressing SBR HF reconstruction), not
sample-rate-family-specific code.
fix(aac): run PNS noise substitution before M/S and intensity stereoAhmet Kaan Gümüş · 7efd1d7
fix(aac): run PNS noise substitution before M/S and intensity stereo

ISO/IEC 14496-3 §4.6.13 fills a PNS band's spectral coefficients with
scaled noise; §4.6.8.1 M/S and §4.6.8.2 intensity stereo then combine
those coefficients like any other spectral data. BlockDecoder::finish
ran M/S and intensity stereo first, then filled PNS bands afterward,
so any band coded as PNS in one channel still read zero when the
stereo tools combined it -- the pre-fill zero got mixed into the
other channel's coefficient (M/S) or copied outright (intensity),
corrupting a real channel's data whenever the encoder mixed PNS with
stereo coding on the same band. Reordered to match every reference
decoder's decode order: PNS -> M/S -> intensity stereo -> TNS.

Diagnostic path: chased a consumer sweep's finding of 0.76-0.92 (and
one 0.0) whole-file correlation on a set of AAC-in-mp4 screen
recordings against ffmpeg. Direct ec-mp4-demux -> ec-aac-decode
measurement (crates/ec-aac/tests/obs_real_content.rs), lag-searched
per the existing sbr_real_library.rs pattern, reads corr=1.0000 on
every non-silent file both before and after this fix -- these files'
PNS usage (1-13 AUs) apparently never lands on a band the M/S mask
also marks, so the reorder is a real spec-order bug but not what
produced that sweep's numbers; the sweep's own method likely lacked
a wide-enough lag search and caught this file family's ~1024-sample
(~21ms, one AAC frame) container/decode alignment offset instead.
The single 0.0000 file is genuine digital silence in both decoders.

Also chased a second repro (a real AAC-LC-in-mp4 download, sequential
single-decoder scan, crates/ec-aac/tests/reelh_per_frame.rs):
per-AU correlation reads 1.0000 across the whole 10.4s file except
one near-silent intro AU where both decoders read ~0 RMS and the
correlation ratio is numerically meaningless -- no reproducible
mid-stream collapse found in this file at this crate's decode layer,
with or without this fix.

Added crate-level tool-usage side info (EC_AAC_TOOL_SIDEINFO_DEBUG,
mirroring sbr_chain's SbrSideInfoRow pattern) and five ffmpeg
tool-isolation fixtures (-aac_pns/-aac_is/-aac_ms/-aac_tns, one at a
time and one with all four) wired into oracle.rs, all passing at
>=0.999 correlation, to pin the fixed decode order and give any
future PNS/IS/M-S/TNS regression a per-tool fixture to land on.
diag(aac-sbr): normative 640-tap QMF window embedded, checksum-pinned; bank replacement reverted, dead end recordedAhmet Kaan Gümüş · 2928bfe
diag(aac-sbr): normative 640-tap QMF window embedded, checksum-pinned; bank replacement reverted, dead end recorded

Charter: replace sbr_qmf's fitted Kaiser bank with the normative ISO/IEC
14496-3 4.6.18.4/4.6.18.8 analysis/synthesis pair built from the provided
640-tap prototype table.

Embedded the table verbatim as crate::sbr_qmf_window::QMF_WINDOW with a
checksum test (sum/sum-of-squares/max/argmax) -- passes, table transcription
confirmed correct.

Implemented and empirically tried, in order, against a broadband-noise
round-trip correlation probe (independent of any real file):

1. The literal folded reading of 4.6.18.4/4.6.18.8 an external spec review
   produced (320-sample analysis buffer folded 5-way to 64 taps, carrier
   exp(j*pi/64*(k+0.5)*(2n-1)); 1280-sample synthesis overlap-add, carrier
   exp(j*pi/64*(k+0.5)*(2n-255)), synthesis window built by mirroring the
   640-tap table to 1280 samples) -- broadband round-trip correlation
   plateaued at ~0.03-0.05 regardless of a grid search over analysis/
   synthesis phase-intercept sign and offset (tried +-1, +-63, +-65, +-127,
   +-129, +-255, +-511, 0) and an alternating-sign fold variant. Not a
   near-miss: this structure does not reconstruct at all.

2. The prior fitted bank's own direct (unfolded) 640-tap-dot-product
   structure, with the real QMF_WINDOW table substituted for the fitted
   Kaiser prototype (no fold, theta = omega_step*(k+0.5)*(n+offset), one
   omega_step per bank) -- best found ~0.697 correlation (offset=bands/2,
   omega_step=pi/64 analysis / pi/128 synthesis, the fitted bank's own
   convention), well short of the fitted bank's own 0.9998 achieved only
   through its Kaiser-beta + cutoff fit. A grid over omega_step in
   {pi/64, pi/128} x2 banks and offset in {+-16, +-32} never exceeded ~0.70.

Both avenues ruled out a fold-based reading of the reviewed equations
outright, and showed the review's exact phase-intercept constants (-1,
-255) are not simply a typo away from working with either window-derivation
guess. Given no access to the literal ISO text (only a review's paraphrase,
itself flagged "review, not ground truth") and no reference decoder's QMF
internals to cross-check against, further correction is a guess-and-check
search over an open constant space, not a bounded fix.

Reverted crates/ec-aac/src/sbr_qmf.rs and sbr_hf.rs to HEAD (4346f31) to
avoid shipping a QMF pair that round-trips at ~0.03-0.70 in place of one
that round-trips the passband at ~0.9998 -- verified unchanged real-file
numbers below.

DONE-GATE, unchanged from baseline (revert confirmed exact):
  cargo test -p ec-aac --lib: 51 passed (50 baseline + 1 new window
    checksum test), 0 failed.
  reeln (44.1k): ch0 full-band corr 0.972474, ch1 0.969785 (both
    unchanged); below 5000Hz 0.992799/0.992329, above 5000Hz
    0.761967/0.746352; whole-file windowed mean 0.955717/0.951577.
  FMJ (48k, kx=27): ch0 full-band corr -0.024069, ch1 0.010887 (both
    unchanged, pre-existing catastrophic decorrelation, separately tracked).

sbr_qmf_window.rs's QMF_WINDOW is not wired into sbr_qmf (module doc there
states why); kept for the next attempt, which needs either the literal ISO
text or a reference decoder's QMF stage to check phase/window hypotheses
against instead of guessing.
test(aac): QMF-domain exact third witness for SBR HF content (round-46)Ahmet Kaan Gümüş · be3ee94
test(aac): QMF-domain exact third witness for SBR HF content (round-46)

Adds HfAnalysis (a 64-band forward analysis bank sharing Synthesis's own
convention) plus a validated self-consistency control, and rebuilds the
STFT-approximate patch-copy simulator (round-45) in this exact band grid
(EC_AAC_SBR_QMF_WITNESS) with a per-band 2nd-order complex transfer fit
between the plain-copy sim and the reference's real HF content
(hf_patch_transfer_fit) plus a bw-value dump (EC_AAC_SBR_BW_DUMP) for
comparison against our own chirp coefficients.

On reeln, the exact-domain witness overturns round-45's STFT-based
lead: for patch (3,28,11) sim-vs-reference clears 0.5 on most bands
(0.42-0.79) while sim-vs-ours stays well under it (0.26-0.42) -- the
opposite polarity from the STFT approximation's hint. The fitted
sim-to-reference transfer on that same patch shows non-trivial order-2
structure with a phase signature (~i, ~-1, ~-i across taps 0/1/2) matching
this file's own already-characterized (and currently disabled)
band_shift_correction quarter-turn convention -- flagged in the ledger as
the next concrete thing to re-test with this sharper instrument, not
implemented here (round-37's contrary real-file evidence used a
scale-trap-prone 8-bin STFT metric this round's own control work found
unreliable; re-enabling a previously-reverted correction needs its own
verification budget).

2026-08-19

probe(sbr-residual): frame x band residual/side-info correlation instrumentAhmet Kaan Gümüş · 6fea6db
probe(sbr-residual): frame x band residual/side-info correlation instrument

EC_AAC_SBR_SIDEINFO_DEBUG logs one row per (AU, channel) apply_data runs
(grid/invf/add_harmonic/coupling/e_q/q_q means, fresh vs hold source) via
a new sbr_sideinfo_log() accessor. EC_AAC_SBR_RESIDUAL_DEBUG cross-tabulates
that log against a (frame x band) residual-energy grid built from
FFT(ours)-FFT(reference) at AU-aligned 2048-sample blocks (linear FFT means
the residual's own spectrum never needs materializing in the time domain).

On reeln (both channels, 489 frames): no predictor dominates decisively.
add_harmonic-flagged bands carry LESS residual than unflagged (ratio 0.13),
refuting sinusoid-injection as the round-19 bar's cause. Envelope borders
run only ~1.1-1.7x interior energy (no sharp gain-placement spike).
Coupling-flip frames run LOWER (ratio ~0.4), same direction as round-11's
DT-base refutation. invf_mode level is non-monotonic against residual and
confounded by population size (round-19's chirp dead-end stands). HF
residual peakiness (~2.2-2.25) sits close to the pure-noise expectation for
4-bin groups (H_4=2.083), reading noise-like, not tonal. hold-state frames
never occurred in this window -- untested, not refuted. Per charter, landing
the diagnostic with these findings rather than chasing a non-dominant lead.
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.
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.
feat(aac): the SBR QMF filterbank pair, phase convention and prototype closedAhmet Kaan Gümüş · f29cb75
feat(aac): the SBR QMF filterbank pair, phase convention and prototype closed

The odd-stacked complex-exponential phase reference needed +bands/2, not
-bands/2 (found by a brute-force sweep over the small discrete convention
space against the round-trip correlation itself); with that settled, a
Kaiser-beta sweep against the same metric closed the residual prototype-shape
gap. Round trip now correlates 0.999949 (bar 0.9999) at a measured 898-sample
delay, and the impulse test's in-band frequency window is resynced to the
synthesis bank's own omega_step.
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.
feat(aac): the SBR frequency-band derivation, ported from the validated rigAhmet Kaan Gümüş · 3a933f6
feat(aac): the SBR frequency-band derivation, ported from the validated rig

The master/high/low/noise band tables as the probe rig derived and proved
them — 6387/6387 header configurations agree with the reference parser —
carried over with 500 embedded cross-check vectors generated by the rig's
own function. Not yet consumed by a decode path.
feat(ec-aac): derive four SBR noise Huffman codebooks, black boxAhmet Kaan Gümüş · c53ad6b
feat(ec-aac): derive four SBR noise Huffman codebooks, black box

Wires the SBR table-derivation rig's widths/books/values stages into its
CLI and adds the value-assignment stage (bisecting a codeword's raw start
value to the reference decoder's own range-check boundary), then emits
the codebooks that closed with a complete, fully-valued prefix code:
NOISE_T, NOISE_F, NOISEB_T, NOISEB_F. The eight envelope books derive
lengths cleanly but each hit at least one codeword whose value probe
crashes the reference decoder rather than range-checking gracefully
("channel element 0.1 is not allocated"); they are left out of
sbr_tables.rs rather than shipped with a guessed value, per the rig's own
rule against fabricating table entries.

2026-08-14

feat(aac): AAC-LC decoder, encoder and rusty_aac shimAhmet Kaan Gümüş · 9a848b4
feat(aac): AAC-LC decoder, encoder and rusty_aac shim

Decoder covers AAC-LC end to end: AudioSpecificConfig and ADTS framing,
all four window sequences and both window shapes, section and scalefactor
data, every spectral codebook including the escape one, pulse data, TNS,
M/S and intensity stereo, PNS, and SCE/CPE/LFE/DSE/PCE/FIL elements.
Output is film order FL, FR, FC, LFE, BL, BR (SL, SR), which is the order
the downmix in this family folds, so a 5.1 track needs no caller-side
permutation. HE-AAC's SBR is not reconstructed: such a stream decodes to
its AAC-LC core and reports the core rate rather than claiming the
extension's.

Encoder is a full two-loop search: 2048-point FFT masking with spectral
flatness for tonality, bark-ish spreading, a relative hearing-threshold
floor, transient-driven window switching, per-band mid/side, exact
Huffman bit counts for codebook choice, and a bit reservoir against a CBR
target. Both ADTS and bare raw_data_block output.

The normative tables were derived rather than transcribed: access units
with a chosen spectral payload were decoded by a reference decoder and
read back through the inverse MDCT, which enumerates each codebook by a
binary tree walk. Every one came out with a Kraft sum of exactly 1 and
the entry count the standard prescribes.

forbid(unsafe_code) in both crates.