APU: decode-convert and PCM rate conversion #218

Closed
github-bot wants to merge 2 commits from gh-pr/218/head into gh-pr/218/base
Owner

@⁠Quat3rnion on GitHub · 2026-11-24 01:32 UTC · original
Quat3rnion:victory-apu-convert → main · +661 −32 · 3 files · 2 commits · closed without merging

What

The console's APU accepted only DecodeOpus. Titles that connected for
DecodeConvertOpus or ConvertPCM got E_NOTIMPL, so their resampled audio
was silent. This adds both process types with the documented
maxFrameCountPerOutput values, pitch and frame-count handling, and
deinterleaved input and output. A portable streaming resampler holds the
conversion arithmetic and has its own unit tests.

An AI tool wrote part of this change.

Tested

  • Windows cross-build: cargo check --target x86_64-pc-windows-gnu -p victory-hle --tests passes. The three new APU tests compile but were not run; there is no Windows host here.
  • Linux: cargo test --workspace on a tree carrying PR #112's Linux build fix: 172 passed, 0 failed, 3 ignored. All eight resampler tests pass. Base main does not build the workspace on Linux yet, which is what #112 addresses.
  • Not tested: a real title or GPU.

Checklist

  • cargo fmt on the changed files; clippy and workspace tests pass on a tree with #112's build fix.
  • cargo xtask policy passes (151 files ok). No game files or data from them were added.
  • AI authorship is disclosed above.
**@⁠Quat3rnion** on GitHub · 2026-11-24 01:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/218) `Quat3rnion:victory-apu-convert` → `main` · +661 −32 · 3 files · 2 commits · closed without merging ## What The console's APU accepted only `DecodeOpus`. Titles that connected for `DecodeConvertOpus` or `ConvertPCM` got `E_NOTIMPL`, so their resampled audio was silent. This adds both process types with the documented `maxFrameCountPerOutput` values, pitch and frame-count handling, and deinterleaved input and output. A portable streaming resampler holds the conversion arithmetic and has its own unit tests. An AI tool wrote part of this change. ## Tested - Windows cross-build: `cargo check --target x86_64-pc-windows-gnu -p victory-hle --tests` passes. The three new APU tests compile but were not run; there is no Windows host here. - Linux: `cargo test --workspace` on a tree carrying PR #112's Linux build fix: 172 passed, 0 failed, 3 ignored. All eight resampler tests pass. Base `main` does not build the workspace on Linux yet, which is what #112 addresses. - Not tested: a real title or GPU. ## Checklist - [x] `cargo fmt` on the changed files; clippy and workspace tests pass on a tree with #112's build fix. - [x] `cargo xtask policy` passes (151 files ok). No game files or data from them were added. - [x] AI authorship is disclosed above.
Accept XApuProcessType 2 and 3 with their documented output lengths and convert input with a portable streaming resampler. Deinterleaved input and output, PCM frame counts and pitch ramps follow the XAPU API. Add unit tests for the resampler and Windows tests for both conversion kinds.
A zero pitch ramp left the resampler at its initial 1.0, so the two conversion tests failed on Windows. Set the pitch directly to the target when there is no ramp; keep gradual ramping for a positive rate. Addresses the review findings on #218.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:55:14 +00:00
github-bot closed this pull request 2026-11-26 03:55:14 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 05:12 UTC · original

Thanks @⁠Quat3rnion for adding decode-convert and PCM rate conversion coverage.

I tested commit 200943e067b78bc1a469fd8d24a450be17522e12 with:

cargo test --locked -p victory-hle --lib apu -- --test-threads=1
cargo test --locked -p victory-hle --lib apu_resample -- --test-threads=1
cargo test --locked -p victory-hle --lib converts_float_pcm_at_the_target_pitch -- --test-threads=1
cargo test --locked -p victory-hle --lib decodes_and_converts_an_opus_stream -- --test-threads=1

The aggregate apu run had 10 passed and 2 failed (80 filtered). The dedicated resampler filter passed all 8 tests (84 filtered), covering unit/half/double pitch, stereo pairing, carry between commands, flush of a partial frame, pitch ramps, and invalid shapes. The title-driven Opus decode test and both conversion-kind connection setup also passed.

The two failures reproduce when run individually:

These two failing tests are introduced in this PR and are absent from base commit d2a4bae1f49533ef5cb512fd1b1ba1513f2e1989, so their same-name baseline behavior could not be tested there. This covers synthetic PCM/Opus buffers and the resampler; it does not exercise audio playback through a real title or output device.

