HLE: keep refilling XMA PCM buffer across zero-sample decode steps #2444

Open
github-bot wants to merge 1 commit from github-bot/gh-2444 into main AGit
Owner

@⁠Texbirds on GitHub · 2026-11-25 13:38 UTC · original
Texbirds:fix/hle-audio-xma-pump-loop → main · +99 −2 · 1 files · 1 commits · open

Problem

In crates/victory-hle/src/modules/audio.rs, pump() refills voice.pcm with a single if voice.pcm.len() < SAMPLES_PER_BLOCK && !decode(context, voice) before writing a 128-sample (SAMPLES_PER_BLOCK) block to the output ring.

decode() legitimately returns true while pushing zero samples in two cases:

  • Buffer 0 is valid with 0 packets (buf0 = 0), so decode() switches to buffer 1 and returns true without decoding a frame yet.
  • start_skip covers a full 4-subframe frame (e.g., start_skip = 4), so decode() drops all 512 samples of frame 0 and returns true with voice.pcm still empty.

On main, pump() does not call decode() again for that output block; it drains 0 samples from voice.pcm, zero-pads the block, and emits a spurious silent 128-sample block before real audio resumes.

Change

  • Replace the single if refill in pump() with a while voice.pcm.len() < SAMPLES_PER_BLOCK loop that keeps calling decode() until a full block is available or decoding stops (returning early only when voice.pcm is empty so a partial tail block is still flushed).
  • Cap consecutive zero-sample decode() returns at 16 so a malformed looping stream (e.g., loop_skip >= keep) cannot spin indefinitely inside pump().
  • Output ring pointer handling, overlap-tail flushing, and decode() itself are unchanged.

Test

pump_refills_across_empty_decode_steps_without_spurious_silence (synthetic in-memory silent XMA stream from the existing silent_stream() helper, no game data):

  • Case 1 (empty buffer 0 -> buffer 1 with 2 packets / 6 frames): expects 26 * SAMPLES_PER_BLOCK total samples (24 frame blocks + 2-block overlap tail); on main this produces 27 blocks (1 extra silent block).
  • Case 2 (start_skip = 4 subframes on the same 6-frame stream): expects 22 * SAMPLES_PER_BLOCK total samples (5 remaining frames + 2-block overlap tail); on main this produces 23 blocks.
**@⁠Texbirds** on GitHub · 2026-11-25 13:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2444) `Texbirds:fix/hle-audio-xma-pump-loop` → `main` · +99 −2 · 1 files · 1 commits · open ### Problem In `crates/victory-hle/src/modules/audio.rs`, `pump()` refills `voice.pcm` with a single `if voice.pcm.len() < SAMPLES_PER_BLOCK && !decode(context, voice)` before writing a 128-sample (`SAMPLES_PER_BLOCK`) block to the output ring. `decode()` legitimately returns `true` while pushing zero samples in two cases: - Buffer 0 is valid with 0 packets (`buf0 = 0`), so `decode()` switches to buffer 1 and returns `true` without decoding a frame yet. - `start_skip` covers a full 4-subframe frame (e.g., `start_skip = 4`), so `decode()` drops all 512 samples of frame 0 and returns `true` with `voice.pcm` still empty. On `main`, `pump()` does not call `decode()` again for that output block; it drains 0 samples from `voice.pcm`, zero-pads the block, and emits a spurious silent 128-sample block before real audio resumes. ### Change - Replace the single `if` refill in `pump()` with a `while voice.pcm.len() < SAMPLES_PER_BLOCK` loop that keeps calling `decode()` until a full block is available or decoding stops (returning early only when `voice.pcm` is empty so a partial tail block is still flushed). - Cap consecutive zero-sample `decode()` returns at `16` so a malformed looping stream (e.g., `loop_skip >= keep`) cannot spin indefinitely inside `pump()`. - Output ring pointer handling, overlap-tail flushing, and `decode()` itself are unchanged. ### Test `pump_refills_across_empty_decode_steps_without_spurious_silence` (synthetic in-memory silent XMA stream from the existing `silent_stream()` helper, no game data): - **Case 1 (empty buffer 0 -> buffer 1 with 2 packets / 6 frames):** expects `26 * SAMPLES_PER_BLOCK` total samples (24 frame blocks + 2-block overlap tail); on `main` this produces 27 blocks (1 extra silent block). - **Case 2 (`start_skip = 4` subframes on the same 6-frame stream):** expects `22 * SAMPLES_PER_BLOCK` total samples (5 remaining frames + 2-block overlap tail); on `main` this produces 23 blocks.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:05:58 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 14:13 UTC · original

