feat(libSceNgs2.native): implement system, racks, voices and PCM rendering #247

Merged
adriadam10 merged 1 commit from upstream-pr/247 into main 2026-10-02 07:33:54 +00:00
adriadam10 commented 2026-10-01 18:46:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-01T18:46:07Z.


What

First of three NGS2 pull requests. The implementation lives only in libSceNgs2.native; libSceNgs2 only exported NotImplemented stubs of functions that .native implements, so, as asked in #228 and #241, its Export.cpp is now APS5_DUMMY_FUN only, like libkernel_sys (no title found that imports libSceNgs2 without .native).

Implemented:

  • System: ResetOption, QueryBufferSize, Create, CreateWithAllocator, Destroy, GetInfo, SetGrainSamples, Render.
  • Racks (sampler 0x1000, submixer 0x2000, mastering 0x3000): QueryBufferSize, Create, CreateWithAllocator, Destroy, GetVoiceHandle, Lock, Unlock.
  • Voices: Control (matrix levels, port volume/matrix, patch, events, block callback, sampler setup/waveform blocks/exit loop/pitch, submixer and mastering setup, mastering output), RunCommands (event, matrix levels, port volume, port matrix), GetState (sampler, submixer), GetStateFlags.
  • Render: PCM16 sampler with linear interpolation (pitch, block repeats, block end/repeat callbacks), port/matrix mixing through submixers, mastering output as PCM16 or float.

Not implemented, these throw: ATRAC9 and other waveform types, custom/reverb racks, filters, envelopes, port delay, unknown voice params and commands. ParseWaveformData, CalcWaveformBlock, Pan* and Geom* stay NotImplemented (next pull requests).

The NGS2 types move from SceTypes.hpp to libSceNgs2.native/include/Ngs2Types.hpp with the PS5 layouts, checked with static_assert: name is 64 bytes, SystemOption has job_scheduler_options and max_voice_channels (144 bytes), RackOption 176, SystemInfo 184, VoiceState 8. sceNgs2VoiceRunCommands takes (handle, commands, size_t count).

References (behaviour, layouts and codes only, no code copied): KytyPS5 src/libs/ngs2.cpp (layouts, param ids, PS5 error codes 0x804A8010/8011/8201/8202), SharpProspero Ngs2.cs (rack ids, waveform types). shadPS4's codes (0x804A0xxx) are the PS4 numbering and differ from KytyPS5's PS5 ones, so only the four PS5 codes known from KytyPS5 are returned; other invalid arguments throw.

Tested

Linux (GCC, Release). New ngs2_render test renders known PCM and compares exact samples: block end and callback, pitch 0.5 with a repeated block, submixer with a matrix to stereo float, allocator create/destroy, error codes and system info. Full ctest: 91/91 pass. NID patching of both .prx succeeds. No title tested.

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); no silent stubs
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4708073736 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/247). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-01T18:46:07Z. --- ### What First of three NGS2 pull requests. The implementation lives only in `libSceNgs2.native`; `libSceNgs2` only exported `NotImplemented` stubs of functions that `.native` implements, so, as asked in #228 and #241, its `Export.cpp` is now `APS5_DUMMY_FUN` only, like `libkernel_sys` (no title found that imports `libSceNgs2` without `.native`). Implemented: - System: `ResetOption`, `QueryBufferSize`, `Create`, `CreateWithAllocator`, `Destroy`, `GetInfo`, `SetGrainSamples`, `Render`. - Racks (sampler `0x1000`, submixer `0x2000`, mastering `0x3000`): `QueryBufferSize`, `Create`, `CreateWithAllocator`, `Destroy`, `GetVoiceHandle`, `Lock`, `Unlock`. - Voices: `Control` (matrix levels, port volume/matrix, patch, events, block callback, sampler setup/waveform blocks/exit loop/pitch, submixer and mastering setup, mastering output), `RunCommands` (event, matrix levels, port volume, port matrix), `GetState` (sampler, submixer), `GetStateFlags`. - Render: PCM16 sampler with linear interpolation (pitch, block repeats, block end/repeat callbacks), port/matrix mixing through submixers, mastering output as PCM16 or float. Not implemented, these throw: ATRAC9 and other waveform types, custom/reverb racks, filters, envelopes, port delay, unknown voice params and commands. `ParseWaveformData`, `CalcWaveformBlock`, `Pan*` and `Geom*` stay `NotImplemented` (next pull requests). The NGS2 types move from `SceTypes.hpp` to `libSceNgs2.native/include/Ngs2Types.hpp` with the PS5 layouts, checked with `static_assert`: `name` is 64 bytes, `SystemOption` has `job_scheduler_options` and `max_voice_channels` (144 bytes), `RackOption` 176, `SystemInfo` 184, `VoiceState` 8. `sceNgs2VoiceRunCommands` takes `(handle, commands, size_t count)`. References (behaviour, layouts and codes only, no code copied): KytyPS5 `src/libs/ngs2.cpp` (layouts, param ids, PS5 error codes `0x804A8010/8011/8201/8202`), SharpProspero `Ngs2.cs` (rack ids, waveform types). shadPS4's codes (`0x804A0xxx`) are the PS4 numbering and differ from KytyPS5's PS5 ones, so only the four PS5 codes known from KytyPS5 are returned; other invalid arguments throw. ### Tested Linux (GCC, Release). New `ngs2_render` test renders known PCM and compares exact samples: block end and callback, pitch 0.5 with a repeated block, submixer with a matrix to stereo float, allocator create/destroy, error codes and system info. Full `ctest`: 91/91 pass. NID patching of both `.prx` succeeds. No title tested. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); no silent stubs - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-01 18:46:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-01T18:46:29Z.


