Skip to content

feat(libSceNgs2): add the custom mastering modules 0x17, 0x18 and 0x1a measured on a PS5 - #18501

Merged
oneandonlydean merged 16 commits into
boykopovar:mainfrom
AlfaRojo:feat/ngs2-custom-mastering-modules
Nov 27, 2026
Merged

oneandonlydean merged 16 commits into
boykopovar:mainfrom
AlfaRojo:feat/ngs2-custom-mastering-modules

Conversation

@AlfaRojo

@AlfaRojo AlfaRojo commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What

A custom mastering rack (0x4003) with modules no longer throws at creation. Modules 0x17 (37 by 37 ChannelMixer matrix), 0x18 (peak meter) and 0x1a (Output) follow kali113's measurement, section A (firmware 13.590.001, console's own libSceNgs2.native, payload process).

  • Creation: state size and offset errors 0x804A8302 / 0x804A8301, meter option size 4 0x804A8092, missing max_grain_samples 0x804A8311, max_channels 0x804A8052, max_voices 0x804A8309, option size 0x500 0x804A8013. QueryBufferSize returns the first three module errors; its sizes are not modelled.
  • 0x17: identity until a param; levels clamped to [-32, 32], NaN passes; applies from the next render.
  • 0x18: modes 0, 1, 2 accepted, 3 returns 0x804A8093; GetState accepts 8 and 172 or more bytes, zeros in mode 0.
  • 0x1a: output id from 0x40001a02; an id without a render buffer renders silence.
  • Params are bound to the module's position (0x804A835A); 0x40030002..6 return 0x804A8362; 0x30000002/3/4/6 return 0x804A835A.
  • Throws and recorded in debt: module 0x16 and any other module, peak meter state in modes 1 and 2 (7th float unexplained), channel mixer params shorter than the table, a mastering setup after a channel mixer param, module buffer ids above 0, racks without modules keep their old behaviour, including the std::invalid_argument on a wrong option size (unmeasured; the measurement covers option size 0x500 with modules only, and an option shorter than 0x500 with modules throws too). Limits: payload process measurement, not a title.

Tested

Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, on main f57c971. ngs2_custom and ngs2_core_custom pass 3/3, all 49 ngs2 tests pass 3/3. Negative control: with src/ reverted to main, ngs2_custom aborts in the new checks. check_test_registration.py and check_conventions.py --base upstream/main pass. Tests render per-channel impulses through a 6-channel matrix and compare against the measured values.

Overlap: pr_overlap.py flagged #15946 (debt file lines 53-54, mine edits that entry, trivial merge) and could not compare #1384, #5548, #10249, #14212; their diffs contain none of my symbols (module ids, channel mixer state, mastering checks). #18461 and #18464 touch Voice.cpp mastering params and Ngs2CheckCustomRack for submixers; hunks are disjoint.

  • Head cc80b4e8a2 (merged with upstream/main 51790c7533): all 49 ngs2 tests pass in 3/3 runs; check_test_registration.py and check_conventions.py --base upstream/main pass. New negative controls: with the old range check a state offset of 0xFFFFFFF0 with size 156 on a 172-byte rack is accepted (ngs2_custom fails), and with the old option-size check a rack without modules returns 0x804A8013 instead of throwing (ngs2_custom fails).
  • Head d73bc635cf: sceNgs2VoiceGetState on a custom mastering rack no longer builds a host buffer of state_size; it writes the header and zeroes the rest in 4 KiB chunks. All 50 ngs2 tests pass in 3/3 runs; check_conventions.py --base upstream/main passes. Negative control: with the previous Voice.cpp, the new guard-page case (state_size 0x80000000 and SIZE_MAX on a one-page buffer) fails ngs2_custom.
  • Head a70b1f566c (merged with upstream/main 802a0aeb2d): module 0x17 now uses main's ChannelMixer (Ngs2CustomVoiceChannelMixerParam, customChannelMixer, ProcessChannelMixer) instead of a separate mixing matrix; the mastering param-id, short-param and setup checks stay. All 51 ngs2 tests pass; check_conventions.py --base upstream/main and check_test_registration.py pass.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none; removes the creation throw JJenkx reported on Rise of the Ronin (PPSA04540): NGS2 custom racks need several buffers, module ids 0x15/0x19/0x1b/0x23 and rack id 0x4003 #8039 for racks with these modules, not shown with a title
  • GPUs tested: n/a
  • AI-assisted: yes

AlfaRojo and others added 4 commits November 11, 2026 12:26
…a measured on a PS5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tead of guessing

