edith_codecs
Clone
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
HANDOFF — reelm@64k dropout second
Goal
Kill the reelm@64k dropout second in ec-opus encoder. Baseline: reelm@64 ours min-second corr .8987 (1 dropout second), ref .9100. Done = drop_ours==0 AND full 14-row sweep still passes (no new dropout row, rate ±5%, no row corr≥ref regressed >.001).
What's done (uncommitted, on branch lane-opus-drop, worktree /home/user/Documents/Code/Rust/ec-wt-opus-drop)
Instrumentation plumbing added — NOT yet compile-checked, NOT yet exercised. All edits to two source files:
-
crates/ec-opus/src/celt_enc.rs- New
pub struct CeltFrameDiag(after line ~275, beforeCeltEncoder): fieldsis_transient, short_blocks, intra, silence, lm, start, coded_bands, intensity, dual_stereo, alloc_trim, vbr_reservoir, nb_compressed, band_log_e: [f32; 2*NB_BANDS], pulses: [i32; NB_BANDS], fine_quant: [i32; NB_BANDS].#[derive(Clone, Debug, Default)]. - New field
last_diag: CeltFrameDiagonCeltEncoder(afterurow), initializedCeltFrameDiag::default()innew(afterurow: vec![0;1280]). - New getter
pub fn last_diag(&self) -> &CeltFrameDiag(afterchannels()). - Populate
self.last_diagat end ofencode, just beforeOk(nb_compressed)(after theenc.error()check block). Copiesself.band_log_einto a[f32; 2*NB_BANDS]array; copiesself.pulsesandself.fine_quantarrays.
- New
-
crates/ec-opus/src/lib.rspub use celt_enc::CeltFrameDiag;(afterCeltEncoderre-export).
-
crates/ec-opus/src/encoder.rs- New
pub fn last_celt_diag(&self) -> &crate::celt_enc::CeltFrameDiagonEncoder(afterfinal_range()), delegating toself.celt.last_diag().
- New
WARNING — one edit left a possible cosmetic issue: after the last edit on the encode tail, the region read back as:
913: Ok(nb_compressed)
914: }
915: // -- Analysis ------------------------------------------------------------
No blank line between } and the // -- Analysis comment. Cosmetic only; syntax probe passed on that edit. The first compile gate (cargo check -p ec-opus) has NOT been run yet — that is the very first next step. If band_log_e local name clashes (there's already a self.band_log_e field but the local shadow is fine) or NB_BANDS/CeltFrameDiag visibility errors surface, fix them. Likely clean.
What remains (exact next steps)
-
Compile gate:
export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-opus-drop && cargo check -p ec-opus(cheap, no emit — per the GLM compile-discipline rule, runchecknotbuild/testfirst). Fix any errors in the three files above. -
Write the instrumentation test. Add a new
#[ignore]testreelm64_dropout_instrumentationincrates/ec-opus/tests/conformance.rs(near the gate test, ~line 3013). AddCeltFrameDiagto the existinguse ec_opus::{...}at line 784. The test should:ffmpeg_decode_pcm(reelm, 120.0)→source_pcm(2ch, 48k).- Ref:
ffmpeg_encode_libopus(reelm, 64, &scratch, 120.0);decode_ogg(&scratch)→ref_dec; also callogg_packets(&fs::read(scratch))to get per-packet byte sizes for the reference (skip packet[0] = OpusHead). Computeref_kbpsfrom file size like the gate does. - Ours:
Encoder::new(48000,2,Audio),set_bitrate((ref_kbps*1000.0).round() as u32),set_vbr_constrained(true). Loop frame-by-frame (960 = 20ms):enc.encode_float(block,960,&mut out)→ recordlen(packet bytes) ANDenc.last_celt_diag()snapshot; decode each via ownDecoder; accumulate decoded. 50 frames = 1 second. - Align ours and ref to source via
align_to_source(..., MAX_LAG=2000). per_second_corrfor ours and ref → find the second(s) where ours < 0.9.- Write
lanes/opus-drop-r1.second.txt: per-second corr table (ours vs ref), then for the failing second dump all 50 frames:frame_idx, t_ms, ours_bytes, ours_bits, ref_bytes, ref_bits, and diag fieldsis_transient, short_blocks, intra, silence, lm, start, coded_bands, intensity, dual_stereo, alloc_trim, vbr_reservoir, plus per-frame decoded RMS (ch0,ch1) for ours and ref. Also dumpband_log_e[0..21](ch0) andpulses[0..21]per frame. - Run:
SWEEP_ONLY=reelm cargo test -p ec-opus --release --test conformance reelm64_dropout_instrumentation -- --ignored --nocapture(or just the test name without SWEEP_ONLY since it's hardcoded to reelm).
-
Name the cause from the dump. Working hypothesis from static read (NOT yet confirmed by data): at 64k stereo,
effective_bytes≈158,effective_rate=2*((8*158-80)>>3)/5≈58→ intensity=16 (bands ≥16 collapse to mono above ~band 16). Combined with the constrained-VBR reservoir draining on transient frames (target=7*target/4at line ~660), a transient burst starves the next ~1s of frames, and anti-collapse reservation (line ~731) needs5<<BITRESbits at lm=3 — if bit-starved it's skipped → transient recovery fails → one second drops below 0.9. The dump will confirm which: look for the failing second to (a) start right after ais_transient=trueframe withvbr_reservoirgoing negative, (b) showours_bytes << ref_bytesfor several frames, (c)coded_bands < 16orintensitystuck high, (d)pulsesnear-zero on upper bands. -
Levers, one at a time (measure each with
SWEEP_ONLY=reelmgate run, keep winner,git checkoutrevert losers, record numbers):- L1 transient bit reservoir: raise the reservoir floor or reduce the
7*target/4transient boost (celt_enc.rs ~660) so a transient burst can't drain >1 frame of buffer. - L2 disallow bandwidth drop at 64k: clamp
coded_bands/endso fullband is always coded (preventcoded_bandscollapsing on starved frames). - L3 stereo width floor: lower the intensity threshold so intensity stays <16 at 64k stereo (line ~710-724), keeping mid/side above band 16.
- L4 tf_select: allow non-zero
tf_selectfor transient frames (line ~545) — reference's tf search may pick better time resolution. - Gate command per lever:
SWEEP_ONLY=reelm cargo test -p ec-opus --release --test conformance encoder_library_gate_vs_libopus -- --ignored --nocapture. Winner =drop_ours==0ANDminsec_oursimproved without trashingcorr_ours.
- L1 transient bit reservoir: raise the reservoir floor or reduce the
-
Full 14-row sweep on winner:
cargo test -p ec-opus --release --test conformance encoder_library_gate_vs_libopus -- --ignored --nocapture(no SWEEP_ONLY). Verify: no new dropout row, rate ±5%, no row wherecorr_ours≥corr_refregressed >.001 vs baseline inlanes/opus-gate-r1.sweep.txt(12/14 rows corr_ours≥corr_ref; reelm@64 + hein@64 trail). -
Report: write
lanes/opus-drop-r1.report.md, verdict line first:reelm@64 minsec a→b, drops n→m; 14-row: X rows corr≥ref; worst regression row <tag>@<kbps> gap +d.dddd. Include cause line (named mechanism with frame evidence from the dump) and refuted levers with their measured numbers. -
Commit on branch
lane-opus-drop(no merge, no push): the diag plumbing + the winning lever change + the report. Do NOT commit the instrumentation test unless it's still wanted — it's#[ignore]d scaffolding; recommend keeping it (ignored, cheap) or removing before commit. User's call, but unattended-batch default = keep ignored scaffolding out of the shipped tree → remove the test before commit, keep theCeltFrameDiag/last_diagplumbing only if a follow-up gate wants it; otherwise revert plumbing too. Recommendation: revert the plumbing + test together once the cause is named and the lever lands, so the final diff is only the encoder fix — unless the user wants persistent introspection.
Key file/line references for the next session
crates/ec-opus/src/celt_enc.rs:encode(439-914), VBR reservoir (652-700, was 652-700 pre-edit, now ~720-770 after diag additions — re-read), stereo intensity (702-726 → ~770-794), anti-collapse (731-736 → ~799-804),last_diagpopulate (~893-912).crates/ec-opus/src/encoder.rs:encode_frame(725-752),last_celt_diag(221-229).crates/ec-opus/tests/conformance.rs: gate test (2862-3013),roundtrip_own(810-843),per_second_corr(2831-2860),align_to_source(2761-2806),decode_ogg(537),ogg_packets(~440),ffmpeg_decode_pcm(2690),ffmpeg_encode_libopus(2724),shellexpand(2680), import line 784.
Evidence / verification status
- Baseline dropout reproduced (prior session):
reelm@64k: ... minsec o=0.8987 r=0.9100, drop o=1 r=0→ DROPOUT GATE FAILED. reelm@96k passes. - No compile or run verification of this session's edits yet. The
CeltFrameDiagplumbing is code-written only. First action next session =cargo check -p ec-opus. Do not claim the instrumentation works until that test runs and produceslanes/opus-drop-r1.second.txt.
Constraints reminder
export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-opus-dropbefore any cargo command.- Codecs deterministic → every claim is a numeric test, never ears.
- ≤60 tool calls then handoff (this session hit the cap mid-instrumentation).
- Commit on branch; no merge, no push.
- Repo is NOT under
~/.claudeor~/.config→ no auto push obligation, but commit is still required per task.