feat(libSceNgs2.native): implement sceNgs2PanInit and sceNgs2PanGetVolumeMatrix #959

Merged
JAB-dev merged 4 commits from upstream-pr/959 into main 2026-10-10 05:53:48 +00:00
JAB-dev commented 2026-10-06 20:25:11 +00:00 (Migrated from github.com)

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


This PR depends on #964 for the default channel map, so its diff includes #964.

What

Both functions threw NotImplemented. They now pan as the console library does.

  • SceNgs2PanParam (16 bytes: angle, distance, full-band level, LFE level) and SceNgs2PanWork (40 bytes: up to 8 speaker angles, unit angle, speaker count) replace the reserved arrays. The layouts are from SharpProspero and match the PS4 library.
  • sceNgs2PanInit(work, angles, unit_angle, num_speakers) takes 2, 4, 5 or 7 speakers:
    • The speakers are given in the order L R, L R Ls Rs, L R C Ls Rs or L R C Ls Rs Lb Rb. They are kept in a fixed circular order, not sorted, plus a wrap-around entry one full turn after the first.
    • The unit angle is 360 or 2π. With null angles any other value means 360; with explicit angles it throws.
    • With null angles the defaults are 90/270, 40/110/250/320, 0/40/110/250/320 and 0/40/110/150/210/250/320 degrees. For a 2π unit they are converted to radians, except the wrap-around entry, which stays in degrees as in the PS4 library.
  • sceNgs2PanGetVolumeMatrix(work, params, num_params, format, out) writes the matrix for formats 1, 2, 6 and 8, laid out by destination channel (out[channel * num_params + param]), for up to 8 params:
    • each angle pans with a sine law between the two neighbouring speakers;
    • a distance below 1 blends in the opposite direction;
    • full-band levels are scaled by fbw_level, and lfe_level goes to the LFE channel;
    • when the format differs from the speaker layout, the levels fold through the default channel map from #964;
    • num_params 0 returns at once and a null output returns INVALID_OUT_ADDRESS, as in the PS4 library.
  • The PS5 error codes aren't known, so the other invalid arguments throw. That includes a speaker angle equal to the unit angle, on which the PS4 library loops forever, and angles so large that a turn no longer changes them, for the same reason. Every param is checked before the matrix is written.

TechnicalDebt records the details and the PS4 source.

Reference

  • PS4 firmware 11.00 libSceNgs2.sprx, dumped and decrypted from a console. It was loaded on Windows with a small test loader and called directly; neither the loader nor the library is part of this PR. The panning code was read from its disassembly, and the test values are its own 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 TestPan uses 15 cases with the PS4 library's output, to 1e-6:

    • the default layouts in degrees and radians;
    • a full turn on two speakers;
    • distance below and above 1;
    • each layout into 1, 2, 6 and 8 channels with the LFE level;
    • custom 5- and 7-speaker angles;
    • angles past a full turn.

    It also checks the init layout, the wrap-around entry and the throws: unknown formats, 9 params, NaN, null work or params, 0, 1, 3, 6 or 8 speakers, a speaker angle equal to the unit angle, angles of ±1e30 and an infinite speaker angle in the work, and a work whose unit angle was overwritten. A NaN in the second param leaves the output untouched.

  • A separate fuzz run compared this implementation with the PS4 library on 200,000 random cases. All matched bit for bit.

  • On main the test fails, because both functions throw NotImplemented. Sixteen mutations of Pan.cpp each make the test fail.

  • Full ctest merged with main d70b8998, together with #964, #2336 and #2337: 507/507.

  • Seen in PPSA22520 (Animal Well): sceNgs2PanInit(work, NULL, 360, 2), then one sceNgs2PanGetVolumeMatrix(work, &param, 1, 2, out) per sound with angle = fmodf(pan * 180 + 270, 360) and distance 1. Its positional sounds pan by ear.

  • 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: #964
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4764242204 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/959). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-06T20:25:11Z. --- > This PR depends on #964 for the default channel map, so its diff includes #964. ### What Both functions threw `NotImplemented`. They now pan as the console library does. - `SceNgs2PanParam` (16 bytes: angle, distance, full-band level, LFE level) and `SceNgs2PanWork` (40 bytes: up to 8 speaker angles, unit angle, speaker count) replace the reserved arrays. The layouts are from SharpProspero and match the PS4 library. - `sceNgs2PanInit(work, angles, unit_angle, num_speakers)` takes 2, 4, 5 or 7 speakers: - The speakers are given in the order L R, L R Ls Rs, L R C Ls Rs or L R C Ls Rs Lb Rb. They are kept in a fixed circular order, not sorted, plus a wrap-around entry one full turn after the first. - The unit angle is 360 or 2π. With null angles any other value means 360; with explicit angles it throws. - With null angles the defaults are 90/270, 40/110/250/320, 0/40/110/250/320 and 0/40/110/150/210/250/320 degrees. For a 2π unit they are converted to radians, except the wrap-around entry, which stays in degrees as in the PS4 library. - `sceNgs2PanGetVolumeMatrix(work, params, num_params, format, out)` writes the matrix for formats 1, 2, 6 and 8, laid out by destination channel (`out[channel * num_params + param]`), for up to 8 params: - each angle pans with a sine law between the two neighbouring speakers; - a distance below 1 blends in the opposite direction; - full-band levels are scaled by `fbw_level`, and `lfe_level` goes to the LFE channel; - when the format differs from the speaker layout, the levels fold through the default channel map from #964; - `num_params` 0 returns at once and a null output returns `INVALID_OUT_ADDRESS`, as in the PS4 library. - The PS5 error codes aren't known, so the other invalid arguments throw. That includes a speaker angle equal to the unit angle, on which the PS4 library loops forever, and angles so large that a turn no longer changes them, for the same reason. Every param is checked before the matrix is written. TechnicalDebt records the details and the PS4 source. ### Reference - **PS4 firmware 11.00 `libSceNgs2.sprx`**, dumped and decrypted from a console. It was loaded on Windows with a small test loader and called directly; neither the loader nor the library is part of this PR. The panning code was read from its disassembly, and the test values are its own 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` `TestPan` uses 15 cases with the PS4 library's output, to 1e-6: - the default layouts in degrees and radians; - a full turn on two speakers; - distance below and above 1; - each layout into 1, 2, 6 and 8 channels with the LFE level; - custom 5- and 7-speaker angles; - angles past a full turn. It also checks the init layout, the wrap-around entry and the throws: unknown formats, 9 params, NaN, null work or params, 0, 1, 3, 6 or 8 speakers, a speaker angle equal to the unit angle, angles of ±1e30 and an infinite speaker angle in the work, and a work whose unit angle was overwritten. A NaN in the second param leaves the output untouched. - A separate fuzz run compared this implementation with the PS4 library on 200,000 random cases. All matched bit for bit. - On `main` the test fails, because both functions throw `NotImplemented`. Sixteen mutations of `Pan.cpp` each make the test fail. - Full ctest merged with `main` d70b8998, together with #964, #2336 and #2337: 507/507. - Seen in PPSA22520 (Animal Well): `sceNgs2PanInit(work, NULL, 360, 2)`, then one `sceNgs2PanGetVolumeMatrix(work, &param, 1, 2, out)` per sound with `angle = fmodf(pan * 180 + 270, 360)` and distance 1. Its positional sounds pan by ear. - 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: #964 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
JAB-dev commented 2026-10-06 21:28:47 +00:00 (Migrated from github.com)

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


