fix(libSceNgs2.native): clamp matrix levels to -4..4 as the PS4 libSceNgs2 does #2337

Merged
JAB-dev merged 2 commits from upstream-pr/2337 into main 2026-10-09 21:44:25 +00:00
JAB-dev commented 2026-10-09 15:49:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-09T15:49:05Z.


What

SCE_NGS2_VOICE_PARAM_MATRIX_LEVELS and the matrix levels command of sceNgs2VoiceRunCommands stored levels as given. Now:

  • levels are clamped to -4..4, so a level of 8 no longer plays twice as loud as on the console; NaN is kept, as the library keeps it;
  • a level count of 0 throws instead of emptying the matrix. The library rejects that count and keeps the matrix, but its PS5 error code is unknown.

TechnicalDebt records that this comes from the PS4 library.

Reference

  • PS4 firmware 11.00 libSceNgs2.sprx, dumped and decrypted from a console. It was loaded on Windows with a small test loader and driven through sceNgs2VoiceControl; neither the loader nor the library is part of this PR. In-range, out-of-range, infinite and NaN levels were set and read back from its rendered output, and a count of 0 was rejected with the matrix unchanged.
  • sceNgs2VoiceRunCommands is not in the PS4 library, so its matrix levels command is assumed to clamp the same way.
  • PS5 firmware 10.06 libSceNgs2.sprx: its readable ELF headers match the PS4 library (3,460-byte .eh_frame_hdr, 431 functions). A decrypted PS5 SELF was not used; anyone with a decrypted PS5 libSceNgs2.sprx can help confirm this.

Tested

  • Windows 11, WinLibs GCC 15.2.0 r7, Release.
  • ngs2_render TestMatrixLevelClamp renders a mono sampler through matrix 0, set both by voice param and by command: ±4, 4.0001, -4.5, ±100 and ±infinity render as ±4 would, 3.5 and -0.25 pass unchanged, NaN stays NaN, and a count of 0 throws.
  • With main's Voice.cpp the test fails. Four mutations each make it fail: no clamp, no upper bound, a bound of 8, and accepting a count of 0.
  • Full ctest merged with main d70b8998, together with #959, #964 and #2336: 507/507.
  • #964 treats an empty matrix as unset. With this PR a count of 0 can no longer empty a matrix.
  • Linux not 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); 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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4802707469 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2337). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-09T15:49:05Z. --- ### What `SCE_NGS2_VOICE_PARAM_MATRIX_LEVELS` and the matrix levels command of `sceNgs2VoiceRunCommands` stored levels as given. Now: - levels are clamped to -4..4, so a level of 8 no longer plays twice as loud as on the console; NaN is kept, as the library keeps it; - a level count of 0 throws instead of emptying the matrix. The library rejects that count and keeps the matrix, but its PS5 error code is unknown. TechnicalDebt records that this comes from the PS4 library. ### Reference - **PS4 firmware 11.00 `libSceNgs2.sprx`**, dumped and decrypted from a console. It was loaded on Windows with a small test loader and driven through `sceNgs2VoiceControl`; neither the loader nor the library is part of this PR. In-range, out-of-range, infinite and NaN levels were set and read back from its rendered output, and a count of 0 was rejected with the matrix unchanged. - `sceNgs2VoiceRunCommands` is not in the PS4 library, so its matrix levels command is assumed to clamp the same way. - **PS5 firmware 10.06 `libSceNgs2.sprx`**: its readable ELF headers match the PS4 library (3,460-byte `.eh_frame_hdr`, 431 functions). A decrypted PS5 SELF was not used; anyone with a decrypted PS5 `libSceNgs2.sprx` can help confirm this. ### Tested - Windows 11, WinLibs GCC 15.2.0 r7, Release. - `ngs2_render` `TestMatrixLevelClamp` renders a mono sampler through matrix 0, set both by voice param and by command: ±4, 4.0001, -4.5, ±100 and ±infinity render as ±4 would, 3.5 and -0.25 pass unchanged, NaN stays NaN, and a count of 0 throws. - With `main`'s `Voice.cpp` the test fails. Four mutations each make it fail: no clamp, no upper bound, a bound of 8, and accepting a count of 0. - Full ctest merged with `main` d70b8998, together with #959, #964 and #2336: 507/507. - #964 treats an empty matrix as unset. With this PR a count of 0 can no longer empty a matrix. - Linux not 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Kikoarl commented 2026-10-09 17:52:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T17:52:47Z.


Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at 255ed1de:

  • Build: Built cleanly in RAM (/tmp/anyps5_build) with zero warnings/errors.
  • Conventions: python3 tools/check_conventions.py --base origin/main --head HEAD -> PASS (0 errors).
  • Verification: Verified matrix level clamping [-4.0, 4.0] in Voice.cpp and ngs2_render tests. Matches hardware and PS4 libSceNgs2 specifications.

LGTM!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6086306856 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2337#issuecomment-6086306856). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-09T17:52:47Z. --- Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at `255ed1de`: - **Build**: Built cleanly in RAM (`/tmp/anyps5_build`) with zero warnings/errors. - **Conventions**: `python3 tools/check_conventions.py --base origin/main --head HEAD` -> **PASS (0 errors)**. - **Verification**: Verified matrix level clamping [-4.0, 4.0] in `Voice.cpp` and `ngs2_render` tests. Matches hardware and PS4 libSceNgs2 specifications. LGTM!
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!2337
No description provided.