feat(libSceNgs2.native): reverb rack following the PS4 libSceNgs2 reverb #2336

Merged
JAB-dev merged 5 commits from upstream-pr/2336 into main 2026-10-09 21:59:55 +00:00
JAB-dev commented 2026-10-09 15:49:02 +00:00 (Migrated from github.com)

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


Replaces #960, which was closed pending a reference. The reverb now follows the PS4 firmware 11.00 libSceNgs2.sprx, read from its code and checked against its output (see the reference section). #1384 is a draft with an approximate reverb that is waiting for the same kind of reference.

What

sceNgs2RackCreate throws for rack id 0x2001 (reverb). This adds the rack, with the reverb the console library renders.

  • Options: SceNgs2ReverbRackOption (rack option, max_channels, reverb_size). The defaults come from KytyPS5: 8 channels and reverb_size 1.
  • Voice params:
    • 0x20010000 setup takes input and output channel counts and flags. It accepts 1, 2, 6 or 8 channels; other counts are invalid arguments. Non-zero flags and differing input and output counts throw.
    • 0x20010001 takes SceNgs2ReverbI3DL2Param (88 bytes). The layout of both params, and of the voice state, matches shadPS4's ngs2_reverb.h. Values are clamped to the library's ranges, as it does; NaN throws.
    • sceNgs2VoiceGetState returns the common voice state.
  • Rendering, as in the library:
    • The input is mixed to mono with the library's fixed gains (0.707 for stereo, 0.316 for 5.1, 0.267 for 7.1), without the LFE channel.
    • A 14400-sample buffer feeds four reflection taps placed by the reflection pattern tables (16 patterns), plus a late feed.
    • Sixteen damped comb filters with a pre-emphasis stage; their lengths follow density.
    • Each output channel takes a signed selection of the combs, then runs four allpasses driven by diffusion.
    • A two-pole room HF filter at hf_reference, then the wet and dry levels. The LFE channel passes dry.
    • New params crossfade over one grain, and wet and dry levels ramp. Until the title sends I3DL2 params, the setup defaults leave the wet output almost silent.
  • The points the PR was closed for:
    • The Freeverb-style approximation is gone.
    • density and reflection_pattern are used.
    • Before any I3DL2 param, the voice renders the library's setup defaults; it no longer passes its input through.
    • Only the default reverb_size of 1 is handled, with its 14400-sample buffer; other sizes throw.
  • Not implemented: the library's half-rate mode, channel conversion, and system sample rates below about 7.5 kHz, where an allpass would have no samples. All three throw, and TechnicalDebt records them.

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 reverb was read from its disassembly, and the test values are its output.
  • Against that library, the output matches to float rounding (110 to 180 dB SNR). That covers presets, every reflection pattern, short and long delays, 1, 2, 6 and 8 channels, noise input, 11.025 to 48 kHz and parameter changes during playback.
  • 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.
  • A PS5 recording of Animal Well (a public walkthrough): the decay of its jump sound, averaged over 382 jumps there and 72 here, matches within about 0.5 dB for the first 120 ms. Later the background music covers the tail, so that part couldn't be compared.

