DSP: convolve reverb streams on the host #240

Closed
Quat3rnion wants to merge 1 commit from upstream-pr/240 into main
Quat3rnion commented 2026-11-24 01:43:09 +00:00 (Migrated from github.com)

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


What

DSP convolution streams returned silence because the impulse-response layout
was unknown. The Xbox docs describe it: frequency-domain complex pairs split
into filter blocks of blockFrameCount pairs, with an optional per-channel
stereo IR. This adds a portable partitioned FFT convolver that decodes that
layout and wires it into XDspSubmitCommand, so reverb returns are wet. FFT
and IFFT streams still return silence; their buffers are spectra, not audio.

The console does not store the Nyquist bin, so it is reconstructed by
conjugate symmetry. A unity impulse therefore comes back within about 0.2
percent instead of exactly, and the convolver allocates block scratch per
call; both are noted in the code.

An AI tool wrote part of this change.

Tested

  • Linux: cargo test --workspace with PR #112's Linux build fix applied locally (not part of this PR): 171 passed, 0 failed, 3 ignored. The convolution tests compare against direct time-domain convolution and exercise the API end to end.
  • Windows cross-build: cargo check --target x86_64-pc-windows-gnu --workspace --tests passes. The Windows-only tests were not run; there is no Windows host here.
  • Not tested: a real title or the console DSP hardware. The exact mapping of activation option bits 2 and 8 follows the existing stream test (bit 2 deinterleaved, bit 8 stereo IR).

