fix(libSceNgs2): clamp the mastering gain to +-32 and keep NaN, as the PS5 module does #10410
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10410"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-23T22:11:36Z.
What
The NGS2 mastering gain no longer throws on NaN or infinity and is now clamped to ±32, matching the PS5 module. Before, an infinite or NaN gain threw, and a gain above 32 was applied unclamped.
sceNgs2VoiceControlwith the mastering param0x30000004(fbwLevel,lfeLevel) returns 0 for every value. Each level is clamped to [−32, 32] on its own, so ±inf gives ±32, and NaN is kept: the channels it scales become NaN. The rest already matched the PS5 module and is now covered by the test: the levels are linear factors on the mastering output, applied from the next render, flat for the first gain a voice receives and ramped over the next grain in eight lanes after that, which this change does not implement; the LFE level acts on channel 3 of 6- and 8-channel voices and the full-band level on every other channel, 1- and 2-channel voices included; a mastering setup resets both to 1, and STOP_IMM plus PLAY keeps them.PS5 measured these into float render buffers only, so a NaN sample in a
PCM_I16Lrender buffer now throws instead of converting to an arbitrary integer; the debt entry says so.Source
The PS5
libSceNgs2.nativemodule of firmware 3.20 and 4.03 (identical results), run on a PC with chosen inputs: a 6- and an 8-channel mastering voice fed an impulse per channel, with each level above sent alone, and 1- and 2-channel voices with mixed full-band and LFE levels. Only return codes and rendered samples were compared. Nothing from the firmware is in the repository.Tested
Windows 11 x64, MinGW GCC 15.2.0 (WinLibs), Release, on
mainate7f46f5c89.TestMasteringGainClampedLikePs5(new, inNgs2Render.cpp) renders into float buffers:PCM_I16Lbuffer throws.TestMasteringGainthat expected a throw is removed.mainsources and the new test,ngs2_renderandngs2_core_renderfail at the first clamped case (gain 33 renders 16.5, not 16).fmin/fmax(drops NaN) in place of the clamp for each level, the LFE level taken from the full-band field, each setup reset removed, and thePCM_I16LNaN throw removed.ctest -R ngs2: 13/13 pass.tools/check_conventions.py --base origin/mainandgit diff --checkare clean.Linux not tested.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T22:54:13Z.
Review: APPROVED
Reviewed the clamping path, NaN handling, channel routing, lifecycle behavior, and new render fixtures against the stated firmware measurements.
std::clamppreserves NaN while bounding finite values and infinities; the tests cover both mastering fields, mono/stereo routing, surround LFE routing, reset and stop/play behavior, plus the explicitly unverified PCM_I16L NaN case. The hosted repository gates pass; build/test jobs are skipped by path policy, and the author reports 13/13 focused NGS2 CTests on Windows with mutation checks. No blocking issue found.