feat(ngs2): report custom sampler voice state #5470

Merged
p3n1cillin merged 1 commit from upstream-pr/5470 into main 2026-10-14 12:20:03 +00:00
p3n1cillin commented 2026-10-13 20:38:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T20:38:05Z.


What

With #4417 merged, Dead Cells (PPSA15552) creates custom sampler voices (rack 0x4001) and polls them with sceNgs2VoiceGetState. That call threw for every custom sampler voice:

terminate called after throwing an instance of 'std::runtime_error'
  what():  NGS2: voice state of rack 0x4001 is not implemented

The title passes a 48-byte buffer at two call sites, and both read only the 64-bit value at offset 16:

0x1740f83: mov rdi, qword ptr [rbx + 0x28]   ; voice handle
0x1740f87: lea rsi, [rbp - 0x48]             ; state
0x1740f8b: mov edx, 0x30                     ; 48 bytes
0x1740f90: call sceNgs2VoiceGetState
0x1740f95: mov rax, qword ptr [rbp - 0x38]   ; state + 0x10
0x1740f99: mov qword ptr [rbx + 8], rax      ; kept

0x1741009: call sceNgs2VoiceGetState         ; same buffer and size
0x174100e: mov eax, dword ptr [rbp - 0x38]   ; state + 0x10
0x1741011: sub eax, dword ptr [rbx + 8]      ; minus the kept value

So offset 16 is a running counter that the title measures progress with. The custom sampler state now:

  • reports the voice's state flags in the common voice state;
  • reports the decoded sample count at offset 16;
  • zeroes the other fields;
  • returns INVALID_OUT_SIZE for any other size, as the sampler, submixer and reverb racks do.

shadPS4's OrbisNgs2CustomSamplerVoiceState is about 80 bytes, so it doesn't match what this title passes. The size and that one field come only from the title, and the other field names and the console's values are unverified. This is recorded under Unknown function info in docs/dev/debt/libSceNgs2.native.md.

