fix(libSceNgs2.native): mix ports without set levels through the default channel map #964

Merged
JAB-dev merged 3 commits from upstream-pr/964 into main 2026-10-10 05:36:03 +00:00
JAB-dev commented 2026-10-06 20:25:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-06T20:25:28Z.


What

A port without a matrix sent source channel n to destination channel n, so a mono voice reached only the left channel of a stereo mix. A port that selects a voice matrix (SCE_NGS2_VOICE_PARAM_PORT_MATRIX, or command 7 of sceNgs2VoiceRunCommands) whose levels were never set mixed nothing at all, at any port volume.

Both now mix through the console's default channel map:

  • mono reaches both stereo channels at -3 dB and the centre of 5.1 and 7.1;
  • stereo folds to mono at -3 dB per side and passes through to stereo, 5.1 and 7.1 unchanged;
  • wider sources fold down with 0.5 and -3 dB gains;
  • the map covers every source width from 1 to 8 channels into 1, 2, 6 and 8 channels;
  • a selected matrix whose levels were never set mixes exactly like no matrix;
  • matrices with levels are unchanged, including a partly set matrix, which still mixes only the rows it has. A level count of 0 still empties the matrix, which then reads as unset; the library rejects that count, and #2337 makes it throw;
  • into 3, 4, 5 or 7 channels the map throws. The library rejects submixer and mastering voices of those widths, so it has no map for them.

TechnicalDebt records that the map 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 its exports; neither the loader nor the library is part of this PR. One sampler voice per source channel was rendered through a submixer into 1, 2, 6 and 8 channel mastering voices, with no matrix and with an unset matrix, and the levels were read from its output. The test values are its results.
  • PS5 firmware 10.06 libSceNgs2.sprx (the module titles import as libSceNgs2): its readable ELF headers match the PS4 library: the same .eh_frame_hdr size (3,460 bytes, 431 functions) and code plus read-only data within 1% (321,328 bytes against 323,432). 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 TestDefaultChannelMap:
    • 26 source channel to destination combinations from 1 to 8 source channels, with the PS4 library's levels;
    • a 4-channel submixer throws, and the system is destroyed after it.
  • ngs2_render TestUnsetMatrix, selecting matrix 0 without levels:
    • a mono source at port volume 0.5 renders 0.25 at -3 dB on both channels;
    • a stereo source renders its two channels unchanged.
  • With main's Render.cpp both tests fail. Six mutations each make them fail.
  • Full ctest merged with main d70b8998, together with #959, #2336 and #2337: 507/507.
  • Seen in PPSA22520 (Animal Well): the title music is a stereo sampler patched to a stereo submixer. The title selects matrix 0 with command 7 and never sets its levels, so on main the title screen is silent. With this change the music fades in and plays.
  • 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:4764245063 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/964). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-06T20:25:28Z. --- ### What A port without a matrix sent source channel n to destination channel n, so a mono voice reached only the left channel of a stereo mix. A port that selects a voice matrix (`SCE_NGS2_VOICE_PARAM_PORT_MATRIX`, or command 7 of `sceNgs2VoiceRunCommands`) whose levels were never set mixed nothing at all, at any port volume. Both now mix through the console's default channel map: - mono reaches both stereo channels at -3 dB and the centre of 5.1 and 7.1; - stereo folds to mono at -3 dB per side and passes through to stereo, 5.1 and 7.1 unchanged; - wider sources fold down with 0.5 and -3 dB gains; - the map covers every source width from 1 to 8 channels into 1, 2, 6 and 8 channels; - a selected matrix whose levels were never set mixes exactly like no matrix; - matrices with levels are unchanged, including a partly set matrix, which still mixes only the rows it has. A level count of 0 still empties the matrix, which then reads as unset; the library rejects that count, and #2337 makes it throw; - into 3, 4, 5 or 7 channels the map throws. The library rejects submixer and mastering voices of those widths, so it has no map for them. TechnicalDebt records that the map 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 its exports; neither the loader nor the library is part of this PR. One sampler voice per source channel was rendered through a submixer into 1, 2, 6 and 8 channel mastering voices, with no matrix and with an unset matrix, and the levels were read from its output. The test values are its results. - **PS5 firmware 10.06 `libSceNgs2.sprx`** (the module titles import as `libSceNgs2`): its readable ELF headers match the PS4 library: the same `.eh_frame_hdr` size (3,460 bytes, 431 functions) and code plus read-only data within 1% (321,328 bytes against 323,432). 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` `TestDefaultChannelMap`: - 26 source channel to destination combinations from 1 to 8 source channels, with the PS4 library's levels; - a 4-channel submixer throws, and the system is destroyed after it. - `ngs2_render` `TestUnsetMatrix`, selecting matrix 0 without levels: - a mono source at port volume 0.5 renders 0.25 at -3 dB on both channels; - a stereo source renders its two channels unchanged. - With `main`'s `Render.cpp` both tests fail. Six mutations each make them fail. - Full ctest merged with `main` d70b8998, together with #959, #2336 and #2337: 507/507. - Seen in PPSA22520 (Animal Well): the title music is a stereo sampler patched to a stereo submixer. The title selects matrix 0 with command 7 and never sets its levels, so on `main` the title screen is silent. With this change the music fades in and plays. - 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)
JAB-dev commented 2026-10-06 21:28:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-06T21:28:50Z.


Converted to draft: the console's initial matrix levels are unknown, and this assumes an unset matrix is not silent, which is the same gap as #960. I'm checking it against the output of the console's own NGS2 library and will mark it ready with that.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6025795083 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/964#issuecomment-6025795083). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-06T21:28:50Z. --- Converted to draft: the console's initial matrix levels are unknown, and this assumes an unset matrix is not silent, which is the same gap as #960. I'm checking it against the output of the console's own NGS2 library and will mark it ready with that.
oneandonlydean commented 2026-10-09 20:14:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:14:25Z.


Please rebase this onto main without the merge commits, and #959 on top of it the same way. Then I'll run the full build and merge this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088505998 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/964#issuecomment-6088505998). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:14:25Z. --- Please rebase this onto main without the merge commits, and #959 on top of it the same way. Then I'll run the full build and merge this one.
JAB-dev commented 2026-10-09 21:56:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-09T21:56:55Z.


Done, both rebased onto main with no merge commits. #964 is now 3 commits (I dropped the old test-buffer bump since main's growing pool replaced it), and #959 is a single commit on top of it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089926950 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/964#issuecomment-6089926950). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-09T21:56:55Z. --- Done, both rebased onto main with no merge commits. #964 is now 3 commits (I dropped the old test-buffer bump since main's growing pool replaced it), and #959 is a single commit on top of it.
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!964
No description provided.