Progress report (c00bc19 → 90295d3)

📈 System libraries: 79.5% (+1.31%, +22 implemented, -25 removed functions)

✅ 22 implemented
Library Name
libSceNgs2.native Allocate
libSceNgs2.native OnBlock
libSceNgs2.native Release
libSceNgs2.native sceNgs2RackCreate
libSceNgs2.native sceNgs2RackCreateWithAllocator
libSceNgs2.native sceNgs2RackDestroy
libSceNgs2.native sceNgs2RackGetVoiceHandle
libSceNgs2.native sceNgs2RackLock
libSceNgs2.native sceNgs2RackQueryBufferSize
libSceNgs2.native sceNgs2RackUnlock
libSceNgs2.native sceNgs2SystemCreate
libSceNgs2.native sceNgs2SystemCreateWithAllocator
libSceNgs2.native sceNgs2SystemDestroy
libSceNgs2.native sceNgs2SystemGetInfo
libSceNgs2.native sceNgs2SystemQueryBufferSize
libSceNgs2.native sceNgs2SystemRender
libSceNgs2.native sceNgs2SystemResetOption
libSceNgs2.native sceNgs2SystemSetGrainSamples
libSceNgs2.native sceNgs2VoiceControl
libSceNgs2.native sceNgs2VoiceGetState
libSceNgs2.native sceNgs2VoiceGetStateFlags
libSceNgs2.native sceNgs2VoiceRunCommands
🗑️ 25 removed
Library Name
libSceNgs2 sceNgs2CalcWaveformBlock
libSceNgs2 sceNgs2GeomApply
libSceNgs2 sceNgs2GeomCalcListener
libSceNgs2 sceNgs2GeomResetListenerParam
libSceNgs2 sceNgs2GeomResetSourceParam
libSceNgs2 sceNgs2PanGetVolumeMatrix
libSceNgs2 sceNgs2PanInit
libSceNgs2 sceNgs2ParseWaveformData
libSceNgs2 sceNgs2RackCreate
libSceNgs2 sceNgs2RackCreateWithAllocator
libSceNgs2 sceNgs2RackDestroy
libSceNgs2 sceNgs2RackGetVoiceHandle
libSceNgs2 sceNgs2RackLock
libSceNgs2 sceNgs2RackQueryBufferSize
libSceNgs2 sceNgs2RackUnlock
libSceNgs2 sceNgs2SystemCreate
libSceNgs2 sceNgs2SystemCreateWithAllocator
libSceNgs2 sceNgs2SystemDestroy
libSceNgs2 sceNgs2SystemGetInfo
libSceNgs2 sceNgs2SystemQueryBufferSize
libSceNgs2 sceNgs2SystemRender
libSceNgs2 sceNgs2SystemSetGrainSamples
libSceNgs2 sceNgs2VoiceControl
libSceNgs2 sceNgs2VoiceGetState
libSceNgs2 sceNgs2VoiceGetStateFlags
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5938238179 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/247#issuecomment-5938238179). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-01T18:46:29Z. --- <!-- progress-report --> ### Progress report (c00bc19 → 90295d3) 📈 **System libraries**: 79.5% (+1.31%, +22 implemented, -25 removed functions) <details> <summary>✅ 22 implemented</summary> | Library | Name | | - | - | | libSceNgs2.native | `Allocate` | | libSceNgs2.native | `OnBlock` | | libSceNgs2.native | `Release` | | libSceNgs2.native | `sceNgs2RackCreate` | | libSceNgs2.native | `sceNgs2RackCreateWithAllocator` | | libSceNgs2.native | `sceNgs2RackDestroy` | | libSceNgs2.native | `sceNgs2RackGetVoiceHandle` | | libSceNgs2.native | `sceNgs2RackLock` | | libSceNgs2.native | `sceNgs2RackQueryBufferSize` | | libSceNgs2.native | `sceNgs2RackUnlock` | | libSceNgs2.native | `sceNgs2SystemCreate` | | libSceNgs2.native | `sceNgs2SystemCreateWithAllocator` | | libSceNgs2.native | `sceNgs2SystemDestroy` | | libSceNgs2.native | `sceNgs2SystemGetInfo` | | libSceNgs2.native | `sceNgs2SystemQueryBufferSize` | | libSceNgs2.native | `sceNgs2SystemRender` | | libSceNgs2.native | `sceNgs2SystemResetOption` | | libSceNgs2.native | `sceNgs2SystemSetGrainSamples` | | libSceNgs2.native | `sceNgs2VoiceControl` | | libSceNgs2.native | `sceNgs2VoiceGetState` | | libSceNgs2.native | `sceNgs2VoiceGetStateFlags` | | libSceNgs2.native | `sceNgs2VoiceRunCommands` | </details> <details> <summary>🗑️ 25 removed</summary> | Library | Name | | - | - | | libSceNgs2 | `sceNgs2CalcWaveformBlock` | | libSceNgs2 | `sceNgs2GeomApply` | | libSceNgs2 | `sceNgs2GeomCalcListener` | | libSceNgs2 | `sceNgs2GeomResetListenerParam` | | libSceNgs2 | `sceNgs2GeomResetSourceParam` | | libSceNgs2 | `sceNgs2PanGetVolumeMatrix` | | libSceNgs2 | `sceNgs2PanInit` | | libSceNgs2 | `sceNgs2ParseWaveformData` | | libSceNgs2 | `sceNgs2RackCreate` | | libSceNgs2 | `sceNgs2RackCreateWithAllocator` | | libSceNgs2 | `sceNgs2RackDestroy` | | libSceNgs2 | `sceNgs2RackGetVoiceHandle` | | libSceNgs2 | `sceNgs2RackLock` | | libSceNgs2 | `sceNgs2RackQueryBufferSize` | | libSceNgs2 | `sceNgs2RackUnlock` | | libSceNgs2 | `sceNgs2SystemCreate` | | libSceNgs2 | `sceNgs2SystemCreateWithAllocator` | | libSceNgs2 | `sceNgs2SystemDestroy` | | libSceNgs2 | `sceNgs2SystemGetInfo` | | libSceNgs2 | `sceNgs2SystemQueryBufferSize` | | libSceNgs2 | `sceNgs2SystemRender` | | libSceNgs2 | `sceNgs2SystemSetGrainSamples` | | libSceNgs2 | `sceNgs2VoiceControl` | | libSceNgs2 | `sceNgs2VoiceGetState` | | libSceNgs2 | `sceNgs2VoiceGetStateFlags` | </details>
boykopovar commented 2026-10-01 20:58:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-01T20:58:33Z.


As I understand it, libSceNgs2 is currently a complete copy of libSceNgs2.native? Unless this is caused by a game being found that imports libSceNgs2 but doesn't import libSceNgs2.native, there's no need to duplicate it; you can simply leave libSceNgs2 empty.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5940410375 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/247#issuecomment-5940410375). Originally posted by [boykopovar](https://github.com/boykopovar) on 2026-10-01T20:58:33Z. --- As I understand it, libSceNgs2 is currently a complete copy of libSceNgs2.native? Unless this is caused by a game being found that imports libSceNgs2 but doesn't import libSceNgs2.native, there's no need to duplicate it; you can simply leave libSceNgs2 empty.
adriadam10 commented 2026-10-02 04:22:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T04:22:09Z.


Right, no title needed it. Moved: the implementation now lives only in libSceNgs2.native; libSceNgs2 is back to its stubs (its only change is including the NGS2 types header from .native, since the types left SceTypes.hpp). #248 is rebased the same way.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5945553920 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/247#issuecomment-5945553920). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T04:22:09Z. --- Right, no title needed it. Moved: the implementation now lives only in `libSceNgs2.native`; `libSceNgs2` is back to its stubs (its only change is including the NGS2 types header from `.native`, since the types left `SceTypes.hpp`). #248 is rebased the same way.
adriadam10 commented 2026-10-02 07:25:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T07:25:19Z.


Following the review on #228/#241: libSceNgs2/Export.cpp is now APS5_DUMMY_FUN only, like libkernel_sys. All 25 of its stubs are exported by libSceNgs2.native. Rebased on main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5947342731 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/247#issuecomment-5947342731). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T07:25:19Z. --- Following the review on #228/#241: `libSceNgs2/Export.cpp` is now `APS5_DUMMY_FUN` only, like `libkernel_sys`. All 25 of its stubs are exported by `libSceNgs2.native`. Rebased on `main`.
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!247
No description provided.