Tested

  • Dead Cells on Windows 11 (MinGW GCC 15), on main a0f5916a2 with #4777. Dead Cells patches a sampler voice to a rack handle, which needs #4777 first. It also needs two local, unsubmitted stubs:

    • the custom filter param it sends, which is 48 bytes rather than the 40 main reads (see my comment on #4417);
    • its rotated sceNgs2GeomCalcListener listener, front (1,0,0) and up (0,0,1).

    Before this change, it stops on the error above about 80 s in. After it, it runs for the whole 120 s run with no library stop. With the same stack plus a local stand-in for this call, it reaches its title screen with audio.

  • Unit test: ngs2_custom now creates a custom sampler voice, renders one grain and checks that:

    • a 56-byte buffer returns INVALID_OUT_SIZE;
    • a 48-byte buffer returns INUSE|PLAYING with 8 decoded samples, then 16 after a second render.

    With main's Voice.cpp the test aborts on the throw. All 10 NGS2 tests pass on Windows and on Linux (WSL Ubuntu, GCC).

  • python tools/check_conventions.py --base origin/main and tools/pr_overlap.py pass, with no overlap with open PRs.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none to build; Dead Cells reaches it with #4777 and the custom filter param it sends
  • Unblocks: Dead Cells (PPSA15552) audio, #3553
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4849173394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5470). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-13T20:38:05Z. --- ### What With #4417 merged, Dead Cells (PPSA15552) creates custom sampler voices (rack `0x4001`) and polls them with `sceNgs2VoiceGetState`. That call threw for every custom sampler voice: ``` terminate called after throwing an instance of 'std::runtime_error' what(): NGS2: voice state of rack 0x4001 is not implemented ``` The title passes a 48-byte buffer at two call sites, and both read only the 64-bit value at offset 16: ``` 0x1740f83: mov rdi, qword ptr [rbx + 0x28] ; voice handle 0x1740f87: lea rsi, [rbp - 0x48] ; state 0x1740f8b: mov edx, 0x30 ; 48 bytes 0x1740f90: call sceNgs2VoiceGetState 0x1740f95: mov rax, qword ptr [rbp - 0x38] ; state + 0x10 0x1740f99: mov qword ptr [rbx + 8], rax ; kept 0x1741009: call sceNgs2VoiceGetState ; same buffer and size 0x174100e: mov eax, dword ptr [rbp - 0x38] ; state + 0x10 0x1741011: sub eax, dword ptr [rbx + 8] ; minus the kept value ``` So offset 16 is a running counter that the title measures progress with. The custom sampler state now: - reports the voice's state flags in the common voice state; - reports the decoded sample count at offset 16; - zeroes the other fields; - returns `INVALID_OUT_SIZE` for any other size, as the sampler, submixer and reverb racks do. shadPS4's `OrbisNgs2CustomSamplerVoiceState` is about 80 bytes, so it doesn't match what this title passes. The size and that one field come only from the title, and the other field names and the console's values are unverified. This is recorded under Unknown function info in `docs/dev/debt/libSceNgs2.native.md`. ### Tested - **Dead Cells on Windows 11** (MinGW GCC 15), on `main` `a0f5916a2` with #4777. Dead Cells patches a sampler voice to a rack handle, which needs #4777 first. It also needs two local, unsubmitted stubs: - the custom filter param it sends, which is 48 bytes rather than the 40 `main` reads (see [my comment on #4417](https://github.com/boykopovar/AnyPS5/pull/4417#issuecomment-6152733807)); - its rotated `sceNgs2GeomCalcListener` listener, front `(1,0,0)` and up `(0,0,1)`. Before this change, it stops on the error above about 80 s in. After it, it runs for the whole 120 s run with no library stop. With the same stack plus a local stand-in for this call, it reaches its title screen with audio. - **Unit test:** `ngs2_custom` now creates a custom sampler voice, renders one grain and checks that: - a 56-byte buffer returns `INVALID_OUT_SIZE`; - a 48-byte buffer returns `INUSE|PLAYING` with 8 decoded samples, then 16 after a second render. With `main`'s `Voice.cpp` the test aborts on the throw. All 10 NGS2 tests pass on Windows and on Linux (WSL Ubuntu, GCC). - `python tools/check_conventions.py --base origin/main` and `tools/pr_overlap.py` pass, with no overlap with open PRs. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none to build; Dead Cells reaches it with #4777 and the custom filter param it sends - [x] Unblocks: Dead Cells (PPSA15552) audio, #3553 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-13 23:29:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T23:29:21Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5548 docs/dev/debt/libSceNgs2.native.md L27
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157384402 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5470#issuecomment-6157384402). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T23:29:21Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5548 | `docs/dev/debt/libSceNgs2.native.md` [L27](https://github.com/boykopovar/AnyPS5/blob/1015c55ee8f5cae23ea6ec8bdcfcce0b8306107e/docs/dev/debt/libSceNgs2.native.md#L27) | | |
adriadam10 commented 2026-10-14 11:49:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:49:43Z.


Checked the new Ngs2CustomSamplerVoiceState (48 bytes, decoded sample count at offset 16), the INVALID_OUT_SIZE path for other sizes, and the ngs2_custom test (fails to build without the change, passes with it); the 9 libSceNgs2.native ctest targets pass on Linux. The debt line records what only the title establishes. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167664131 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5470#issuecomment-6167664131). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T11:49:43Z. --- Checked the new `Ngs2CustomSamplerVoiceState` (48 bytes, decoded sample count at offset 16), the `INVALID_OUT_SIZE` path for other sizes, and the `ngs2_custom` test (fails to build without the change, passes with it); the 9 libSceNgs2.native ctest targets pass on Linux. The debt line records what only the title establishes. Merging.
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
boykopovar/AnyPS5!5470
No description provided.