**@⁠jeremygold02** on GitHub · 2026-11-24 05:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7122733401) Thanks @⁠Quat3rnion for adding decode-convert and PCM rate conversion coverage. I tested commit `200943e067b78bc1a469fd8d24a450be17522e12` with: ``` cargo test --locked -p victory-hle --lib apu -- --test-threads=1 cargo test --locked -p victory-hle --lib apu_resample -- --test-threads=1 cargo test --locked -p victory-hle --lib converts_float_pcm_at_the_target_pitch -- --test-threads=1 cargo test --locked -p victory-hle --lib decodes_and_converts_an_opus_stream -- --test-threads=1 ``` The aggregate `apu` run had 10 passed and 2 failed (80 filtered). The dedicated resampler filter passed all 8 tests (84 filtered), covering unit/half/double pitch, stereo pairing, carry between commands, flush of a partial frame, pitch ramps, and invalid shapes. The title-driven Opus decode test and both conversion-kind connection setup also passed. The two failures reproduce when run individually: - [`converts_float_pcm_at_the_target_pitch`](https://github.com/Marvisak/VIctory/blob/200943e067b78bc1a469fd8d24a450be17522e12/crates/victory-hle/src/modules/apu.rs#L808) expected S_OK, 8 frames, pitch 2.0, and 32 output bytes; it received S_OK, 15 frames, pitch 1.0, and 60 bytes at the assertion on [line 845](https://github.com/Marvisak/VIctory/blob/200943e067b78bc1a469fd8d24a450be17522e12/crates/victory-hle/src/modules/apu.rs#L845). - [`decodes_and_converts_an_opus_stream`](https://github.com/Marvisak/VIctory/blob/200943e067b78bc1a469fd8d24a450be17522e12/crates/victory-hle/src/modules/apu.rs#L853) fails the half-pitch assertion that converted output contains more than 960 frames ([line 895](https://github.com/Marvisak/VIctory/blob/200943e067b78bc1a469fd8d24a450be17522e12/crates/victory-hle/src/modules/apu.rs#L895)). These two failing tests are introduced in this PR and are absent from base commit `d2a4bae1f49533ef5cb512fd1b1ba1513f2e1989`, so their same-name baseline behavior could not be tested there. This covers synthetic PCM/Opus buffers and the resampler; it does not exercise audio playback through a real title or output device.
Author
Owner

@⁠etcetera-yt on GitHub · 2026-11-24 05:36 UTC · original

On main (d2a4bae) plus #218 alone, Windows 10 19045, Rust 1.98.1, cargo test -p victory-hle modules::apu:

modules::apu::tests::converts_float_pcm_at_the_target_pitch ... FAILED
  crates\victory-hle\src\modules\apu.rs:845:9  left: (0, 15, 1.0, 60)  right: (0, 8, 2.0, 32)
modules::apu::tests::decodes_and_converts_an_opus_stream ... FAILED
  crates\victory-hle\src\modules\apu.rs:895:9  "a half pitch writes more frames"

The resampler's own tests (apu_resample::tests::*, 8) pass, so the target pitch seems not to reach the resampler
through the APU command path: the result has pitch 1.0 and the unconverted frame count. Possibly host-dependent
(output device or sample rate); worth checking on another machine.

AI use: Claude Code, Claude Opus 5.5.

**@⁠etcetera-yt** on GitHub · 2026-11-24 05:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7123107064) On `main` (`d2a4bae`) plus #218 alone, Windows 10 19045, Rust 1.98.1, `cargo test -p victory-hle modules::apu`: ``` modules::apu::tests::converts_float_pcm_at_the_target_pitch ... FAILED crates\victory-hle\src\modules\apu.rs:845:9 left: (0, 15, 1.0, 60) right: (0, 8, 2.0, 32) modules::apu::tests::decodes_and_converts_an_opus_stream ... FAILED crates\victory-hle\src\modules\apu.rs:895:9 "a half pitch writes more frames" ``` The resampler's own tests (`apu_resample::tests::*`, 8) pass, so the target pitch seems not to reach the resampler through the APU command path: the result has pitch 1.0 and the unconverted frame count. Possibly host-dependent (output device or sample rate); worth checking on another machine. AI use: Claude Code, Claude Opus 5.5.
Author
Owner

@⁠KevinPratap on GitHub · 2026-11-24 07:13 UTC · original

The two failing tests here (converts_float_pcm_at_the_target_pitch, decodes_and_converts_an_opus_stream) come from a zero pitch_ramp never moving the pitch. Fix with a test, against this branch: https://github.com/Quat3rnion/VIctory/pull/1 (10 → 13 passing in cargo test -p victory-hle --lib apu). AI-assisted.

