APU: decode-convert and PCM rate conversion #218

Closed
Quat3rnion wants to merge 2 commits from upstream-pr/218 into main
Quat3rnion commented 2026-11-24 01:32:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-24T01:32:27Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6572562573 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/218). Originally posted by [Quat3rnion](https://github.com/Quat3rnion) on 2026-11-24T01:32:27Z. --- ## 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.
jeremygold02 commented 2026-11-24 06:55:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T05:12:52Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122733401 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7122733401). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T05:12:52Z. --- 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.
etcetera-yt commented 2026-11-24 06:56:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by etcetera-yt on 2026-11-24T05:36:32Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123107064 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7123107064). Originally posted by [etcetera-yt](https://github.com/etcetera-yt) on 2026-11-24T05:36:32Z. --- 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.
KevinPratap commented 2026-11-24 08:02:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KevinPratap on 2026-11-24T07:13:55Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7124762144 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7124762144). Originally posted by [KevinPratap](https://github.com/KevinPratap) on 2026-11-24T07:13:55Z. --- 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.
Quat3rnion commented 2026-11-24 08:02:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-24T07:30:02Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125058726 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7125058726). Originally posted by [Quat3rnion](https://github.com/Quat3rnion) on 2026-11-24T07:30:02Z. --- 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.
lameloball2813-ui commented 2026-11-24 09:06:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lameloball2813-ui on 2026-11-24T08:15:16Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125910860 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7125910860). Originally posted by [lameloball2813-ui](https://github.com/lameloball2813-ui) on 2026-11-24T08:15:16Z. --- 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).
MamaLeVrai commented 2026-11-24 18:05:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-24T17:41:38Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139567794 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7139567794). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-24T17:41:38Z. --- 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.
upstream-sync closed this pull request 2026-11-25 00:05:20 +00:00
Marvisak commented 2026-11-25 00:06:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:00:47Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148039050 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/218#issuecomment-7148039050). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:00:47Z. --- 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

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