The measurement does not say whether a custom mastering setup clears the matrix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… which were not measured

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e the mix scratch buffer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx

JJenkx commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 5560952714, merged onto main 65351c2931 (e20ace05ef, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • ngs2_control_reentry_guards, ngs2_detached_pending, ngs2_lifecycle, ngs2_lifecycle_guards, ngs2_ownership, ngs2_rackinfo pass in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1384 core/libs/prx/libSceNgs2.native/include/Ngs2Types.hpp
core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp
core/libs/prx/libSceNgs2.native/src/Rack.cpp
core/libs/prx/libSceNgs2.native/src/Render.cpp
core/libs/prx/libSceNgs2.native/src/Voice.cpp
PR 24647 core/libs/prx/libSceNgs2.native/src/Rack.cpp
core/libs/prx/libSceNgs2.native/src/Voice.cpp
PR 27628 core/libs/prx/libSceNgs2.native/src/Voice.cpp

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 5560952714:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: ngs2_custom_tests built cleanly.
  • CTest (ngs2_custom_safety_custom_callback, ngs2_custom_safety_upstream_callback, ngs2_custom_safety_configured_gain, ngs2_custom_safety_routing_one_buffer, ngs2_custom_safety_routing_two_buffers, ngs2_custom):
    1/6 Test #3816: ngs2_custom_safety_custom_callback .......   Passed    0.02 sec
    2/6 Test #3817: ngs2_custom_safety_upstream_callback .....   Passed    0.02 sec
    3/6 Test #3818: ngs2_custom_safety_configured_gain .......   Passed    0.02 sec
    4/6 Test #3819: ngs2_custom_safety_routing_one_buffer ....   Passed    0.02 sec
    5/6 Test #3820: ngs2_custom_safety_routing_two_buffers ...   Passed    0.03 sec
    6/6 Test #3825: ngs2_custom ..............................   Passed    0.21 sec
    100% tests passed, 0 tests failed out of 6
    
  • Negative control: with core/libs/prx/libSceNgs2.native/include/Ngs2Types.hpp, core/libs/prx/libSceNgs2.native/src/Custom.cpp, core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp, core/libs/prx/libSceNgs2.native/src/Rack.cpp, core/libs/prx/libSceNgs2.native/src/Render.cpp, core/libs/prx/libSceNgs2.native/src/Voice.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified Custom.cpp CheckMasteringModules and CheckMasteringModuleState enforce state size requirements, min state size 16, and exact error codes SCE_NGS2_ERROR_INVALID_STATE_SIZE (0x804A8302) and SCE_NGS2_ERROR_INVALID_STATE_OFFSET (0x804A8301).
    • Verified Custom.cpp ProcessMixMatrix and ApplyMasteringModuleParam bounds safety, clamping levels to [-32.0f, 32.0f] while preserving NaN passthrough, and indexing within the 37x37 levels matrix without out-of-bounds access.
    • Verified Custom.cpp Ngs2CheckMasteringParamId and Voice.cpp sceNgs2VoiceControl position-based module slot routing (0xffff00e0u mask), returning SCE_NGS2_ERROR_INVALID_VOICE_CONTROL_ID (0x804A8362) for 0x40030002..6 and SCE_NGS2_ERROR_INVALID_PARAM_ID (0x804A835A) for mismatched or invalid module IDs.
    • Verified Voice.cpp sceNgs2VoiceGetState output size handling for SCE_NGS2_RACK_ID_CUSTOM_MASTERING with peak meter module, accepting 8 and >= 172 bytes, zeroing state in mode 0, throwing runtime_error for modes 1 and 2, and returning SCE_NGS2_ERROR_INVALID_OUT_SIZE otherwise.
    • Verified Render.cpp Ngs2MasteringOutputUnbound correctly silences output when outputId exceeds numBufferInfo on custom mastering racks configured with module 0x1a.
    • Verified Rack.cpp CheckedRackOption and sceNgs2RackQueryBufferSize validation for SCE_NGS2_RACK_ID_CUSTOM_MASTERING, returning exact error codes 0x804A8013, 0x804A8311, 0x804A8052, and 0x804A8309.
    • Verified AGENTS.md compliance: zero comments in code, Conventional Commit title, no untracked files, and all unmodelled/unimplemented behaviors documented in docs/dev/debt/libSceNgs2.native.md.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

Head 55609527146a7003f35677c093d5174c921c8ea6 adds custom mastering modules 0x17, 0x18 and 0x1a to libSceNgs2; I found no blocking defect in the code I read, and nothing was built or run here.

What I ran

  • Head SHA 55609527146a7003f35677c093d5174c921c8ea6, base main.
  • Read the diff of all 8 reviewed files, then the head code around the changed lines with the repository reader.
  • No build, no test run, no negative control. Toolchain is Linux here; the author's Windows results are reported, not reproduced.
Reader commands
repo_read.py search "samples" core/libs/prx/libSceNgs2.native/src/Custom.cpp
repo_read.py search "CheckedRackOption" core/libs/prx/libSceNgs2.native/src/Rack.cpp
repo_read.py search "ApplyParam" core/libs/prx/libSceNgs2.native/src/Voice.cpp
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Rack.cpp 278 300
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Voice.cpp 1075 1090
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Voice.cpp 1140 1162
repo_read.py search "const bool inside" core/libs/prx/libSceNgs2.native/src/Custom.cpp
repo_read.py search "option->size != size" core/libs/prx/libSceNgs2.native/src/Rack.cpp

Results

Check Result Note
Build libSceNgs2 (Windows, GCC) not run author-reported only
ngs2_custom and ngs2 tests not run author-reported 3/3
Negative control not run author-reported only
check_test_registration.py, check_conventions.py not run author-reported only

Findings

Blocking

None.

Non-blocking

  1. core/libs/prx/libSceNgs2.native/src/Custom.cpp:95: the state range check adds two std::uint32_t values, so state_offset + state_size can wrap. A peak meter at offset 0xFFFFFF00 with size 156 on a 172-byte rack sums to 156, passes the check, and the rack is created. Suggested change:
    const bool inside = info.state_offset >= SCE_NGS2_CUSTOM_MASTERING_MIN_STATE_SIZE && info.state_size <= option.state_size && info.state_offset <= option.state_size - info.state_size;
  1. core/libs/prx/libSceNgs2.native/src/Rack.cpp:106: the option-size check now returns 0x804A8013 for every custom mastering rack, including racks with no modules. Before this change those racks threw std::invalid_argument. The PR body says "racks without modules keep their old behaviour", so either that sentence or the code is wrong. The create path returns the code (Rack.cpp:282). No test covers a no-module rack with a wrong option size; the size test in Ngs2Custom.cpp uses TitleRackOption, which has modules.

Sources

Not verified

  • No build or test run. The author's test results are taken as reported, not reproduced.
  • The 13.590.001 console measurements (the linked #8039 comment) were not opened, so the error codes and state sizes were not checked against the console.
  • Whether the console rejects the wrapped offset in finding 1, or returns an error for no-module racks with a wrong option size (finding 2).
  • Whether ProcessUserFx runs for every mastering voice, which the mix-matrix path depends on; only the author's tests cover this.
  • Compile-time sizes: the static_assert(sizeof(Ngs2CustomVoiceMixMatrixParam) == 5484) assumes 37 channels and an 8-byte header.
  • Only hunks and the head ranges above were read. Ngs2Internal.hpp, Render.cpp, Ngs2Custom.cpp and the debt file were read in the diff only. Excluded by rule: none.

To get this to a good state

  • Decide whether no-module mastering racks should keep throwing on a wrong option size (Rack.cpp:106). Either restrict the check to num_modules != 0 or correct the PR text.
  • Make the state range check overflow-safe (Custom.cpp:95).
  • Rerun ngs2_custom, ngs2, check_test_registration.py and check_conventions.py on the new head.

AlfaRojo and others added 2 commits November 13, 2026 09:11
… and keep the old throw for racks without modules

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@AlfaRojo

Copy link
Copy Markdown
Contributor Author

@MarcZX10 thanks, both points are addressed in 9c484d4daf (which also merges main).

  1. State range check. It is now overflow-safe, as you suggested: state_size <= option.state_size && state_offset <= option.state_size - state_size, with the minimum offset kept and the same 0x804A8301 result. One detail: 0xFFFFFF00 + 156 is 0xFFFFFF9C and does not wrap, so that example was already rejected; the first wrapping offset is 0xFFFFFF64. The new test uses offset 0xFFFFFFF0 with size 156 on a 172-byte rack, which the old check accepted and the new one rejects. Offsets 17 (rejected) and 16 (accepted) are pinned as well.
  2. Option size on racks without modules. The measurement only covers option size 0x500 on a rack that has modules, so the code was wrong and the description was right. 0x804A8013 is now returned only for racks with modules (and an option of at least 0x500 bytes, so num_modules is read inside the declared size); racks without modules throw std::invalid_argument again, as before this PR, with a test. The unmeasured cases are in the debt entry.

All 49 ngs2 tests pass in 3 of 3 runs on the new head (Windows 11, WinLibs GCC 15.2.0 r7, Release); check_test_registration.py and check_conventions.py --base upstream/main pass.

AI-assisted: yes.

AlfaRojo and others added 3 commits November 13, 2026 13:27
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tering debt entry

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: make existing custom mastering gain and output parameters capturable when controls are deferred, and add coverage for that path.

What I ran

Reviewed head cc80b4e8a2d659086c3a5c436b39f81ed4b8c7b7. No commands or tests were run; author-reported test results are not independent runs.

Results

Check Result Note
Changed-line review passed All listed changed files read
Test execution not run Results below are author-reported

Findings

Blocking

  • core/libs/prx/libSceNgs2.native/src/Voice.cpp:757: The new capture hook handles module params, but custom mastering gain (0x40030004) and output (0x40030005) still fall through to the “buffered voice parameter is not implemented” exception. During render or job execution, controls are deferred, so these existing parameters cannot be changed on a custom mastering rack with modules. Extend capture to preserve and apply these parameters, and cover both deferred controls.

Non-blocking

None.

Not verified

  • Tests described in the PR body (including the 49-test suite and negative controls) were not run in this review.
  • Files read: core/libs/prx/libSceNgs2.native/include/Ngs2Types.hpp, core/libs/prx/libSceNgs2.native/src/Custom.cpp, core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp, core/libs/prx/libSceNgs2.native/src/Rack.cpp, core/libs/prx/libSceNgs2.native/src/Render.cpp, core/libs/prx/libSceNgs2.native/src/Voice.cpp, core/libs/prx/libSceNgs2.native/tests/Ngs2Custom.cpp, and docs/dev/debt/libSceNgs2.native.md.
  • Files excluded: none; the manifest lists eight changed files and all eight were read.

To get this to a good state

  • Add deferred capture and application for custom mastering gain and output parameters, with tests exercising controls issued during render or job execution.

@AlfaRojo

Copy link
Copy Markdown
Contributor Author

@MarcZX10 on a rack with modules, 0x40030004 and 0x40030005 never reach CaptureParamControl: Ngs2CheckMasteringParamId runs before the deferral branch (Voice.cpp:1215 vs :1234) and returns INVALID_VOICE_CONTROL_ID (0x804A8362) for 0x40030002 to 0x40030006, as the 13.590 measurement shows (#8039 issuecomment-6792157201); Ngs2Custom.cpp:1526 pins it for each of them. Deferred gain/output on racks without modules already throws on main (Voice.cpp:757 upstream) and this PR does not change that path.

The red windows check is guest_relative_sleep (0xc0000409), the Windows sleep flake that #18299 addresses; no NGS2 test failed.

…stering-modules

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 16, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The change is consistent with its stated scope, and the inspected code showed no verified blocking defect.

What I ran

Reviewed head b7748c925ef3d829fac6ac4cb4ee422b0a6f95e5 using repo_read.py; no tests or builds were run in this review. The description reports Windows 11 / GCC 15.2 test results on an earlier revision and a later head, which I did not independently run.

Results

Check Result Note
Changed code review passed Inspected relevant implementation and tests
Automated checks not run No commands were run in this review
Console behavior not run Measurement is author-reported

Negative control

Not run during this review. The description reports negative controls on earlier revisions; those results were not independently verified.

Findings

Blocking

None verified.

Non-blocking

None.

Sources

Reviewed the prepared description.md, commits.md, manifest.json, and diff.patch, plus the changed files Ngs2Types.hpp, Custom.cpp, Ngs2Internal.hpp, Rack.cpp, Render.cpp, Voice.cpp, Ngs2Custom.cpp, and libSceNgs2.native.md. The implementation accepts only the stated module set and checked state ranges; matrix processing and output routing follow the described behavior in the inspected code. The description and debt entry limit the measurement claim to firmware 13.590.001 payload-process observations, not a title run.

Not verified

Build and test results, console behavior, and any changed lines outside the inspected ranges were not independently verified. No files were excluded by the manifest.

To get this to a good state

Nothing is required. The test and measurement results remain author-reported and were not run or confirmed in this review.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi AlfaRojo, the merge with main is clean and the rest of the PR is the same as the head I and the other reviewers passed. One thing in the merge resolution needs a change, in sceNgs2VoiceGetState for the custom mastering rack (Voice.cpp, the std::vector<std::uint8_t> mastering(state_size, 0) block).

The earlier head cleared the caller's state with std::memset(state, 0, state_size). After the rebase onto the guest-copy change the reply is built in a host vector sized by state_size. The size check there is state_size != sizeof(Ngs2VoiceState) or, with the peak meter module, state_size >= 172, so there is no upper bound: a guest that passes 0x80000000 with a peak meter rack makes the host allocate 2 GiB (or throw bad_alloc out of an export).

Please keep the host buffer bounded. For example build only the 172 byte state (or sizeof(Ngs2VoiceState)) in the vector and write the remaining state_size - n zero bytes through WriteGuestBytes in chunks from a small fixed zero block (4 KiB), returning INVALID_OUT_ADDRESS if any chunk fails. A test with a large state_size on an unmapped or small mapped buffer would pin it.

… copy of its size

sceNgs2VoiceGetState on a custom mastering rack with a peak meter accepts any
state_size from 172 up, and the reply was built in a host vector of that size,
so a large state_size allocated that much host memory or threw out of the
export. Write the common header, then zero the rest through 4 KiB chunks of a
fixed zero block, returning INVALID_OUT_ADDRESS when a chunk cannot be written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlfaRojo

Copy link
Copy Markdown
Contributor Author

@oneandonlydean thanks, fixed in d73bc635cf. The custom mastering branch of sceNgs2VoiceGetState now writes the 8-byte Ngs2VoiceState header with WriteGuest, then zeroes the remaining state_size - 8 bytes through WriteGuestBytes in chunks of at most 4 KiB from a static zero block, returning INVALID_OUT_ADDRESS on the first chunk that fails. No host buffer depends on state_size any more.

New case TestMasteringPeakMeterStateLargerThanTheBuffer: a two-page mapping with the second page inaccessible, state_size 0x80000000 and SIZE_MAX on a peak-meter rack, both return INVALID_OUT_ADDRESS. With the previous Voice.cpp it fails ngs2_custom; with the fix all 50 ngs2 tests pass in 3/3 runs (Windows 11, WinLibs GCC 15.2, Release).

AI-assisted: yes.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Reviewed head d73bc635cfdcb3ee2d6365feff4a4b506b8e964d. I used the review reader to inspect the prepared diff and targeted source context; I did not run commands or tests.

Results

Check Result Note
Diff and changed code review passed All eight changed files were included and reviewed
Test execution not run Reader-only environment

Negative control

Not run; the reader-only environment does not provide test execution.

Findings

Blocking

None identified in the reviewed diff.

Non-blocking

None.

Sources

Not verified

Tests and console behavior were not independently verified. I reviewed the complete prepared diff for all changed files: Ngs2Types.hpp, Custom.cpp, Ngs2Internal.hpp, Rack.cpp, Render.cpp, Voice.cpp, Ngs2Custom.cpp, and libSceNgs2.native.md. No changed files were excluded by the review bundle. Repository files were read in targeted ranges, not in full.

To get this to a good state

Nothing is required. Optionally, run the reported ngs2 test suite on this head.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 16, 2026
…stering-modules

Module 0x17 on the custom mastering rack now uses main's ChannelMixer
(SCE_NGS2_CUSTOM_VOICE_PARAM_CHANNEL_MIXER, Ngs2CustomVoiceChannelMixerParam,
voice.customChannelMixer, ProcessChannelMixer) instead of the separate
MixMatrix type, state and processing. The mastering-specific param-id,
short-param and setup checks stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 17, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head a70b1f566ce6a5c27e06e272412a93be726dd42b, base main, merged-preview not checked.
  • Read the review folder (description, commits, manifest, file list, diff) and the house-rule sections "Readable reviews", "Accuracy and evidence" and "Standard PR response format".
  • Traced the changed code at head with the reader, in Voice.cpp, Custom.cpp, Rack.cpp and Ngs2Internal.hpp.
  • No build and no test run. This is a static review.
Reader commands
repo_read.py search "CaptureParamControl" core/libs/prx/libSceNgs2.native/src/Voice.cpp
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Voice.cpp 1205 1250
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Voice.cpp 1168 1200
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Voice.cpp 1094 1118
repo_read.py search "customChannelMixer" core/libs/prx/libSceNgs2.native/src/Voice.cpp
repo_read.py search "customChannelMixer" core/libs/prx/libSceNgs2.native/src/Custom.cpp
repo_read.py search "WriteGuestBytes" core/libs/prx/libSceNgs2.native/src/Voice.cpp
repo_read.py search "Ngs2ApplyCustomParam" core/libs/prx/libSceNgs2.native/src/Voice.cpp
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Custom.cpp 130 150
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Rack.cpp 255 300
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp 366 376
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp 440 470

Results

Check Result Note
Diff and manifest read passed 8 of 8 reviewed files
Changed code traced at head passed Four source files
Build and unit tests not run Static review only
Author-reported test runs not run 51 ngs2 tests, not re-run
Negative control not run Not run here

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceNgs2.native/src/Custom.cpp:108: module 0x17 accepts a module option of size 20. The debt entry for the channel mixer lists 4, 8 and 16, and the PR text does not mention 20. Confirm that 20 is part of the measurement, or drop it.
  • core/libs/prx/libSceNgs2.native/src/Custom.cpp:97: a peak meter module (0x18) with state_size 0 is accepted as having no state, and the rack then reports a meter to GetState. Neither the PR nor the debt entry says this was measured.
  • core/libs/prx/libSceNgs2.native/src/Custom.cpp:394: (id >> 16) == SCE_NGS2_CUSTOM_VOICE_PARAM_USER_FX2 >> 16 is correct, because >> binds tighter than ==, but parentheses would make the intent clearer.
  • core/libs/prx/libSceNgs2.native/src/Voice.cpp:1385: the zero fill writes in 4 KiB chunks and can return INVALID_OUT_ADDRESS after an earlier chunk has already been written. A failed call can leave part of the guest buffer zeroed, where main wrote nothing on failure. Low impact; worth a comment in the debt entry.

Not verified

  • The build, the 51 ngs2 tests, the negative control and the check_* scripts. The results are author-reported and were not run here.
  • Console behaviour. The measured values (kali113's section A, firmware 13.590.001) and every claim that depends on them. The linked comment was not fetched.
  • The deferred path, Voice.cpp:763 (mastering module params captured while a voice is deferred). I did not check whether any test reaches it.
  • Overlap and merge claims in the description (pr_overlap.py, #15946, #18461, #18464). Not checked.
  • Full text of the eight reviewed files. I read the changed hunks in diff.patch and the reader ranges listed above. Ngs2Types.hpp, Render.cpp, the test file and the debt file were read only through their diffs.
  • WriteGuestBytes rejecting the guard-page write, which the guard-page test relies on. GuestCopyOut was not read.

To get this to a good state

Nothing is required. The non-blocking points above are optional.

@AlfaRojo

Copy link
Copy Markdown
Contributor Author

@oneandonlydean merged current upstream/main (802a0aeb2d) into this branch (a70b1f566c). It conflicted with b1fc911, which added the same module 0x17 as ChannelMixer for the custom submixer and sampler racks, where this PR had added it as a mixing matrix for the custom mastering rack.

There is now one implementation of 0x17, main's:

  • SCE_NGS2_CUSTOM_MODULE_ID_CHANNEL_MIXER, SCE_NGS2_CUSTOM_VOICE_PARAM_CHANNEL_MIXER, Ngs2CustomVoiceChannelMixerParam, per-module state voice.customChannelMixer[module], and ProcessChannelMixer for rendering. The PR's MixMatrix constants, struct, voice.mixMatrix, mixScratch and ProcessMixMatrix are gone.
  • Both clamp levels to [-32, 32] and keep NaN, and both leave the buffer unchanged until a param is set, so the two behaviours agreed and nothing had to be chosen there.
  • What stays scoped to the mastering rack: params bound to the module position (0x804A835A), the 0x40030002..6 and 0x30000002/3/4/6 codes, option sizes 4, 8, 16 and 20 for this rack, module buffer ids above 0 throwing, and a mastering setup after a configured channel mixer throwing.

One difference, not resolved from sources: a param shorter than the 5484-byte table. Main's ChannelMixer applies the bytes present and zero-fills the rest on the submixer and sampler racks. On the mastering rack this PR throws, since the 13.590.001 measurement shows the console reading past the param and the result is unknown. I kept both, each on its own rack, and noted it in the debt entries.

Tests: ngs2_custom was adapted to the ChannelMixer names (same per-channel impulse expectations); ngs2_channelmixer, ngs2_custom, ngs2_core_custom and all 51 ngs2 tests pass. check_conventions.py --base upstream/main and check_test_registration.py pass. debt_fold.py --check fails on two libSceLibreSsl3 fragments that come from main, not from this PR.

@artor410 artor410 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent run of the current head, plus a check of the code against section A of the measurement. I found no defects. Two small documentation points follow, neither blocking.

Since a70b1f566c replaced the separate mixing matrix with main's ChannelMixer, the only test results have been the author's; the later reviews were static. This run covers that head.

Windows run of a70b1f566c

Setup: Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7, Ninja, Release. The head was merged onto main a902d373c1 with --no-ff (clean merge).

  • All ngs2 tests: ctest -R '^ngs2' gives 51 of 51 in 3 of 3 runs.
  • Negative control: the branch's src/ was reverted to main, keeping this PR's Ngs2Types.hpp, since the tests use its new error constants. ngs2_custom then stops with what(): NGS2: custom mastering racks with modules are not implemented (0 of 1). With the branch's src/ restored and the executable rebuilt, it passes again.
  • Checks: tools/check_conventions.py --base origin/main passes with 0 errors (see point 2 for the warnings). tools/debt_fold.py --check passes, and no pending fragment changes the entries this PR edits.

Checked against section A of kali113's measurement

  • Creation:
    • max_grain_samples 0 gives 0x804A8311, max_channels 0 gives 0x804A8052, max_voices 0 gives 0x804A8309.
    • With modules, an option size other than 0x508 gives 0x804A8013.
    • A rack state below 16 gives 0x804A8302.
  • Module state:
    • 0x17 with a non-zero state gives 0x804A8302.
    • 0x18 with a state size other than 156 gives 0x804A8302; at offset 0 it gives 0x804A8301.
    • Rack state 16 and 171 with the title's modules give 0x804A8301, through the overflow-safe range check.
    • 0x17 accepts options of size 4, 8, 16 and 20 (20 is in the table, at buffer size 53592).
    • 0x18 with an option of size 4 gives 0x804A8092.
  • Params:
    • Ids are bound to the module position (0x40001701, 0x40001800 and 0x40001a00 on the title's rack give 0x804A835A).
    • 0x40030002 to 0x40030006 give 0x804A8362, and 0x30000002/3/4/6 give 0x804A835A.
    • Peak meter mode 3 gives 0x804A8093.
    • 0x40001a02 with output_id 1 renders silence.
  • GetState: sizes 8 and 172 or more are accepted, other sizes give 0x804A8011, and mode 0 is zero past the flags.
  • Bounds: every route to ApplyMasteringModuleParam, direct or through the deferred CaptureParamControl copy, passes Ngs2CheckMasteringParamId in sceNgs2VoiceControl first. So customChannelMixer[param.id & 0x1f] stays within the num_modules entries Custom.cpp assigns.

Non-blocking

  1. Debt entries are edited directly. docs/dev/TechnicalDebt.md#fragments (since b720379ac3, 8 Nov) says a pull request adds docs/dev/debt/changes/<branch>.md instead of editing the debt file. This branch changes two libSceNgs2.native.md entries and adds a third in place. The check does not reject it, so this is only about the convention. Moving the three edits into a fragment (## add for the new entry, ## change for the two others) would also stop them from conflicting with later edits to the same lines.
  2. Length warnings. check_conventions warns debt-length on two entries. "NGS2 custom mastering modules" is new and has 1081 characters. "NGS2 custom ChannelMixer" was already 1001 on main and grows to 1039 with the added "(see NGS2 custom mastering modules)".

Not covered: console behaviour (measurement as reported), Linux or macOS, and titles.

AI-assisted: yes (Claude Code). I ran the tests above and read the code at this head against the cited measurement.

AlfaRojo and others added 2 commits November 20, 2026 09:28
@AlfaRojo

Copy link
Copy Markdown
Contributor Author

@artor410 thanks for the run and the check against section A. Both points are addressed in c92c00a890:

  1. The three debt edits moved to docs/dev/debt/changes/feat-ngs2-custom-mastering-modules.md (## change for "NGS2 custom ChannelMixer" and "NGS2 custom mastering rack", ## add Functional for "NGS2 custom mastering modules"); git diff upstream/main...HEAD -- docs/dev/debt/libSceNgs2.native.md is now empty.
  2. "NGS2 custom mastering modules" is down to 997 characters with every throw and not-modelled item kept (wording only), and "NGS2 custom ChannelMixer" is 998, below main's 999: the PR's addition is now "mastering rack modules". check_conventions --base origin/main reports no debt-length warning.

The branch also merges current main (clean); ctest -R '^ngs2' gives 51 of 51 on Windows after the rebuild.

AI-assisted: yes.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Inspected the prepared diff and relevant source sections at head c92c00a8903e3c46b8600facba334d1bbbdc047b using the review reader. I did not run tests.

Results

Check Result Note
Changed-code review passed Relevant hunks inspected
Test suite not run No test command available through the reader
Negative control not run Not executed in this review

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

I inspected relevant sections, not every line, of the eight changed files listed in the manifest: Ngs2Types.hpp, Custom.cpp, Ngs2Internal.hpp, Rack.cpp, Render.cpp, Voice.cpp, Ngs2Custom.cpp, and the debt change fragment. The manifest marks all eight as included; the separate files.json exclusion list was unavailable through the reader. Tests, CI results, and console behavior were not independently verified. The description reports successful tests on earlier heads, not this reviewed head.

To get this to a good state

Nothing is required. Optionally, run the reported test suite on this exact head before merging.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 21, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The reviewed changes add custom mastering rack modules 0x17, 0x18 and 0x1a; I found no verified blocking defect in the inspected implementation.

What I ran

  • Reviewed head 42ab5683f34dc39df32bf0e39021e5b3a86a9995 using repo_read.py.
  • No tests or build commands were run. The test results in the PR description are author reported.

Results

Check Result Note
Changed code review passed Inspected implementation and tests
Build and tests not run Author reported results only

Findings

Blocking

None verified in the inspected code.

Non-blocking

None.

Not verified

The manifest lists seven changed files, all marked included. I read Ngs2Types.hpp, Custom.cpp, Ngs2Internal.hpp, Rack.cpp, Render.cpp, Voice.cpp, and Ngs2Custom.cpp only partially, alongside the description, commits, manifest, and diff. I did not inspect the full text of every changed file or the debt fragment, and did not run tests or builds. The diff patch was read through line 721.

To get this to a good state

Nothing is required.

@JJenkx

JJenkx commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

A title this does not reach yet, for scope. BLUE REFLECTION Quartet (PPSA33655) is a PS5 title, but it imports the PS4 libSceNgs2.prx, the APS5_NGS2_PS4_LIBRARY build, not libSceNgs2.native. It creates a custom mastering rack with modules at startup.

Setup: Linux 7.3.5, RX 7900 XTX (RADV), GCC 16.2.1, Release. main 2b0d3eed8e, and this PR's head 42ab5683f3 merged onto it (eec6d3ab76, clean merge). Fresh save, 240 s, Cross every 15 s.

result
main abort at startup: NGS2: custom mastering racks with modules are not implemented
this PR abort at startup: NGS2: custom mastering racks with modules are not implemented in the PS4 library (Custom.cpp:114, CheckMasteringModules)

So the PR's PS4-library refusal is the stop for this title now. I'm not asking for a change here. The description's measurement is from the PS5 library, and I have no PS4-library measurement to offer. This only records that a released PS5 title takes the PS4 path with modules, in case that matters for scope or a follow-up. The rack it creates, logged by a local print placed just before the PS4-library check (run brdiag161435, not part of this PR): num_modules 2, num_buffers 1, state_size 172.

module module_id source/extra/dest buffer state offset + size option
0 0x17 0/0/0 0 + 0 none
1 0x18 0/0/0 16 + 156 none

Both are modules this PR implements for the PS5 library, with one buffer and no options. I have not checked whether 0x17 with a zero-size state passes CheckMasteringModuleState, or what the PS4 library returns for this rack on hardware.

AI-assisted: yes

Next stop, local experiment only. I let the PS4 library take the module rack, gated behind a private environment variable in a local build, not a proposed change (run brps4m161545). The rack is then accepted, and the title stops at startup on the next call: NGS2: voice param 0x40030001 is not implemented. This PR defines only 0x40030000 (setup), 0x40030004 (gain) and 0x40030005 (output) for the custom mastering voice. So a PS4-library path for this title would also need 0x40030001, whatever that turns out to be. I have no measurement of it.

@oneandonlydean
oneandonlydean dismissed MarcZX10’s stale review November 26, 2026 03:39

18501 MarcZX10 CR 5899870291 (14 Nov 00:12Z on cc80b4e): unfounded for this PR

Claim: deferred custom mastering gain (0x40030004) and output (0x40030005) still throw "buffered voice parameter is not implemented".

  • Gain: live head 42ab568, core/libs/prx/libSceNgs2.native/src/Voice.cpp:676-682 CaptureParamControl captures SCE_NGS2_CUSTOM_MASTERING_VOICE_PARAM_GAIN when deferring. Not a gap.
  • Output: deferred output is not captured for any mastering rack, standard or custom. main has the same code (origin/main Voice.cpp:676 captures only gain, :1182 applies output only immediately). This is pre-existing and not touched by the PR, whose Voice.cpp change is 24/-4 lines for the new 0x17/0x18/0x1a modules.
    PASS MED YES by pr-review3 on 42ab568 at 22 Nov 04:07Z, after the CR. Checked at source by pr-review1.
@oneandonlydean
oneandonlydean merged commit 3387a16 into boykopovar:main Nov 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants