Skip to content

feat(libSceNgs2): add custom sampler and custom mastering racks - #3793

Closed
Techx3 wants to merge 1 commit into
boykopovar:mainfrom
Techx3:ngs2-custom-sampler-mastering
Closed

Techx3 wants to merge 1 commit into
boykopovar:mainfrom
Techx3:ngs2-custom-sampler-mastering

Conversation

@Techx3

@Techx3 Techx3 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Add the custom sampler (0x4001) and custom mastering (0x4003) racks on top of the custom submixer support:

  • Ngs2CustomSamplerRackOption (1304 bytes) and Ngs2CustomMasteringRackOption (1288 bytes), with their voice states (48 and 16 bytes).
  • The racks render as the sampler / mastering rack they are built on and run their UserFx2 modules like the custom submixer.
  • Custom sampler params are the sampler params under the custom rack id; the custom mastering setup param 0x40030000 sets the channel count.
  • Built-in (non-UserFx2) modules are accepted on these two racks but not run individually; their controls are ignored and logged once. The custom submixer keeps rejecting them. Recorded in docs/dev/TechnicalDebt.md.

Seen on PPSA15552 (Dead Cells), which creates both racks at start-up. (It also patches voices to a rack handle, which still fails and is not part of this change.)
Tests cover both racks in tests/Ngs2Custom.cpp.

Claude-Session: https://claude.ai/code/session_017Dqgm9nUKygsXzr6poJsHJ

What

Adds the NGS2 custom sampler (0x4001) and custom mastering (0x4003) racks next to the existing custom submixer:

  • Ngs2CustomSamplerRackOption (1304 bytes) and Ngs2CustomMasteringRackOption (1288 bytes), and their voice states Ngs2CustomSamplerVoiceState (48) and Ngs2CustomMasteringVoiceState (16); the sizes are checked with static_assert. Layouts follow KytyPS5, where the same title runs.
  • The racks render like the sampler / mastering rack they are built on and run their UserFx2 modules like the custom submixer.
  • Custom sampler params are the sampler params under the custom rack id (0x4001xxxx); the custom mastering setup param 0x40030000 sets the channel count with the custom submixer setup layout.
  • Built-in (non-UserFx2) modules are accepted on these two racks but not run one by one: the rack's own sampler or mastering processing stands for the chain, and their controls (0x4000xxxx outside UserFx2) are ignored and logged once. The custom submixer keeps rejecting them. Recorded in TechnicalDebt.

Tested

  • Linux (GCC 13): ngs2_custom, ngs2_render, ngs2_core_render, ngs2_atrac9, ngs2_filter, ngs2_parse, ngs2_stream and ngs2_userfx pass. New cases in tests/Ngs2Custom.cpp cover both racks (sampler playback with a UserFx2 gain and a built-in module, custom mastering output, voice states).
  • Windows 11, PPSA15552 (Dead Cells): on current main it stops at NGS2: rack id 0x4001 is not implemented; with this change it creates both racks (built-in module 0x13 in the custom sampler) and continues. The title then patches voices to a rack handle, which is not part of this PR.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes (Claude)

Add the custom sampler (0x4001) and custom mastering (0x4003) racks on top of
the custom submixer support:

- Ngs2CustomSamplerRackOption (1304 bytes) and Ngs2CustomMasteringRackOption
  (1288 bytes), with their voice states (48 and 16 bytes).
- The racks render as the sampler / mastering rack they are built on and run
  their UserFx2 modules like the custom submixer.
- Custom sampler params are the sampler params under the custom rack id;
  the custom mastering setup param 0x40030000 sets the channel count.
- Built-in (non-UserFx2) modules are accepted on these two racks but not run
  individually; their controls are ignored and logged once. The custom
  submixer keeps rejecting them. Recorded in docs/dev/TechnicalDebt.md.

Seen on PPSA15552 (Dead Cells), which creates both racks at start-up. (It also
patches voices to a rack handle, which still fails and is not part of this
change.)
Tests cover both racks in tests/Ngs2Custom.cpp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Dqgm9nUKygsXzr6poJsHJ

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the layouts match KytyPS5 (Ngs2CustomSamplerRackOption 1304, Ngs2CustomMasteringRackOption 1288, voice states 48/16) and ngs2_custom plus the other Ngs2 tests pass here. A few things before this can merge:

  • Custom.cpp:23-30, Custom.cpp:112-120: built-in modules are accepted, skipped and only logged to stderr. That returns plausible-but-wrong audio where main threw. Please either throw for any built-in module whose behaviour isn't implemented, or show (a test, or a log from the title) that skipping module 0x13 is exact for what the title does with it and limit the skip to exactly that id/controls.
  • tests/Ngs2Custom.cpp:256-257, :275, :294-295: the project doesn't allow code comments (CONTRIBUTING); please remove them.
  • docs/dev/TechnicalDebt.md:241: KytyPS5 doesn't read the 0x40030000 setup param at all (it only checks the rack type), so "as KytyPS5 handles them" is wrong for the mastering setup layout. Please say the custom-submixer layout is an assumption. Since the skip changes behaviour, the line also belongs under "### Functional", not "### Unknown function info".

@xXPBSXx

xXPBSXx commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Windows data point for Dead Cells (PPSA15552) with this PR: Windows 10, MinGW/Ninja Release build of the PR head on top of main a11c8f7, relinked from the reconstructed ELF (1 module, 0 absent imports), 60 s run. ctest -R ngs2_custom passes. The title creates its custom sampler rack and then aborts on the next missing call:

what():  sceNgs2GeomResetSourceParam not implemented
FATAL: abort() (SIGABRT)

So on this machine it gets past the rack id and does not reach the voice patch to a rack handle mentioned in the description; the Geom call comes first.

The option block I captured with a local trace before this PR (not committed) agrees with the layout here: rack id 0x4001, option size = 0x518 (1304), name "Default", max_voices = 256, max_ports = 8, max_matrices = 1, state_size = 48, num_buffers = 1, num_modules = 1, and that module has module_id = 0x13, option = nullptr, state_size = 0; the title creates this rack twice. I had a smaller branch for the same rack (xXPBSXx:fix/ngs2-custom-sampler-rack, 58c902fe2: only the rack creation and a test, no voices or rendering). This PR covers it, so I am not opening mine.

What I did not check: audio, the mastering rack, Linux.

AI-assisted (Claude Code).

@hansjm10

Copy link
Copy Markdown
Contributor

Linux matches @xXPBSXx's data (Debian 12, GCC 14, RADV gfx1036 and llvmpipe, main a11c8f7): the same 1304-byte option with the single module 0x13 (no option, no state), sampler limits 256 / 16 / 256 / 256 / 0 / 32, and with a 0x4001 rack the next stop is sceNgs2GeomResetSourceParam not implemented.

Two points for review:

  • Built-in modules: in this title the only built-in module is 0x13, so 0x4001 doesn't need the accept-and-ignore path here. Accepting exactly 0x13 and throwing for other built-in ids and their 0x4000xxxx controls covers PPSA15552 and keeps "exact behaviour or a throw". I have that variant locally (rack creation only, with a test that fails on main); I'm not opening it.
  • Geom and later stops: the next stop is the Geom family from feat(libSceNgs2): implement the Geom family #1021 and feat(ngs2): implement geometry parameter resets #1875, both closed because no title reached them. With feat(libSceNgs2): implement the Geom family #1021 applied locally, the title ran for about 120 s. It sent no 0x4001xxxx voice parameters and made no sceNgs2VoiceGetState call on this rack's voices. It never requested rack 0x4003 either; that build had no 0x4003 and would have thrown. It then stopped on an unrelated shader limit of this GPU (Barycentric geometry SPIR-V: the emulated barycentric inputs exceed 32 locations). So the voice side and the mastering rack are not exercised on Linux yet.

AI-assisted: yes (Claude Code).

@MarcZX10

Copy link
Copy Markdown
Contributor

I reviewed the ready branch for #3759 against this PR and current main. It overlaps the custom sampler implementation here, so I have not opened a parallel PR.

The useful difference is the built-in module case from Dead Cells: the candidate accepts and skips module 0x13 only on the custom sampler/mastering racks (custom submixer still throws), logs the unimplemented module/control once, keeps the UserFx2 module processing, and has a test that verifies sampler output and UserFx2 gain while a 0x13 module/control is present. This is aimed at the review request to either throw for unsupported built-ins or demonstrate and limit the skip for the title's 0x13 module. It also adds rejection tests for loop/filter/other unsupported parameters, buffer-count bounds, and checks custom sampler voice state.

I rebased the original one-commit branch onto current upstream/main; aside from the TechnicalDebt append it applied unchanged and preserves screamm as commit author. Linux Release validation on GCC 12: all nine ngs2_* CTests pass, including ngs2_custom; conventions and git diff --check pass. The full issue report attributes the rack layout to KytyPS5 and shadPS4, but the sampler behavior itself is still not console-verified.

If this follow-up is useful, the branch is MarcZX100:codex/carry-ngs2-custom-sampler-3759 (commit 99ff1fa6b). It is currently not pushed.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing in favour of #4417: the points from 10-11 are still open (built-in modules accepted and skipped, 0x40001300 ignored), and #4417 implements module 0x13 instead of skipping it. No title requests rack 0x4003 yet. Thanks, the run in #4334 on this branch is what showed the remaining stops. If you decide to continue, please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants