[PR #1072] tools/awc_opus: honor hdr24 block_samples budget, interleaved skip, and deficit continuation #1108

Open
opened 2026-11-26 20:20:07 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1072
Author: @Elijah-J
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/awc-hdr24-chunk-budget-skip


📝 Commits (3)

  • c6ba76d tools/awc_opus: honor hdr24 block_samples budget, interleaved skip, and deficit continuation
  • d05a683 tools/awc_opus: bound streamed metadata packet retention
  • c640232 tools/awc_opus: honor empty chunk budgets in streamed music

📊 Changes

3 files changed (+231 additions, -31 deletions)

View changed files

📝 docs/audio.md (+16 -5)
📝 tests/test_awc_opus.py (+111 -0)
📝 tools/awc_opus.py (+104 -26)

📄 Description

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 checked skip as a per-channel frame count and ignored block_samples (+12), which rejected multi-stem/multi-block streamed music banks that:

  • pad a chunk's trailing 2048-byte subblock with extra Opus packets past block_samples / packet_channels,
  • store skip_samples in interleaved stereo units (2 * frames), or
  • stop a chunk short of its block_samples budget so the deficit carries into the next chunk's skip_samples.

Changes:

  • tools/awc_opus.py: read (count, skip, block_samples) from hdr24 +4..+16; trim trailing subblock padding packets past block_samples // pch; match interleaved (skip // pch) and per-channel (skip) repeated prefixes; handle exact-boundary deficit continuation when a preceding block stopped short of its block_samples budget while continuing to fail closed on partial/corrupt skips or odd block_samples.
  • docs/audio.md: document +8 (skip_samples), +12 (block_samples), and the conditions for carry-over recovery under ### Streamed music (0x48).
  • Metadata-only reads keep block locations and only the packet buffers needed for the current overlap check. On an 8.6 MB test bank, traced temporary allocations peaked at 380 KB, down from 9.1 MB in the first draft.
  • 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 OK
  • python3 -I tests/test_awc_manifest.py -v — 23/23 OK
  • python3 -I tests/test_text_write_line_endings.py -v — 3/3 OK
  • python3 -m compileall -q make_game.py tools tests — exit 0

A 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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — audio tool/docs only)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1072 **Author:** [@Elijah-J](https://github.com/Elijah-J) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/awc-hdr24-chunk-budget-skip` --- ### 📝 Commits (3) - [`c6ba76d`](https://github.com/ubiquitarianism/leonida/commit/c6ba76d74ac128fcc8a2c28778ae89f16f0b9f02) tools/awc_opus: honor hdr24 block_samples budget, interleaved skip, and deficit continuation - [`d05a683`](https://github.com/ubiquitarianism/leonida/commit/d05a68356ef5c5779bdc53d5e32d508b8a991e62) tools/awc_opus: bound streamed metadata packet retention - [`c640232`](https://github.com/ubiquitarianism/leonida/commit/c640232b8bbb8a20cb07a16a0920065b151c8216) tools/awc_opus: honor empty chunk budgets in streamed music ### 📊 Changes **3 files changed** (+231 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `docs/audio.md` (+16 -5) 📝 `tests/test_awc_opus.py` (+111 -0) 📝 `tools/awc_opus.py` (+104 -26) </details> ### 📄 Description Claimed in the coordination issue as: [AWC-HDR24-BUDGET](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140624662) (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 checked `skip` as a per-channel frame count and ignored `block_samples` (`+12`), which rejected multi-stem/multi-block streamed music banks that: - pad a chunk's trailing 2048-byte subblock with extra Opus packets past `block_samples / packet_channels`, - store `skip_samples` in interleaved stereo units (`2 * frames`), or - stop a chunk short of its `block_samples` budget so the deficit carries into the next chunk's `skip_samples`. Changes: - `tools/awc_opus.py`: read `(count, skip, block_samples)` from `hdr24` `+4..+16`; trim trailing subblock padding packets past `block_samples // pch`; match interleaved (`skip // pch`) and per-channel (`skip`) repeated prefixes; handle exact-boundary deficit continuation when a preceding block stopped short of its `block_samples` budget while continuing to fail closed on partial/corrupt skips or odd `block_samples`. - `docs/audio.md`: document `+8` (`skip_samples`), `+12` (`block_samples`), and the conditions for carry-over recovery under `### Streamed music (0x48)`. - Metadata-only reads keep block locations and only the packet buffers needed for the current overlap check. On an 8.6 MB test bank, traced temporary allocations peaked at 380 KB, down from 9.1 MB in the first draft. - `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 OK - `python3 -I tests/test_awc_manifest.py -v` — 23/23 OK - `python3 -I tests/test_text_write_line_endings.py -v` — 3/3 OK - `python3 -m compileall -q make_game.py tools tests` — exit 0 A 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. *(n/a — audio tool/docs only)* --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1108
No description provided.