tools/awc_opus: honor hdr24 block_samples budget, interleaved skip, and deficit continuation #1072
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1072"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by Elijah-J on 2026-11-24T17:48:45Z.
Claimed in the coordination issue as: AWC-HDR24-BUDGET (posted after the draft was opened)
What and why
Streamed music (
0x48) chunks carry a 24-byte per-channel header with(subblocks, skip_samples, block_samples)at+4..+16. The sampled stereo banks use interleaved counts (2× per-channel 48 kHz frames), while the exporter also accepts a per-channel skip that verifies an exact packet overlap.Previously
music_channels()only checkedskipas a per-channel frame count and ignoredblock_samples(+12), which rejected multi-stem/multi-block streamed music banks that:block_samples / packet_channels,skip_samplesin interleaved stereo units (2 * frames), orblock_samplesbudget so the deficit carries into the next chunk'sskip_samples.Changes:
tools/awc_opus.py: read(count, skip, block_samples)fromhdr24+4..+16; trim trailing subblock padding packets pastblock_samples // pch; match interleaved (skip // pch) and per-channel (skip) repeated prefixes; handle exact-boundary deficit continuation when a preceding block stopped short of itsblock_samplesbudget while continuing to fail closed on partial/corrupt skips or oddblock_samples.docs/audio.md: document+8(skip_samples),+12(block_samples), and the conditions for carry-over recovery under### Streamed music (0x48).tests/test_awc_opus.py: add synthetic unit tests covering block-budget padding trimming, interleaved stereo skip deduplication, short-block deficit continuation, and partial-boundary fail-closed rejection.Tested
Synthetic unit tests on macOS:
python3 -I tests/test_awc_opus.py -v— 64/64 OKpython3 -I tests/test_awc_manifest.py -v— 23/23 OKpython3 -I tests/test_text_write_line_endings.py -v— 3/3 OKpython3 -m compileall -q make_game.py tools tests— exit 0A separate read-only Xbox Series 1.0.2.1 check recovered four banks (11 stems) rejected by the previous overlap-only extractor. FFmpeg decoded every stem to its descriptor length after Ogg end trimming. Three carry-over transitions exercised a zero net skip. Positive net skip was tested synthetically.
GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a — audio tool/docs only)Imported from ubiquitarianism/leonida. Originally posted by Copilot on 2026-11-24T18:43:22Z.
Code review location:
tools/awc_opus.py; line 396prev_deficitis only updated whenkeptis non-empty. If a chunk has a positiveblock_samplesbudget but yields zero packets (or all packets are trimmed away),deficitcan be > 0 but won’t carry forward, breaking the stated “deficit continuation” behavior for the next chunk. Consider updatingprev_deficitwhenever a positive budget is present (and parsing succeeded), while only updatingpreviouswhenkeptactually has packets.Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T18:43:23Z.
Review: COMMENTED
Copilot review overview
3 open issues
prev_deficitis only updated whenkeptis non-empty. If a chunk has a positiveblock_samples… · Newopus_packets()always copies packet payloads into newbytes. Incollect_packets=Falsemode,… · New_trim_packets_to_budgetcomputesopus_samples()for every packet twice (once insum(...),… · NewWhat changed in this PR
Updates streamed-music (
0x48) parsing to correctly interpret HDR24 per-channel headers, honoringblock_samplesbudgets and stereo-interleavedskip_samples, including deficit carry-over between chunks.Changes:
(subblocks, skip_samples, block_samples)from the per-channel 24-byte headers and trim packets beyondblock_samples.skip // pch) and per-channel skip when verifying repeated-prefix overlaps, plus deficit continuation when a prior chunk undershot its budget.skip_samples/block_samplessemantics and deficit carry-over recovery rules.Review effort: Lite
Imported from ubiquitarianism/leonida. Originally posted by Copilot on 2026-11-24T18:43:23Z.
Code review location:
tools/awc_opus.py; line 406opus_packets()always copies packet payloads into newbytes. Incollect_packets=Falsemode, this still allocates per-packet bytes even though callers ultimately discard buffers after overlap validation. If allocation pressure matters (as noted in the PR description), consider having the overlap-check logic work on(start, end)ranges (ormemoryviewslices) and only materializebyteswhencollect_packets=True(or when needed to persist output).Imported from ubiquitarianism/leonida. Originally posted by Copilot on 2026-11-24T18:43:23Z.
Code review location:
tools/awc_opus.py; line 282_trim_packets_to_budgetcomputesopus_samples()for every packet twice (once insum(...), again in the trimming loop). This is avoidable by doing a single pass that accumulates durations until reaching/exceedingtarget_frames(and separately computing deficit when you never reach the target). This is likely small per chunk, but it’s in a hot loop over all packets/blocks.Imported from ubiquitarianism/leonida. Originally posted by Elijah-J on 2026-11-24T18:54:00Z.
I addressed the three review notes in
c640232: empty budgeted chunks now update skip state, metadata-only scans avoid copying packet payloads, and budget trimming stops once the target is reached. All 93 focused tests passed, and FFmpeg again matched the declared lengths of all 11 sampled stems. The current CI and No Game Data runs are waiting for maintainer approval. CI · No Game DataImported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T13:09:23Z.
Red/green: tests/test_awc_opus.py 6 failed on main, 67 passed with the PR.
Targeted batch of 30 PRs (their tests, the tests importing the changed modules, the docs tests, the translator suite) on main
a997a3c: no new failure, Windows 11 / Python.AI-assisted (Claude Code, Claude Opus 5.5)