audio: accept NGS2 sampler waveform controls on non-sampler racks #968

Closed
github-bot wants to merge 1 commit from gh-pr/968/head into gh-pr/968/base
Owner

@⁠mriamnobody on GitHub · 2026-10-02 04:34 UTC · original
mriamnobody:audio-ngs2-waveform-control-rack-types → main · +164 −2 · 3 files · 1 commits · closed without merging

Summary

The NGS2 voice-control gate required an exact rack-type match: control id 0x1000 (sampler waveform setup) was only accepted on Sampler racks (and 0x4001 on CustomSampler racks), and EXIT_NOT_IMPLEMENTED fired otherwise (ngs2.cpp:2357).

Games legally drive these controls on other rack types. Atomfall (Asura engine, PPSA15493) owns only one Mastering rack (0x3000) and five CustomSubmixer racks (0x4002) — no sampler rack at all — yet sends id = 0x10000000 to a CustomSubmixer-rack voice, killing the emulator right after the intro video (AvPlayer video stopped -> fatal). Since the game plays audio on hardware while owning no sampler racks, the strict check is over-restrictive.

Safety: the entire handler behind the check (SetupSampler, ngs2.cpp:577) and the block path touch only per-voice state (channels, sample rate, decoder, blocks, filters) — no rack->option union access. The change allow-lists all seven known rack types; an unknown future type still fails as a genuine "not implemented".

Changes

  • src/libs/ngs2.cpp — replace the strict rack-type equality with an allow-list of all known Ngs2RackType values
  • tests/Ngs2RackControlTests.cpp (new) + CMakeLists.txt registration — ngs2_rack_control_tests covering:
    • waveform setup accepted on every known rack type
    • the exact Atomfall sequence (CustomSubmixer rack -> 0x10000000 setup -> non-repeating block queue)
    • Sampler-rack behavior unchanged (no regression for previously-working titles)
    • documented render-neutrality of non-sampler voices (render path is a separate, still-open item)