**@⁠KevinPratap** on GitHub · 2026-11-24 07:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7124762144) The two failing tests here (`converts_float_pcm_at_the_target_pitch`, `decodes_and_converts_an_opus_stream`) come from a zero `pitch_ramp` never moving the pitch. Fix with a test, against this branch: https://github.com/Quat3rnion/VIctory/pull/1 (10 → 13 passing in `cargo test -p victory-hle --lib apu`). AI-assisted.
Author
Owner

@⁠Quat3rnion on GitHub · 2026-11-24 07:30 UTC · original

Rebased on current main and added a fix for the two failing conversion tests: a zero pitch ramp left the resampler at its initial 1.0, so target_pitch was ignored. The pitch is now set directly when no ramp is set. New head 7175608. The APU tests are Windows-gated, so I could not run them here — could you re-run the two reported failures? Thanks.

**@⁠Quat3rnion** on GitHub · 2026-11-24 07:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7125058726) Rebased on current main and added a fix for the two failing conversion tests: a zero pitch ramp left the resampler at its initial 1.0, so target_pitch was ignored. The pitch is now set directly when no ramp is set. New head 7175608. The APU tests are Windows-gated, so I could not run them here — could you re-run the two reported failures? Thanks.
Author
Owner

@⁠lameloball2813-ui on GitHub · 2026-11-24 08:15 UTC · original

Re-ran the APU tests at the new head 7175608 on Windows 11, Rust 1.98.1, debug: cargo test -p victory-hle --lib modules::apu. All 13 passed, 0 failed, including the two that failed before:

  • modules::apu::tests::converts_float_pcm_at_the_target_pitch ... ok
  • modules::apu::tests::decodes_and_converts_an_opus_stream ... ok

The new apu_resample tests pass too (a_zero_ramp_applies_the_target_immediately, pitch_ramps_towards_the_target, stereo_channels_stay_paired and the rest).

**@⁠lameloball2813-ui** on GitHub · 2026-11-24 08:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7125910860) Re-ran the APU tests at the new head `7175608` on Windows 11, Rust 1.98.1, debug: `cargo test -p victory-hle --lib modules::apu`. All **13 passed, 0 failed**, including the two that failed before: - `modules::apu::tests::converts_float_pcm_at_the_target_pitch` ... ok - `modules::apu::tests::decodes_and_converts_an_opus_stream` ... ok The new `apu_resample` tests pass too (`a_zero_ramp_applies_the_target_immediately`, `pitch_ramps_towards_the_target`, `stereo_channels_stay_paired` and the rest).
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 17:41 UTC · original · edited 2026-11-24 18:26 UTC

Correction to my earlier comment: the CI run of this PR did run and fails on the same lints. For reference, the three errors of cargo clippy --workspace --all-targets --locked -- -D warnings on this PR merged onto main at ffe310e, all in modules/apu.rs:

  • line 470: needless_option_as_deref (decoder.as_deref_mut() on an Option<&mut _>; use decoder)
  • line 489: manual_is_multiple_of (frames % multiple != 0; use !frames.is_multiple_of(multiple))
  • line 496: chunks_exact_to_as_chunks (.chunks_exact(4); use as_chunks::<4>().0.iter())

Clippy suggests each fix. The tests pass. AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-24 17:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7139567794) · edited 2026-11-24 18:26 UTC Correction to my earlier comment: the CI run of this PR did run and fails on the same lints. For reference, the three errors of `cargo clippy --workspace --all-targets --locked -- -D warnings` on this PR merged onto `main` at `ffe310e`, all in `modules/apu.rs`: - line 470: `needless_option_as_deref` (`decoder.as_deref_mut()` on an `Option<&mut _>`; use `decoder`) - line 489: `manual_is_multiple_of` (`frames % multiple != 0`; use `!frames.is_multiple_of(multiple)`) - line 496: `chunks_exact_to_as_chunks` (`.chunks_exact(4)`; use `as_chunks::<4>().0.iter()`) Clippy suggests each fix. The tests pass. AI-assisted (Claude Code); no game data.
Author
Owner

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

Automated triage for the maintainers. Closing because it breaks a repository rule (see docs/asset-policy.md and the project rules): nothing taken from the console SDK or the game, no weakening of the asset policy, and the title stays offline.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7148039050) Automated triage for the maintainers. Closing because it breaks a repository rule (see `docs/asset-policy.md` and the project rules): nothing taken from the console SDK or the game, no weakening of the asset policy, and the title stays offline. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!218
No description provided.