Tested

  • Windows 11, WinLibs GCC 15.2.0 r7, Release.

  • ngs2_render TestReverb uses 8 cases with the PS4 library's output, to 2e-7 + 1e-5 of each value:

    • the "cave" preset Animal Well uses;
    • a damped room;
    • 5.1;
    • a parameter change mid-stream;
    • clamped values;
    • short delays with pattern 15;
    • noise input with a change;
    • a density change.

    Channel 3 is skipped: the PS4 mastering voice low-passes the LFE channel, and AnyPS5's doesn't yet.

  • TestReverbSetup: 3, 4, 5 and 7 channels are rejected; channel conversion, flags and NaN throw; the setup defaults render a non-zero level below 1e-8; rendering at 7000 Hz throws, and rack options with reverb_size 0 or 2 throw.

  • On main the tests fail, because rack 0x2001 throws. 25 mutations of Reverb.cpp, and removing either new throw, each make them fail.

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

  • Seen in PPSA22520 (Animal Well): it creates the rack with default options, sets up a 2-in, 2-out voice, loads I3DL2 preset 9 ("cave" in the standard preset order) and patches it to its mastering voice. Played with #959 and #964 on main: the jump reverb is the one compared with the PS5 recording above, the game runs at 59 FPS, and there are no NGS2 errors.

  • 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:4802706961 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2336). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-09T15:49:02Z. --- > Replaces #960, which was closed pending a reference. The reverb now follows the PS4 firmware 11.00 `libSceNgs2.sprx`, read from its code and checked against its output (see the reference section). #1384 is a draft with an approximate reverb that is waiting for the same kind of reference. ### What `sceNgs2RackCreate` throws for rack id `0x2001` (reverb). This adds the rack, with the reverb the console library renders. - **Options:** `SceNgs2ReverbRackOption` (rack option, `max_channels`, `reverb_size`). The defaults come from KytyPS5: 8 channels and `reverb_size` 1. - **Voice params:** - `0x20010000` setup takes input and output channel counts and flags. It accepts 1, 2, 6 or 8 channels; other counts are invalid arguments. Non-zero flags and differing input and output counts throw. - `0x20010001` takes `SceNgs2ReverbI3DL2Param` (88 bytes). The layout of both params, and of the voice state, matches shadPS4's `ngs2_reverb.h`. Values are clamped to the library's ranges, as it does; NaN throws. - `sceNgs2VoiceGetState` returns the common voice state. - **Rendering**, as in the library: - The input is mixed to mono with the library's fixed gains (0.707 for stereo, 0.316 for 5.1, 0.267 for 7.1), without the LFE channel. - A 14400-sample buffer feeds four reflection taps placed by the reflection pattern tables (16 patterns), plus a late feed. - Sixteen damped comb filters with a pre-emphasis stage; their lengths follow `density`. - Each output channel takes a signed selection of the combs, then runs four allpasses driven by `diffusion`. - A two-pole room HF filter at `hf_reference`, then the wet and dry levels. The LFE channel passes dry. - New params crossfade over one grain, and wet and dry levels ramp. Until the title sends I3DL2 params, the setup defaults leave the wet output almost silent. - **The points the PR was closed for:** - The Freeverb-style approximation is gone. - `density` and `reflection_pattern` are used. - Before any I3DL2 param, the voice renders the library's setup defaults; it no longer passes its input through. - Only the default `reverb_size` of 1 is handled, with its 14400-sample buffer; other sizes throw. - **Not implemented:** the library's half-rate mode, channel conversion, and system sample rates below about 7.5 kHz, where an allpass would have no samples. All three throw, and TechnicalDebt records them. ### 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 reverb was read from its disassembly, and the test values are its output. - Against that library, the output matches to float rounding (110 to 180 dB SNR). That covers presets, every reflection pattern, short and long delays, 1, 2, 6 and 8 channels, noise input, 11.025 to 48 kHz and parameter changes during playback. - **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. - **A PS5 recording of Animal Well** (a public walkthrough): the decay of its jump sound, averaged over 382 jumps there and 72 here, matches within about 0.5 dB for the first 120 ms. Later the background music covers the tail, so that part couldn't be compared. ### Tested - Windows 11, WinLibs GCC 15.2.0 r7, Release. - `ngs2_render` `TestReverb` uses 8 cases with the PS4 library's output, to 2e-7 + 1e-5 of each value: - the "cave" preset Animal Well uses; - a damped room; - 5.1; - a parameter change mid-stream; - clamped values; - short delays with pattern 15; - noise input with a change; - a density change. Channel 3 is skipped: the PS4 mastering voice low-passes the LFE channel, and AnyPS5's doesn't yet. - `TestReverbSetup`: 3, 4, 5 and 7 channels are rejected; channel conversion, flags and NaN throw; the setup defaults render a non-zero level below 1e-8; rendering at 7000 Hz throws, and rack options with `reverb_size` 0 or 2 throw. - On `main` the tests fail, because rack 0x2001 throws. 25 mutations of `Reverb.cpp`, and removing either new throw, each make them fail. - Full ctest merged with `main` d70b8998, together with #959, #964 and #2337: 507/507. - Seen in PPSA22520 (Animal Well): it creates the rack with default options, sets up a 2-in, 2-out voice, loads I3DL2 preset 9 ("cave" in the standard preset order) and patches it to its mastering voice. Played with #959 and #964 on `main`: the jump reverb is the one compared with the PS5 recording above, the game runs at 59 FPS, and there are no NGS2 errors. - 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:49 +00:00 (Migrated from github.com)

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


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

  • 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 reverb rack DSP implementation in libSceNgs2.native. All audio pipeline tests pass cleanly.

LGTM!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6086307638 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2336#issuecomment-6086307638). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-09T17:52:49Z. --- Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at `473ca04b`: - **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 reverb rack DSP implementation in `libSceNgs2.native`. All audio pipeline tests pass cleanly. 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!2336
No description provided.