Testing performed

  • ngs2_rack_control_tests: all 4 cases pass
  • ngs2_sampler_tests: all existing cases pass (no regression)
  • Full local test suite: 25/27 executables pass; the 2 failures (kernel_file_system_tests, save_data_memory_tests) reproduce identically on a pristine build of main (verified by stashing this change) — pre-existing/environmental, unrelated to this PR
  • Live game: Atomfall (PPSA15493, dump v1.00) previously died at ngs2.cpp:2357 immediately after the intro video; with this change the game passes the gate, its NGS2 racks/voices initialize, and it progresses into shader compilation until an unrelated later issue (shader resource tracking, the open #855 class: hash=0x4b3c8fdeb1ad6300 stage=pixel pc=0x1c40 GetImageResource dword 0 is not a valid runtime value) — reproduced identically on the latest release build b3e419f, i.e. independent of this PR
  • #641 (Atomfall won't boot), #766 (Atomfall stops after intro) — this pins the exact stop point and clears it
  • Same failure message family as #855 (that one is the shader-tracking gate, a separate subsystem)

AI disclosure (per contributing policy)

This change was developed with AI assistance (analysis, patch drafting, and test writing). The submitter ran the build and test suite locally, reviewed the diff, and performed the live game verification described above; all submitted code has been reviewed and tested by the human contributor.

**@⁠mriamnobody** on GitHub · 2026-10-02 04:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/968) `mriamnobody:audio-ngs2-waveform-control-rack-types` → `main` · +164 −2 · 3 files · 1 commits · closed without merging ## Summary The NGS2 voice-control gate required an exact rack-type match: control id `0x1000` (sampler waveform setup) was only accepted on `Sampler` racks (and `0x4001` on `CustomSampler` racks), and `EXIT_NOT_IMPLEMENTED` fired otherwise (`ngs2.cpp:2357`). Games legally drive these controls on other rack types. **Atomfall** (Asura engine, PPSA15493) owns only one Mastering rack (`0x3000`) and five CustomSubmixer racks (`0x4002`) — no sampler rack at all — yet sends `id = 0x10000000` to a CustomSubmixer-rack voice, killing the emulator right after the intro video (`AvPlayer video stopped` -> fatal). Since the game plays audio on hardware while owning no sampler racks, the strict check is over-restrictive. **Safety:** the entire handler behind the check (`SetupSampler`, `ngs2.cpp:577`) and the block path touch only per-voice state (channels, sample rate, decoder, blocks, filters) — no `rack->option` union access. The change allow-lists all seven known rack types; an unknown future type still fails as a genuine "not implemented". ## Changes - `src/libs/ngs2.cpp` — replace the strict rack-type equality with an allow-list of all known `Ngs2RackType` values - `tests/Ngs2RackControlTests.cpp` (new) + `CMakeLists.txt` registration — `ngs2_rack_control_tests` covering: - waveform setup accepted on **every** known rack type - the exact Atomfall sequence (CustomSubmixer rack -> `0x10000000` setup -> non-repeating block queue) - Sampler-rack behavior unchanged (no regression for previously-working titles) - documented render-neutrality of non-sampler voices (render path is a separate, still-open item) ## Testing performed - `ngs2_rack_control_tests`: all 4 cases pass - `ngs2_sampler_tests`: all existing cases pass (no regression) - Full local test suite: 25/27 executables pass; the 2 failures (`kernel_file_system_tests`, `save_data_memory_tests`) reproduce identically on a pristine build of `main` (verified by stashing this change) — pre-existing/environmental, unrelated to this PR - Live game: Atomfall (PPSA15493, dump v1.00) previously died at `ngs2.cpp:2357` immediately after the intro video; with this change the game passes the gate, its NGS2 racks/voices initialize, and it progresses into shader compilation until an unrelated later issue (shader resource tracking, the open #855 class: `hash=0x4b3c8fdeb1ad6300 stage=pixel pc=0x1c40 GetImageResource dword 0 is not a valid runtime value`) — reproduced identically on the latest release build `b3e419f`, i.e. independent of this PR ## Related issues - #641 (Atomfall won't boot), #766 (Atomfall stops after intro) — this pins the exact stop point and clears it - Same failure message family as #855 (that one is the shader-tracking gate, a separate subsystem) ## AI disclosure (per contributing policy) This change was developed with AI assistance (analysis, patch drafting, and test writing). The submitter ran the build and test suite locally, reviewed the diff, and performed the live game verification described above; all submitted code has been reviewed and tested by the human contributor.
The voice-control gate required an exact rack-type match: control id 0x1000
(sampler waveform setup) was only accepted on Sampler racks and 0x4001 on
CustomSampler racks, exiting otherwise.

Games legally drive these controls on other rack types: Atomfall (Asura
engine, PPSA15493) owns only Mastering and CustomSubmixer racks yet sends
0x10000000 to a CustomSubmixer-rack voice, exiting at ngs2.cpp:2357 right
after its intro video. SetupSampler and the block path only touch voice
state, so every known rack type is now allowed; unknown future types still
fail as a genuine not-implemented.

Added ngs2_rack_control_tests covering all rack types, the Atomfall
sequence, sampler-rack behavior, and the render-neutrality contract.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:38:36 +00:00
github-bot closed this pull request 2026-11-26 09:38:36 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 04:37 UTC · original · edited 2026-10-02 04:41 UTC

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

Waveform setup and block controls now pass the rack-type check for all seven known rack types. New regression tests check control results, voice configuration, and rendering on CustomSubmixer and Sampler racks. CMake now defines the test executable and its dependencies.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🔵 Low · up to 7aadd

Waveform controls are now accepted on all known NGS2 rack types, which unblocks the Atomfall startup. A title that queues blocks repeatedly on a non-sampler voice could grow memory. This is worth a follow-up but is not likely to block merge.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 7aadd

Newly accepted waveform blocks can remain queued indefinitely on non-sampler voices. Continued submissions may exhaust emulator memory unless the caller explicitly clears, resets, or destroys the rack. The exposure is confined to the existing emulator process; no additional privilege boundary was identified.