Converted to draft: the panning itself (equal power between the two neighbouring speakers, rear angles mirrored to the front for two speakers) is assumed, not taken from the console, 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:6025794300 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/959#issuecomment-6025794300). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-06T21:28:47Z. --- Converted to draft: the panning itself (equal power between the two neighbouring speakers, rear angles mirrored to the front for two speakers) is assumed, not taken from the console, 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.
github-actions[bot] commented 2026-10-07 05:17:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T05:17:17Z.


Progress report (7331a12 → 00e13ec)

📈 System libraries: 85.55% (+0.06%, +2 implemented functions)

✅ 2 implemented
Library Name
libSceNgs2.native sceNgs2PanGetVolumeMatrix
libSceNgs2.native sceNgs2PanInit
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6031474845 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/959#issuecomment-6031474845). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T05:17:17Z. --- <!-- progress-report --> ### Progress report (7331a12 → 00e13ec) 📈 **System libraries**: 85.55% (+0.06%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libSceNgs2.native | `sceNgs2PanGetVolumeMatrix` | | libSceNgs2.native | `sceNgs2PanInit` | </details>
adriadam10 commented 2026-10-10 00:19:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T00:19:56Z.


Checked build + ctest on Linux for libSceNgs2.native (7/7, ngs2_render passes; without the change the test doesn't compile), conventions and TechnicalDebt placement; no problems found in the code.

@oneandonlydean this PR carries #964 as its first three commits, and you asked for #964 to go first so you can run the full build on it. Merging this one now would land #964 untested on your side. Could you merge #964 and then this one, in that order? Once #964 is on main this is a single commit and nothing else needs changing.

Not verified here: the PS4 11.00 library values (the author's own dump; KytyPS5/shadPS4 only give the signature), the match with the PS5 library, and real titles.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091526920 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/959#issuecomment-6091526920). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T00:19:56Z. --- Checked build + ctest on Linux for `libSceNgs2.native` (7/7, `ngs2_render` passes; without the change the test doesn't compile), conventions and TechnicalDebt placement; no problems found in the code. @oneandonlydean this PR carries #964 as its first three commits, and you asked for #964 to go first so you can run the full build on it. Merging this one now would land #964 untested on your side. Could you merge #964 and then this one, in that order? Once #964 is on `main` this is a single commit and nothing else needs changing. Not verified here: the PS4 11.00 library values (the author's own dump; KytyPS5/shadPS4 only give the signature), the match with the PS5 library, and real titles.
github-actions[bot] commented 2026-10-10 05:42:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T05:42:35Z.


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
#2561 sceNgs2PanGetVolumeMatrix
sceNgs2PanInit
core/libs/prx/libSceNgs2.native/src/Pan.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094311098 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/959#issuecomment-6094311098). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T05:42:35Z. --- <!-- 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 | |---|---|---|---| | #2561 | | `sceNgs2PanGetVolumeMatrix`<br>`sceNgs2PanInit` | `core/libs/prx/libSceNgs2.native/src/Pan.cpp` |
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!959
No description provided.