Independent verification of #2444 at 413cf34 (pure CPU)

Commands: cargo test -p victory-hle --lib, cargo clippy -p victory-hle --all-targets -- -D warnings, cargo xtask policy; merges cleanly with origin/main 940d32f.

  • lib tests: 144 passed, 0 failed (plus 1 in another target); clippy clean; policy OK.
  • Negative control: audio.rs reverted to origin/main with the new test kept -> pump_refills_across_empty_decode_steps_without_spurious_silence FAILS.
  • Note: the inner loop gives up after 16 consecutive zero-sample decode steps without a further empty-output guard, which is reasonable and bounded.

AI-assisted verification by Claude Code (Claude Sonnet 5.5). No game files, dumps or hashes.

**@⁠oni-swr** on GitHub · 2026-11-25 14:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2444#issuecomment-7164935440) **Independent verification of #2444 at `413cf34`** (pure CPU) Commands: `cargo test -p victory-hle --lib`, `cargo clippy -p victory-hle --all-targets -- -D warnings`, `cargo xtask policy`; merges cleanly with `origin/main` `940d32f`. - lib tests: 144 passed, 0 failed (plus 1 in another target); clippy clean; policy OK. - Negative control: `audio.rs` reverted to `origin/main` with the new test kept -> `pump_refills_across_empty_decode_steps_without_spurious_silence` FAILS. - Note: the inner loop gives up after 16 consecutive zero-sample decode steps without a further empty-output guard, which is reasonable and bounded. AI-assisted verification by Claude Code (Claude Sonnet 5.5). No game files, dumps or hashes.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 16:01 UTC · original

Automated triage for the maintainers.

Merge candidate. pump in crates/victory-hle/src/modules/audio.rs now keeps calling decode until a block is full; on main a decode step that yields no samples (an input buffer switched or used up, or a skip covering a whole frame) leaves a padded silent block in the output. The loop is bounded and the new test fails on main per an independent run. CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 16:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2444#issuecomment-7167517829) <!-- victory-triage v1 head=413cf34509321fc1543f559c462483143e61629e verdict=merge-candidate at=2026-11-25T15:53:50Z --> Automated triage for the maintainers. Merge candidate. `pump` in `crates/victory-hle/src/modules/audio.rs` now keeps calling `decode` until a block is full; on main a decode step that yields no samples (an input buffer switched or used up, or a skip covering a whole frame) leaves a padded silent block in the output. The loop is bounded and the new test fails on main per an independent run. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 16:53 UTC · original

Semantics look right: a decode step that produces zero samples (buffer-0→buffer-1 transition, or a start-skip covering a full frame) no longer causes a spurious silent block — the pump retries up to 16 consecutive empty steps, and a decode failure now emits the partial pcm it has instead of returning with samples held.

One edge: empty counts cumulative, not consecutive, zero-progress steps within a block fill (it's never reset on progress). In practice interleaved progress still reaches SAMPLES_PER_BLOCK and exits the inner loop, so the cap can only trigger on a real stall — fine as written.

**@⁠kotekompotek** on GitHub · 2026-11-25 16:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2444#issuecomment-7168694364) Semantics look right: a decode step that produces zero samples (buffer-0→buffer-1 transition, or a start-skip covering a full frame) no longer causes a spurious silent block — the pump retries up to 16 consecutive empty steps, and a `decode` failure now emits the partial `pcm` it has instead of returning with samples held. One edge: `empty` counts cumulative, not consecutive, zero-progress steps within a block fill (it's never reset on progress). In practice interleaved progress still reaches `SAMPLES_PER_BLOCK` and exits the inner loop, so the cap can only trigger on a real stall — fine as written.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2444/head:github-bot/gh-2444'
git switch 'github-bot/gh-2444'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2444'
git switch 'github-bot/gh-2444'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2444'
git switch 'github-bot/gh-2444'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2444'
git switch 'main'
git merge --squash 'github-bot/gh-2444'
git switch 'main'
git merge --ff-only 'github-bot/gh-2444'
git switch 'main'
git merge 'github-bot/gh-2444'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
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
github/Marvisak--VIctory!2444
No description provided.