Retained concerns

  • Medium · security · inferred: The widened gate accepts waveform blocks on non-sampler voices without a corresponding consumer or automatic completion path. Submissions that retain block acceptance can grow the unbounded descriptor queue despite continued rendering. Stop events do not clear it; cleanup depends on explicit clearing, waveform setup, or rack destruction. Sustained submissions can therefore cause emulator-process memory exhaustion.
Security review details

Security Blast Radius

  • inferred — The supported adverse outcome is heap growth and availability loss in the emulator process hosting the voices. Triggering it requires access to guest audio controls and a voice on a newly eligible rack. The inspected path does not establish a cross-service or credential exposure.

Security Findings and Attack Paths

  • inferred — A guest can configure a non-sampler voice and repeatedly submit non-repeating blocks with the continued-acceptance flag, without the clear flag. Each submission allocates retained descriptor storage, while rendering neither consumes those blocks nor emits their completion callbacks. This is newly reachable on non-sampler racks; the unbounded insertion mechanism already existed for sampler voices. Memory exhaustion is inferred from this path, not demonstrated by an executed test.

Trust Boundaries and Controls

  • observed — Guest-supplied block data remains referenced rather than copied into owned waveform storage. The changed path copies block metadata into voice-owned storage. The scoped evidence does not establish a pinning or lifetime contract for retained data pointers; it also does not prove a dangling-pointer dereference on non-sampler voices.

Resilience and Maintainability Implications

  • observed — Control and rendering take the per-system mutex, and explicit rack destruction takes that mutex before destroying voices. Setup clears queues and resets decoder state; block clearing is caller-selected. Stop and empty events change playback state without clearing queued blocks, so terminal playback state does not guarantee resource release.

Hardening Proposals

  • proposed — Define a bounded ownership and retirement policy for accepted non-sampler blocks independently of audible rendering. Possible designs include bounded compatibility storage with explicit completion semantics or a supported consumer path. Validate continued submissions and interruption/cleanup against that policy.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the NGS2 rack-control change, its rationale, tests, and validation results.
