feat(ngs2): implement the sampler and submixer peak meter #11354

Merged
edubox merged 3 commits from upstream-pr/11354 into main 2026-10-28 14:16:06 +00:00
edubox commented 2026-10-26 07:27:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-10-26T07:27:56Z.


What

Implement the sampler and submixer peak meter.

  • Handles the sampler control 0x10000009 and the submixer control 0x20000005 (16 bytes, detect type at offset 8).
  • Accepts detect types 0 (off), 1 (peak) and 2 (RMS); above 2 returns 0x804A8093.
  • Keeps a ring of num_peak_meter_blocks values per channel (1 to 256; otherwise 0x804A8092). Peak mode stores the largest absolute sample of each grain, RMS mode the sum of squares.
  • Reports peak_height through sceNgs2VoiceGetState: the largest channel peak, or sqrt(sum / (blocks * grain)) for RMS, over the filled slots.
  • A voice reset clears the detect type and the ring; a detect-type change empties the ring. Measurement is taken after the voice's modules, on its output.

Firmware 13.42 confirms the peak_height field at offset 12 (peak 0.5 and RMS 0.353553 for alternating 16384/0 PCM) and that a sampler SETUP reset turns the meter off until it is enabled again. The submixer reset remains unmeasured and is recorded in the debt entry, together with the ring details that still follow fma-rc's 12.70 module reading.

Tested

