feat(libSceNgs2.native): sampler voice low-pass filter #778

Merged
adriadam10 merged 1 commit from upstream-pr/778 into main 2026-10-06 05:36:29 +00:00
adriadam10 commented 2026-10-05 23:15:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T23:15:37Z.


What

sceNgs2VoiceControl now accepts the sampler voice filter param (0x1000000a, 56 bytes). Until now it threw "sampler voice param 0x1000000a is not implemented".

The only reference with a body is KytyPS5 (src/libs/ngs2.cpp, Ngs2SamplerFilter). shadPS4, fpPS4, prosper and SharpProspero have nothing for this param, so the layout and behaviour come from KytyPS5 alone:

  • Layout: index, location, type, a 64-bit channel_mask at offset 16 of the payload, then frequency, q and level.
  • Location 1 type 1 is an RBJ low-pass biquad (Audio EQ Cookbook), scaled by level. It runs after resampling at the system sample rate, not the source rate. A cutoff of 0 gives silence and a cutoff at or above Nyquist passes the input through times level.
  • A set bit in channel_mask bypasses that channel.
  • Type 0 turns the filter off and clears its history. Sending the same params again keeps the history.
  • A filter tail keeps the voice playing after its last block until the history is zero. Outputs below 1e-20 are flushed to zero. That cutoff is KytyPS5's choice.
  • A new sampler setup clears the voice's filters.

Where we differ from KytyPS5 (exact or throw):

  • KytyPS5 logs a warning and disables the filter for other locations/types. Here they throw runtime_error.
  • KytyPS5 also disables it for a NaN or negative frequency, q <= 0 or a negative level. Here those throw invalid_argument.
  • An index at or past the rack's max_filters throws, as it does in KytyPS5.

The inferred layout and the tail behaviour are listed under TechnicalDebt "Unknown function info".

Tested

Linux, GCC (Release and a fast debug build): new ngs2_filter test (registered in ctest next to ngs2_render/ngs2_atrac9). It renders through a mastering voice into F32 buffers and checks:

  • Impulse response against an RBJ biquad computed in the test, the params resent every grain, and the tail after the block end (voice stays PLAYING, then type 0 → silent and flags 0).
  • Bypass mask on a stereo voice and the level gain at Nyquist, plus the voice going empty once the history drains.
  • A 24 kHz source with an 18 kHz cutoff filtered at the 48 kHz system rate, a zero cutoff giving silence, and a new setup clearing the filters.
  • Each rejected param: index 8, location 0, type 2, NaN or negative frequency, q 0, negative level, short size.

On main the test fails because the param throws. 12 mutants of the implementation (source rate, no bypass, no tail, history reset on resend, no clear on setup, level dropped, bounds) each make it fail. ngs2_render and ngs2_atrac9 still pass, and so do all guest_* tests.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4751907822 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/778). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T23:15:37Z. --- ### What `sceNgs2VoiceControl` now accepts the sampler voice filter param (`0x1000000a`, 56 bytes). Until now it threw "sampler voice param 0x1000000a is not implemented". The only reference with a body is KytyPS5 (`src/libs/ngs2.cpp`, `Ngs2SamplerFilter`). shadPS4, fpPS4, prosper and SharpProspero have nothing for this param, so the layout and behaviour come from KytyPS5 alone: - Layout: `index`, `location`, `type`, a 64-bit `channel_mask` at offset 16 of the payload, then `frequency`, `q` and `level`. - Location 1 type 1 is an RBJ low-pass biquad (Audio EQ Cookbook), scaled by `level`. It runs after resampling at the system sample rate, not the source rate. A cutoff of 0 gives silence and a cutoff at or above Nyquist passes the input through times `level`. - A set bit in `channel_mask` bypasses that channel. - Type 0 turns the filter off and clears its history. Sending the same params again keeps the history. - A filter tail keeps the voice playing after its last block until the history is zero. Outputs below 1e-20 are flushed to zero. That cutoff is KytyPS5's choice. - A new sampler setup clears the voice's filters. Where we differ from KytyPS5 (exact or throw): - KytyPS5 logs a warning and disables the filter for other locations/types. Here they throw `runtime_error`. - KytyPS5 also disables it for a NaN or negative frequency, `q <= 0` or a negative level. Here those throw `invalid_argument`. - An index at or past the rack's `max_filters` throws, as it does in KytyPS5. The inferred layout and the tail behaviour are listed under TechnicalDebt "Unknown function info". ### Tested Linux, GCC (Release and a fast debug build): new `ngs2_filter` test (registered in ctest next to `ngs2_render`/`ngs2_atrac9`). It renders through a mastering voice into F32 buffers and checks: - Impulse response against an RBJ biquad computed in the test, the params resent every grain, and the tail after the block end (voice stays PLAYING, then type 0 → silent and flags 0). - Bypass mask on a stereo voice and the `level` gain at Nyquist, plus the voice going empty once the history drains. - A 24 kHz source with an 18 kHz cutoff filtered at the 48 kHz system rate, a zero cutoff giving silence, and a new setup clearing the filters. - Each rejected param: index 8, location 0, type 2, NaN or negative frequency, q 0, negative level, short size. On `main` the test fails because the param throws. 12 mutants of the implementation (source rate, no bypass, no tail, history reset on resend, no clear on setup, level dropped, bounds) each make it fail. `ngs2_render` and `ngs2_atrac9` still pass, and so do all `guest_*` tests. ### 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
adriadam10 commented 2026-10-05 23:42:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T23:42:20Z.


Rebased on main (TechnicalDebt conflict with the libSceShare line, both kept); ngs2 tests pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6005643255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/778#issuecomment-6005643255). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T23:42:20Z. --- Rebased on main (TechnicalDebt conflict with the libSceShare line, both kept); ngs2 tests pass.
oneandonlydean commented 2026-10-06 03:27:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T03:27:13Z.


Thanks. This now conflicts with main in docs/dev/TechnicalDebt.md only: #582 (predication GetSize functions) added its line at the same place, the end of the unverified-behaviour list. Keeping both lines resolves it. The code itself is unchanged since my last check, so after the rebase it is ready from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6008721533 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/778#issuecomment-6008721533). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T03:27:13Z. --- Thanks. This now conflicts with `main` in `docs/dev/TechnicalDebt.md` only: #582 (predication GetSize functions) added its line at the same place, the end of the unverified-behaviour list. Keeping both lines resolves it. The code itself is unchanged since my last check, so after the rebase it is ready from my side.
adriadam10 commented 2026-10-06 05:16:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T05:16:37Z.


Rebased on current main: kept both TechnicalDebt lines (#582 predication GetSize and Resource registration, then the sampler filter line). ngs2_* tests pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6009839740 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/778#issuecomment-6009839740). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T05:16:37Z. --- Rebased on current `main`: kept both TechnicalDebt lines (#582 predication GetSize and Resource registration, then the sampler filter line). `ngs2_*` tests pass.
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!778
No description provided.