Checklist

  • cargo fmt on the changed files; workspace tests and Windows cross-check pass as described.
  • 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:5464472449 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/240). Originally posted by [Quat3rnion](https://github.com/Quat3rnion) on 2026-11-24T01:43:09Z. --- ## What DSP convolution streams returned silence because the impulse-response layout was unknown. The Xbox docs describe it: frequency-domain complex pairs split into filter blocks of `blockFrameCount` pairs, with an optional per-channel stereo IR. This adds a portable partitioned FFT convolver that decodes that layout and wires it into `XDspSubmitCommand`, so reverb returns are wet. FFT and IFFT streams still return silence; their buffers are spectra, not audio. The console does not store the Nyquist bin, so it is reconstructed by conjugate symmetry. A unity impulse therefore comes back within about 0.2 percent instead of exactly, and the convolver allocates block scratch per call; both are noted in the code. An AI tool wrote part of this change. ## Tested - Linux: `cargo test --workspace` with PR #112's Linux build fix applied locally (not part of this PR): 171 passed, 0 failed, 3 ignored. The convolution tests compare against direct time-domain convolution and exercise the API end to end. - Windows cross-build: `cargo check --target x86_64-pc-windows-gnu --workspace --tests` passes. The Windows-only tests were not run; there is no Windows host here. - Not tested: a real title or the console DSP hardware. The exact mapping of activation option bits 2 and 8 follows the existing stream test (bit 2 deinterleaved, bit 8 stereo IR). ## Checklist - [x] `cargo fmt` on the changed files; workspace tests and Windows cross-check pass as described. - [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:56 +00:00 (Migrated from github.com)

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


Thanks @Quat3rnion for the host-side DSP convolution path. I tested the open PR at head 9f77a9a27d620ee5f88384f7f98c517f2d38741f with:

cargo test --locked -p victory-hle --lib dsp_convolve -- --test-threads=1

Result: 6 passed, 0 failed, 0 ignored. The tests cover FFT round-tripping, impulse response copying, block convolution against a direct reference, stereo channel separation, gain ramps/reset, and malformed layout/buffer rejection. This validates the synthetic convolution math and buffer handling; it does not measure behavior with a live title audio stream or real host audio device.

Code: dsp_convolve.rs, dsp.rs.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122609745 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/240#issuecomment-7122609745). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T05:05:09Z. --- Thanks @Quat3rnion for the host-side DSP convolution path. I tested the open PR at head `9f77a9a27d620ee5f88384f7f98c517f2d38741f` with: ``` cargo test --locked -p victory-hle --lib dsp_convolve -- --test-threads=1 ``` Result: 6 passed, 0 failed, 0 ignored. The tests cover FFT round-tripping, impulse response copying, block convolution against a direct reference, stereo channel separation, gain ramps/reset, and malformed layout/buffer rejection. This validates the synthetic convolution math and buffer handling; it does not measure behavior with a live title audio stream or real host audio device. Code: [dsp_convolve.rs](https://github.com/Marvisak/VIctory/blob/9f77a9a27d620ee5f88384f7f98c517f2d38741f/crates/victory-hle/src/modules/dsp_convolve.rs), [dsp.rs](https://github.com/Marvisak/VIctory/blob/9f77a9a27d620ee5f88384f7f98c517f2d38741f/crates/victory-hle/src/modules/dsp.rs).
mercuryVM commented 2026-11-24 13:24:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T13:24:13Z.

Review: APPROVED


Tested 2d1036d on Windows 11, RTX 5070, MSVC: cargo test -p victory-hle 94 passed, including the convolver tests (a unity impulse within tolerance, the stereo IR layout).

The partitioned FFT convolver and the documented IR layout (blocks of blockFrameCount complex pairs, Nyquist rebuilt by conjugate symmetry) look right, and FFT/IFFT streams correctly stay silent. Clippy adds five new warnings in the new code, which suggest leftovers:

  • dsp_convolve.rs:
    • encode_ir and reset are never used. If they're test helpers, put them under #[cfg(test)]; otherwise drop them.
    • Two needless_range_loop warnings (the bin and frame loops at lines 246/256).
    • An f32 -> f32 cast.
  • dsp.rs:179: an unsafe block without a SAFETY: comment.
  • The per-call block scratch allocation you mention is on the audio thread. Keeping it in the stream state would avoid an allocation every submit.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6039964286 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/240#pullrequestreview-6039964286). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T13:24:13Z. **Review:** APPROVED --- Tested 2d1036d on Windows 11, RTX 5070, MSVC: `cargo test -p victory-hle` 94 passed, including the convolver tests (a unity impulse within tolerance, the stereo IR layout). The partitioned FFT convolver and the documented IR layout (blocks of `blockFrameCount` complex pairs, Nyquist rebuilt by conjugate symmetry) look right, and FFT/IFFT streams correctly stay silent. Clippy adds five new warnings in the new code, which suggest leftovers: - `dsp_convolve.rs`: - `encode_ir` and `reset` are never used. If they're test helpers, put them under `#[cfg(test)]`; otherwise drop them. - Two `needless_range_loop` warnings (the `bin` and `frame` loops at lines 246/256). - An `f32 -> f32` cast. - `dsp.rs:179`: an `unsafe` block without a `SAFETY:` comment. - The per-call block scratch allocation you mention is on the audio thread. Keeping it in the stream state would avoid an allocation every submit. AI-assisted (Claude Code).
Yaekai commented 2026-11-24 17:04:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Yaekai on 2026-11-24T16:28:27Z.


Independent test & review on Windows 11 (Rust 1.98.1) at head 723f4a2:

  • cargo test -p victory-hle --lib: 101 passed, 0 failed.
  • Live GTA VI (1.0.2.1, --console series-s): audio runs cleanly with no panics or crashes.
  • CI blocker (cargo clippy -p victory-hle -- -D warnings): fails with 5 lints in dsp_convolve.rs before merge:
    1. dead_code: method reset is never used
    2. dead_code: function encode_ir is never used
    3. undocumented_unsafe_blocks: unsafe block missing a safety comment
    4. needless_range_loop: the loop variable frame is used to index spectrum
    5. needless_range_loop: the loop variable bin is only used to index spectrum
<!-- greyfinch-sync:Marvisak/VIctory:comment:7137721227 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/240#issuecomment-7137721227). Originally posted by [Yaekai](https://github.com/Yaekai) on 2026-11-24T16:28:27Z. --- Independent test & review on Windows 11 (Rust 1.98.1) at head `723f4a2`: - `cargo test -p victory-hle --lib`: 101 passed, 0 failed. - Live GTA VI (`1.0.2.1`, `--console series-s`): audio runs cleanly with no panics or crashes. - **CI blocker (`cargo clippy -p victory-hle -- -D warnings`)**: fails with 5 lints in `dsp_convolve.rs` before merge: 1. `dead_code`: `method reset is never used` 2. `dead_code`: `function encode_ir is never used` 3. `undocumented_unsafe_blocks`: `unsafe block missing a safety comment` 4. `needless_range_loop`: `the loop variable frame is used to index spectrum` 5. `needless_range_loop`: `the loop variable bin is only used to index spectrum`
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:40Z.


Correction to my earlier comment: the CI run of this PR did run and fails on clippy. For reference, what cargo clippy -p victory-hle --all-targets --locked -- -D warnings reports on this PR merged onto main at ffe310e:

  • dsp_convolve.rs:173: method reset is never used (dead code)
  • dsp_convolve.rs:246: function encode_ir is never used (dead code)
  • dsp.rs:179: unsafe block missing a safety comment
  • dsp_convolve.rs:203 and :256: needless_range_loop (the loop variables only index spectrum)
  • dsp_convolve.rs:328: casting f32 to f32 is unnecessary (test build)

The tests pass. AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139568309 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/240#issuecomment-7139568309). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-24T17:41:40Z. --- Correction to my earlier comment: the CI run of this PR did run and fails on clippy. For reference, what `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` reports on this PR merged onto `main` at `ffe310e`: - `dsp_convolve.rs:173`: method `reset` is never used (dead code) - `dsp_convolve.rs:246`: function `encode_ir` is never used (dead code) - `dsp.rs:179`: unsafe block missing a safety comment - `dsp_convolve.rs:203` and `:256`: `needless_range_loop` (the loop variables only index `spectrum`) - `dsp_convolve.rs:328`: casting `f32` to `f32` is unnecessary (test build) The tests pass. AI-assisted (Claude Code); no game data.
Marvisak commented 2026-11-25 01:07:48 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs work. CI fails on clippy in crates/victory-hle/src/modules/dsp_convolve.rs (needless_range_loop around line 256, unnecessary_cast at line 328, and others).

Beyond that, this changes emulation behaviour without stated evidence: the impulse-response layout Convolver::new decodes (complex pairs in blocks of frames, the Nyquist bin dropped, one run per channel with option bit 8) is asserted, while main's module doc in dsp.rs says the layout is unknown. The new checks in valid() also change the activation call's return values, and the tests use the PR's own encode_ir, so they only check that the code agrees with itself. Please cite public documentation for the layout or show it against the title's own data, and reword the comment that uses an identifier copied from the console SDK headers.

CI: failing (clippy).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148518583 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/240#issuecomment-7148518583). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:26:49Z. --- <!-- victory-triage v1 head=723f4a296a00aebc416d60747f04e5c796ee0675 verdict=needs-work at=2026-11-25T00:18:46Z --> Automated triage for the maintainers. **Needs work.** CI fails on clippy in `crates/victory-hle/src/modules/dsp_convolve.rs` (`needless_range_loop` around line 256, `unnecessary_cast` at line 328, and others). Beyond that, this changes emulation behaviour without stated evidence: the impulse-response layout `Convolver::new` decodes (complex pairs in blocks of `frames`, the Nyquist bin dropped, one run per channel with option bit 8) is asserted, while main's module doc in `dsp.rs` says the layout is unknown. The new checks in `valid()` also change the activation call's return values, and the tests use the PR's own `encode_ir`, so they only check that the code agrees with itself. Please cite public documentation for the layout or show it against the title's own data, and reword the comment that uses an identifier copied from the console SDK headers. CI: failing (clippy). --- _Generated by [Claude Code](https://claude.ai/code)_
kais7654 commented 2026-11-25 15:04:24 +00:00 (Migrated from github.com)

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


The check job fails on clippy -D warnings: five warnings in the new
code, no test failure. Rebased onto main 940d32f's layout with the
fixes and opened a PR: the needless_range_loop pair, reset and
encode_ir marked cfg(test) (their only callers are tests), the IR
slice's SAFETY note moved against its unsafe block, and a doubled cast.
Your convolution tests all pass on a Windows host (victory-hle: 150/0),
so the change itself is sound — the head was one clippy pass away.

AI-assisted (Mistral Vibe).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165739776 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/240#issuecomment-7165739776). Originally posted by [kais7654](https://github.com/kais7654) on 2026-11-25T14:44:25Z. --- The check job fails on clippy -D warnings: five warnings in the new code, no test failure. Rebased onto main 940d32f's layout with the fixes and opened a PR: the needless_range_loop pair, `reset` and `encode_ir` marked cfg(test) (their only callers are tests), the IR slice's SAFETY note moved against its unsafe block, and a doubled cast. Your convolution tests all pass on a Windows host (victory-hle: 150/0), so the change itself is sound — the head was one clippy pass away. AI-assisted (Mistral Vibe).
kilolimaVI commented 2026-11-26 21:46:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-26T21:46:31Z.


FYI: #2483 carries this PR's commit plus the clippy fixes CI needs, and it merges cleanly onto current main with its DSP tests passing and clippy clean (details on #2483).

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204046943 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/240#issuecomment-7204046943). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-26T21:46:31Z. --- FYI: #2483 carries this PR's commit plus the clippy fixes CI needs, and it merges cleanly onto current main with its DSP tests passing and clippy clean (details on #2483). AI-assisted (Claude).
Quat3rnion commented 2026-11-27 02:46:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-27T02:46:02Z.


Superseded by #2483, which carries this PR's convolution commit with the clippy fixes CI needs and is verified on Windows. Thanks @kais7654 for picking it up.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7208413038 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/240#issuecomment-7208413038). Originally posted by [Quat3rnion](https://github.com/Quat3rnion) on 2026-11-27T02:46:02Z. --- Superseded by #2483, which carries this PR's convolution commit with the clippy fixes CI needs and is verified on Windows. Thanks @kais7654 for picking it up.

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