Linux, GCC 16.2.1. All 16 ngs2_* tests pass, including TestPeakMeter and TestPeakMeterHistory:

  • submixer and sampler peak_height in peak mode (0.5),
  • submixer RMS mode (0.5) and off mode (0),
  • invalid detect type returns 0x804A8093,
  • submixer and sampler rack creation rejects 0 and 257 blocks with 0x804A8092,
  • multi-block RMS, ring eviction, and a reset that reads 0 and stays off until the meter is enabled again.

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 (a prerequisite for PPSA32802 audio, which still has other gaps)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5013692144 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11354). Originally posted by [edubox](https://github.com/edubox) on 2026-10-26T07:27:56Z. --- ### What Implement the sampler and submixer peak meter. - Handles the sampler control `0x10000009` and the submixer control `0x20000005` (16 bytes, detect type at offset 8). - Accepts detect types 0 (off), 1 (peak) and 2 (RMS); above 2 returns `0x804A8093`. - Keeps a ring of `num_peak_meter_blocks` values per channel (1 to 256; otherwise `0x804A8092`). Peak mode stores the largest absolute sample of each grain, RMS mode the sum of squares. - Reports `peak_height` through `sceNgs2VoiceGetState`: the largest channel peak, or `sqrt(sum / (blocks * grain))` for RMS, over the filled slots. - A voice reset clears the detect type and the ring; a detect-type change empties the ring. Measurement is taken after the voice's modules, on its output. Firmware 13.42 confirms the `peak_height` field at offset 12 (peak 0.5 and RMS 0.353553 for alternating 16384/0 PCM) and that a sampler SETUP reset turns the meter off until it is enabled again. The submixer reset remains unmeasured and is recorded in the debt entry, together with the ring details that still follow [fma-rc's 12.70 module reading](https://github.com/boykopovar/AnyPS5/issues/8039#issuecomment-6319332943). ### Tested Linux, GCC 16.2.1. All 16 `ngs2_*` tests pass, including `TestPeakMeter` and `TestPeakMeterHistory`: - submixer and sampler `peak_height` in peak mode (0.5), - submixer RMS mode (0.5) and off mode (0), - invalid detect type returns `0x804A8093`, - submixer and sampler rack creation rejects 0 and 257 blocks with `0x804A8092`, - multi-block RMS, ring eviction, and a reset that reads 0 and stays off until the meter is enabled again. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none (a prerequisite for PPSA32802 audio, which still has other gaps) - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-26 07:30:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T07:30:25Z.

Review: COMMENTED


I reviewed the implementation against the linked 12.70 analysis and issue #8039's follow-up. That analysis supports the detect modes, block range, ring calculation and a linear voicePeak, but its author explicitly says they have not determined which sampler state field receives that value. This PR writes it directly to Ngs2SamplerVoiceState::peak_height (and the submixer field). The field name makes that mapping plausible, but the current evidence does not establish the firmware mapping; the Trails report in #8039 still identifies it as unresolved. Please add evidence for the output field/offset and read semantics, or document that mapping as an unverified assumption rather than presenting it as confirmed behavior.

The new regression checks one rendered block for peak and RMS. It does not exercise the multi-block RMS average, ring eviction after the configured window, or the reset/retention behavior described in the implementation. Those cases would materially validate the main history logic.

Eligibility, conventions, intake and labels pass; hosted Build jobs are skipped by path policy. I attempted a local configure for an independent run, but it stopped because SDL2's CMake package is unavailable in this environment, so I did not run the reported 16-test suite. I’m leaving this as feedback rather than approval pending the evidence and focused coverage.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5648694266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11354#pullrequestreview-5648694266). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T07:30:25Z. **Review:** COMMENTED --- I reviewed the implementation against the linked 12.70 analysis and issue #8039's follow-up. That analysis supports the detect modes, block range, ring calculation and a linear `voicePeak`, but its author explicitly says they have not determined which sampler state field receives that value. This PR writes it directly to `Ngs2SamplerVoiceState::peak_height` (and the submixer field). The field name makes that mapping plausible, but the current evidence does not establish the firmware mapping; the Trails report in #8039 still identifies it as unresolved. Please add evidence for the output field/offset and read semantics, or document that mapping as an unverified assumption rather than presenting it as confirmed behavior. The new regression checks one rendered block for peak and RMS. It does not exercise the multi-block RMS average, ring eviction after the configured window, or the reset/retention behavior described in the implementation. Those cases would materially validate the main history logic. Eligibility, conventions, intake and labels pass; hosted Build jobs are skipped by path policy. I attempted a local configure for an independent run, but it stopped because SDL2's CMake package is unavailable in this environment, so I did not run the reported 16-test suite. I’m leaving this as feedback rather than approval pending the evidence and focused coverage.
MarcZX10 commented 2026-10-26 09:14:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T09:14:23Z.

Review: CHANGES_REQUESTED


Reviewed exact head 7d136db8870a0cf2c6bc0e72aa18da5a231b45eb against current main 8100e480f7d55e87afb5376b8f784bf17df0f75c.

The new TestPeakMeterHistory addresses the earlier coverage gap: it exercises multi-block RMS, circular eviction, and reset behavior. The debt entry now accurately labels the peak_height mapping as an assumption, rather than established firmware behavior. That disclosure is useful, but the implementation still writes the result into that field and asserts reset retains the detect type even though the PR says neither behavior is verified on PS5. AGENTS.md requires unknown behavior to throw and be recorded in debt. Please provide firmware/console evidence for the field mapping and reset semantics, or leave those behaviors unsupported until evidence establishes them; the test currently verifies the PR's assumptions, not console equivalence.

The latest main has changed Render.cpp, Voice.cpp, Ngs2Render.cpp, and the NGS2 debt file since the PR's merge base c3db979cd33a65a0a651f1e7ba7958137a961413. The merge preview is currently clean, but those shared-path changes were not in the reported test base. Please refresh onto current main, preserve both sets of changes, and rerun the focused NGS2 suite on that exact head.

I also compared the current #11354 and #11315 heads with git merge-tree: they still conflict in Ngs2Internal.hpp, Rack.cpp, Render.cpp, Voice.cpp, and docs/dev/debt/libSceNgs2.native.md. These appear to be separate changes, so the conflict does not itself prove a functional dependency; please coordinate landing order and retain both implementations, test changes and debt entries when resolving it. The PR currently says Depends on: none.

The author reports all 16 ngs2_* tests passing on this head. I did not independently rerun them; hosted eligibility, conventions, labels and report checks pass, and product/build test jobs are skipped by path policy. My earlier local attempt could not execute this NGS2 test binary because the host CPU preflight requires unsupported instructions.

AI-assisted review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5649712272 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11354#pullrequestreview-5649712272). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T09:14:23Z. **Review:** CHANGES_REQUESTED --- Reviewed exact head `7d136db8870a0cf2c6bc0e72aa18da5a231b45eb` against current main `8100e480f7d55e87afb5376b8f784bf17df0f75c`. The new `TestPeakMeterHistory` addresses the earlier coverage gap: it exercises multi-block RMS, circular eviction, and reset behavior. The debt entry now accurately labels the `peak_height` mapping as an assumption, rather than established firmware behavior. That disclosure is useful, but the implementation still writes the result into that field and asserts reset retains the detect type even though the PR says neither behavior is verified on PS5. `AGENTS.md` requires unknown behavior to throw and be recorded in debt. Please provide firmware/console evidence for the field mapping and reset semantics, or leave those behaviors unsupported until evidence establishes them; the test currently verifies the PR's assumptions, not console equivalence. The latest main has changed `Render.cpp`, `Voice.cpp`, `Ngs2Render.cpp`, and the NGS2 debt file since the PR's merge base `c3db979cd33a65a0a651f1e7ba7958137a961413`. The merge preview is currently clean, but those shared-path changes were not in the reported test base. Please refresh onto current main, preserve both sets of changes, and rerun the focused NGS2 suite on that exact head. I also compared the current #11354 and #11315 heads with `git merge-tree`: they still conflict in `Ngs2Internal.hpp`, `Rack.cpp`, `Render.cpp`, `Voice.cpp`, and `docs/dev/debt/libSceNgs2.native.md`. These appear to be separate changes, so the conflict does not itself prove a functional dependency; please coordinate landing order and retain both implementations, test changes and debt entries when resolving it. The PR currently says `Depends on: none`. The author reports all 16 `ngs2_*` tests passing on this head. I did not independently rerun them; hosted eligibility, conventions, labels and report checks pass, and product/build test jobs are skipped by path policy. My earlier local attempt could not execute this NGS2 test binary because the host CPU preflight requires unsupported instructions. AI-assisted review.
MarcZX10 commented 2026-10-26 09:33:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T09:33:25Z.

Review: DISMISSED


Re-reviewed exact head 05bb568fe73b994b5a2f3b5dabe665d47a83914e against current main 4e43321bd6ceccdc1ae28568bbbc35d9a6446464. The branch is now current. The added history tests address the prior multi-block RMS, ring-eviction and reset-coverage gaps, and the author reports all 16 ngs2_* tests passing on this exact head. My python3 -I tools/check_conventions.py --base upstream/main --head upstream/pr/11354 and git diff --check upstream/main...upstream/pr/11354 also pass. I could not independently run the NGS2 binaries on this host: the earlier built test executable exits during its CPU-feature preflight because this Xeon lacks required instructions.

The remaining blocker is the behavior the author confirmed is unverified: the 12.70 module reading does not identify the peak_height output field or its read semantics, and no PS5 measurement establishes that mapping or whether reset retains the detect type. The implementation nevertheless writes voice.peakHeight to that field and the tests assert the assumed value and reset behavior. Recording the uncertainty in the debt file is transparent, but it does not make returning the assumed result conform to AGENTS.md's rule that unknown behavior remains unsupported. Please add firmware evidence for both behaviors, or leave the peak-meter output unsupported until they can be established.

The exact-head pairwise merge preview with #11315 still conflicts in Ngs2Internal.hpp, Rack.cpp, Render.cpp, Voice.cpp and the NGS2 debt file. The changes are distinct; coordinate landing order and preserve both sets when resolving those conflicts.

AI-assisted review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5649917257 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11354#pullrequestreview-5649917257). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T09:33:25Z. **Review:** DISMISSED --- Re-reviewed exact head `05bb568fe73b994b5a2f3b5dabe665d47a83914e` against current `main` `4e43321bd6ceccdc1ae28568bbbc35d9a6446464`. The branch is now current. The added history tests address the prior multi-block RMS, ring-eviction and reset-coverage gaps, and the author reports all 16 `ngs2_*` tests passing on this exact head. My `python3 -I tools/check_conventions.py --base upstream/main --head upstream/pr/11354` and `git diff --check upstream/main...upstream/pr/11354` also pass. I could not independently run the NGS2 binaries on this host: the earlier built test executable exits during its CPU-feature preflight because this Xeon lacks required instructions. The remaining blocker is the behavior the author confirmed is unverified: the 12.70 module reading does not identify the `peak_height` output field or its read semantics, and no PS5 measurement establishes that mapping or whether reset retains the detect type. The implementation nevertheless writes `voice.peakHeight` to that field and the tests assert the assumed value and reset behavior. Recording the uncertainty in the debt file is transparent, but it does not make returning the assumed result conform to `AGENTS.md`'s rule that unknown behavior remains unsupported. Please add firmware evidence for both behaviors, or leave the peak-meter output unsupported until they can be established. The exact-head pairwise merge preview with #11315 still conflicts in `Ngs2Internal.hpp`, `Rack.cpp`, `Render.cpp`, `Voice.cpp` and the NGS2 debt file. The changes are distinct; coordinate landing order and preserve both sets when resolving those conflicts. AI-assisted review.
THEMANnt commented 2026-10-26 15:13:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T15:13:19Z.

Review: APPROVED


Reviewed 4e9ab12 against 035ac96. No actionable findings. The changed render paths maintain per-channel peak/RMS history, reset it when the detection mode changes, and validate sampler and submixer block counts. I built ngs2_render_tests, ngs2_custom_tests and ngs2_voiceindex_tests in Release with WinLibs GCC 15.2.0; focused CTest passed all three (3 passed, 0 skipped, 0 failed). Review-only checks also confirmed both rack types accept the 256-block upper boundary and reject 257. The exact-head Actions run passed eligibility only; product build/test jobs were skipped. This independently validates the affected Windows/MinGW paths, not the full 16-test NGS2 suite or console firmware behavior.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5654336279 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11354#pullrequestreview-5654336279). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-26T15:13:19Z. **Review:** APPROVED --- Reviewed `4e9ab12` against `035ac96`. No actionable findings. The changed render paths maintain per-channel peak/RMS history, reset it when the detection mode changes, and validate sampler and submixer block counts. I built `ngs2_render_tests`, `ngs2_custom_tests` and `ngs2_voiceindex_tests` in Release with WinLibs GCC 15.2.0; focused CTest passed all three (3 passed, 0 skipped, 0 failed). Review-only checks also confirmed both rack types accept the 256-block upper boundary and reject 257. The exact-head Actions run passed eligibility only; product build/test jobs were skipped. This independently validates the affected Windows/MinGW paths, not the full 16-test NGS2 suite or console firmware behavior.
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!11354
No description provided.