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

Open
Texbirds wants to merge 1 commit from upstream-pr/2444 into main
Texbirds commented 2026-11-25 13:38:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T13:38:42Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6605769810 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2444). Originally posted by [Texbirds](https://github.com/Texbirds) on 2026-11-25T13:38:42Z. --- ### 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.
DenRakEiw commented 2026-11-25 14:07:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:58:20Z.

Review: APPROVED


Verified against origin/main (940d32f):

  • Continuing to refill the XMA PCM buffer across zero-sample decode steps cleanly avoids spurious silence dropouts.
  • cargo test -p victory-hle audio::: 9/9 passed (including pump_refills_across_empty_decode_steps_without_spurious_silence).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6058951567 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2444#pullrequestreview-6058951567). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T13:58:20Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`): - Continuing to refill the XMA PCM buffer across zero-sample decode steps cleanly avoids spurious silence dropouts. - `cargo test -p victory-hle audio::`: 9/9 passed (including `pump_refills_across_empty_decode_steps_without_spurious_silence`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 15:03:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:11:20Z.

Review: COMMENTED


HLE: keep refilling XMA PCM buffer across zero-sample stretches. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

<!-- greyfinch-sync:Marvisak/VIctory:review:6059178217 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2444#pullrequestreview-6059178217). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T14:11:20Z. **Review:** COMMENTED --- HLE: keep refilling XMA PCM buffer across zero-sample stretches. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
oni-swr commented 2026-11-25 15:04:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T14:13:02Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7164935440 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2444#issuecomment-7164935440). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T14:13:02Z. --- **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.
Marvisak commented 2026-11-25 16:09:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:01:03Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167517829 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2444#issuecomment-7167517829). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T16:01:03Z. --- <!-- 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)_
kotekompotek commented 2026-11-25 17:05:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T16:53:46Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7168694364 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2444#issuecomment-7168694364). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T16:53:46Z. --- 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.
fuzeofficlal commented 2026-11-26 03:04:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:05:45Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 — clean fix and ready to merge:

  • Converting pump (crates/victory-hle/src/modules/audio.rs:558-573) to loop until voice.pcm reaches SAMPLES_PER_BLOCK (128) or input is exhausted prevents spurious silence blocks across empty buffer transitions and full-frame start_skip/loop_start_skip steps, flushes partial tail samples (< 128) instead of dropping them, and bounds empty decode iterations (empty >= 16).
  • New synthetic 6-frame XMA test pump_refills_across_empty_decode_steps_without_spurious_silence exercises both buffer rollover and skipped subframes cleanly.

Local verification:

  • cargo test --locked -p victory-hle: 153/153 unit + 2/2 integration tests passed
  • cargo clippy --locked -p victory-hle --tests -- -D warnings (default & --all-features): 0 warnings
  • cargo xtask policy: 191 files ok
<!-- greyfinch-sync:Marvisak/VIctory:review:6067593750 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2444#pullrequestreview-6067593750). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T02:05:45Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 — clean fix and ready to merge: - Converting `pump` (`crates/victory-hle/src/modules/audio.rs:558-573`) to loop until `voice.pcm` reaches `SAMPLES_PER_BLOCK` (128) or input is exhausted prevents spurious silence blocks across empty buffer transitions and full-frame `start_skip`/`loop_start_skip` steps, flushes partial tail samples (`< 128`) instead of dropping them, and bounds empty decode iterations (`empty >= 16`). - New synthetic 6-frame XMA test `pump_refills_across_empty_decode_steps_without_spurious_silence` exercises both buffer rollover and skipped subframes cleanly. **Local verification**: - `cargo test --locked -p victory-hle`: **153/153 unit + 2/2 integration tests passed** - `cargo clippy --locked -p victory-hle --tests -- -D warnings` (default & `--all-features`): 0 warnings - `cargo xtask policy`: 191 files ok
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2444:upstream-pr/2444'
git switch 'upstream-pr/2444'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2444'
git switch 'upstream-pr/2444'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2444'
git switch 'upstream-pr/2444'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2444'
git switch 'main'
git merge --squash 'upstream-pr/2444'
git switch 'main'
git merge --ff-only 'upstream-pr/2444'
git switch 'main'
git merge 'upstream-pr/2444'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2442
No description provided.