Title check ✅ Passed The title clearly and concisely describes the main change: allowing NGS2 sampler waveform controls on non-sampler racks.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 u…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 04:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/968#issuecomment-5945687752) · edited 2026-10-02 04:41 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/968?cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough Waveform setup and block controls now pass the rack-type check for all seven known rack types. New regression tests check control results, voice configuration, and rendering on CustomSubmixer and Sampler racks. CMake now defines the test executable and its dependencies. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"7aaddca2d244c897a59f39ac5431dca2b4d11e47" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🔵 Low_ · up to `7aadd` <!-- final_review_risk_coverage:{"sourceCommitId":"7aaddca2d244c897a59f39ac5431dca2b4d11e47","coveredCommitId":"7aaddca2d244c897a59f39ac5431dca2b4d11e47","kind":"reviewed"} --> Waveform controls are now accepted on all known NGS2 rack types, which unblocks the Atomfall startup. A title that queues blocks repeatedly on a non-sampler voice could grow memory. This is worth a follow-up but is not likely to block merge. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `7aadd` Newly accepted waveform blocks can remain queued indefinitely on non-sampler voices. Continued submissions may exhaust emulator memory unless the caller explicitly clears, resets, or destroys the rack. The exposure is confined to the existing emulator process; no additional privilege boundary was identified. **Retained concerns** - **Medium · security · inferred:** The widened gate accepts waveform blocks on non-sampler voices without a corresponding consumer or automatic completion path. Submissions that retain block acceptance can grow the unbounded descriptor queue despite continued rendering. Stop events do not clear it; cleanup depends on explicit clearing, waveform setup, or rack destruction. Sustained submissions can therefore cause emulator-process memory exhaustion. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — The supported adverse outcome is heap growth and availability loss in the emulator process hosting the voices. Triggering it requires access to guest audio controls and a voice on a newly eligible rack. The inspected path does not establish a cross-service or credential exposure. **Security Findings and Attack Paths** - _inferred_ — A guest can configure a non-sampler voice and repeatedly submit non-repeating blocks with the continued-acceptance flag, without the clear flag. Each submission allocates retained descriptor storage, while rendering neither consumes those blocks nor emits their completion callbacks. This is newly reachable on non-sampler racks; the unbounded insertion mechanism already existed for sampler voices. Memory exhaustion is inferred from this path, not demonstrated by an executed test. **Trust Boundaries and Controls** - _observed_ — Guest-supplied block data remains referenced rather than copied into owned waveform storage. The changed path copies block metadata into voice-owned storage. The scoped evidence does not establish a pinning or lifetime contract for retained data pointers; it also does not prove a dangling-pointer dereference on non-sampler voices. **Resilience and Maintainability Implications** - _observed_ — Control and rendering take the per-system mutex, and explicit rack destruction takes that mutex before destroying voices. Setup clears queues and resets decoder state; block clearing is caller-selected. Stop and empty events change playback state without clearing queued blocks, so terminal playback state does not guarantee resource release. **Hardening Proposals** - _proposed_ — Define a bounded ownership and retirement policy for accepted non-sampler blocks independently of audible rendering. Possible designs include bounded compatibility storage with explicit completion semantics or a supported consumer path. Validate continued submissions and interruption/cleanup against that policy. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 5</summary> <details> <summary>✅ Passed checks (5 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Description check | ✅ Passed | The description clearly explains the NGS2 rack-control change, its rationale, tests, and validation results. | | Title check | ✅ Passed | The title clearly and concisely describes the main change: allowing NGS2 sampler waveform controls on non-sampler racks. | | Docstring Coverage | ✅ Passed | Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 u… | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts > Autopilot is currently an internal CodeRabbit preview. <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=968)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -2357,1 +2362,3 @@
(rack_id == 0x1000 ? Ngs2RackType::Sampler : Ngs2RackType::CustomSampler));
voice->rack->type != Ngs2RackType::Sampler &&
voice->rack->type != Ngs2RackType::CustomSampler &&
voice->rack->type != Ngs2RackType::Submixer &&
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 04:37 UTC · original

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Advance or release blocks accepted on non-sampler racks.

If a non-sampler voice repeatedly queues blocks with flag 1, control 0x10000001 keeps appending to voice.blocks. Ngs2RenderVoice consumes blocks only on Sampler and CustomSampler racks. Rendering therefore never drains this queue or runs its block-completion callbacks. A long-running stream can retain an unbounded number of blocks. Add a neutral completion path for non-sampler voices, or avoid retaining blocks that cannot be consumed.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 04:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/968#discussion_r4162901866) _🩺 Stability & Availability_ | _🟠 Major_ | _🏗️ Heavy lift_ **Advance or release blocks accepted on non-sampler racks.** If a non-sampler voice repeatedly queues blocks with flag `1`, control `0x10000001` keeps appending to `voice.blocks`. `Ngs2RenderVoice` consumes blocks only on Sampler and CustomSampler racks. Rendering therefore never drains this queue or runs its block-completion callbacks. A long-running stream can retain an unbounded number of blocks. Add a neutral completion path for non-sampler voices, or avoid retaining blocks that cannot be consumed. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:b6c7274b08b6a75c8b083aee --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 04:37 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: e512001a-5fec-47ab-9545-20434044f533

📥 Commits

Reviewing files that changed from the base of the PR and between b3e419ff11 and 7aaddca2d2.

📒 Files selected for processing (3)
  • CMakeLists.txt
  • src/libs/ngs2.cpp
  • tests/Ngs2RackControlTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 04:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/968#pullrequestreview-5388354048) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `e512001a-5fec-47ab-9545-20434044f533` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between b3e419ff1101999525fa2d061ada1d102cf788b1 and 7aaddca2d244c897a59f39ac5431dca2b4d11e47. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `CMakeLists.txt` * `src/libs/ngs2.cpp` * `tests/Ngs2RackControlTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠Nmzik on GitHub · 2026-10-08 14:46 UTC · original

This is a hack

**@⁠Nmzik** on GitHub · 2026-10-08 14:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/968#issuecomment-6062446876) This is a hack

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.