feat(libSceNgs2.native): stream 16-bit PCM waveforms through appended waveform blocks #1038

Merged
gjonn merged 1 commit from upstream-pr/1038 into main 2026-10-08 06:01:18 +00:00
gjonn commented 2026-10-07 02:55:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-07T02:55:12Z.


What

Streams 16-bit PCM through appended waveform blocks. A 16-bit PCM block whose num_samples exceed its data was rejected with NGS2: waveform block 0 does not fit its data. It now starts a stream, and a sceNgs2SamplerVoiceAddWaveformBlocks call with flag 0x2 (named SCE_NGS2_WAVEFORM_BLOCKS_FLAG_APPEND here) adds more data to it. While the voice has played everything appended and CONTINUE is set, it outputs silence without advancing. It ends at num_samples or, once CONTINUE is cleared, at the end of the appended data. sceNgs2VoiceGetState reports decoded_data_size and waveform_data for the data actually played. Appending to a block that is not a stream, other waveform formats, skipped samples, repeats and partial frames throw. No reference describes flag 0x2, so its meaning is inferred from the title's calls and recorded in TechnicalDebt.

PPSA21402 (Balatro) streams its music this way: one block whose num_samples is the whole track and whose data is a 16 KiB first piece, with CONTINUE, then one flag-0x2 block for each further piece, releasing its queued data as decoded_data_size grows. On main plus #1020 and #1032, and with the flip queue limited to 2 pending flips (otherwise the GPU worker aborts the title after about 10 s, see #1034), the title stops about 18 s after start with NGS2: waveform block 0 does not fit its data. With this change it keeps running.

Tested

  • Windows 11, NVIDIA GeForce RTX 5090 Mobile (laptop GPU), MinGW-w64 GCC 15.2.0: ctest -R ngs2 passes (all 6 Ngs2 suites). The new ngs2_stream suite renders a stream that ends at num_samples after three pieces (silence while it waits for data, waveform_data and decoded_data_size after each render), a stream that is closed by clearing CONTINUE before num_samples, and the rejections above. With stream detection disabled it aborts with NGS2: waveform block 0 does not fit its data.
  • PPSA21402 (same machine), built from main + #1020 + #1032 with VIDEO_OUT_FLIP_QUEUE_CAPACITY set to 2 locally (not part of this PR, see #1034). Without this change the title stopped with NGS2: waveform block 0 does not fit its data at frame about 820, roughly 14 s after the first frame (2 of 2 runs). With it, 3 of 3 runs were still rendering after 60 s at 59.6 to 60.0 FPS. I cannot listen to the audio here, so how the music sounds is not verified.
  • The full test suite was not run locally, and nothing was run on Linux. Not verified on PS5 hardware.

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:4767314988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1038). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-07T02:55:12Z. --- ### What Streams 16-bit PCM through appended waveform blocks. A 16-bit PCM block whose `num_samples` exceed its data was rejected with `NGS2: waveform block 0 does not fit its data`. It now starts a stream, and a `sceNgs2SamplerVoiceAddWaveformBlocks` call with flag `0x2` (named `SCE_NGS2_WAVEFORM_BLOCKS_FLAG_APPEND` here) adds more data to it. While the voice has played everything appended and `CONTINUE` is set, it outputs silence without advancing. It ends at `num_samples` or, once `CONTINUE` is cleared, at the end of the appended data. `sceNgs2VoiceGetState` reports `decoded_data_size` and `waveform_data` for the data actually played. Appending to a block that is not a stream, other waveform formats, skipped samples, repeats and partial frames throw. No reference describes flag `0x2`, so its meaning is inferred from the title's calls and recorded in TechnicalDebt. PPSA21402 (Balatro) streams its music this way: one block whose `num_samples` is the whole track and whose data is a 16 KiB first piece, with `CONTINUE`, then one flag-`0x2` block for each further piece, releasing its queued data as `decoded_data_size` grows. On `main` plus #1020 and #1032, and with the flip queue limited to 2 pending flips (otherwise the GPU worker aborts the title after about 10 s, see #1034), the title stops about 18 s after start with `NGS2: waveform block 0 does not fit its data`. With this change it keeps running. ### Tested - Windows 11, NVIDIA GeForce RTX 5090 Mobile (laptop GPU), MinGW-w64 GCC 15.2.0: `ctest -R ngs2` passes (all 6 Ngs2 suites). The new `ngs2_stream` suite renders a stream that ends at `num_samples` after three pieces (silence while it waits for data, `waveform_data` and `decoded_data_size` after each render), a stream that is closed by clearing `CONTINUE` before `num_samples`, and the rejections above. With stream detection disabled it aborts with `NGS2: waveform block 0 does not fit its data`. - PPSA21402 (same machine), built from `main` + #1020 + #1032 with `VIDEO_OUT_FLIP_QUEUE_CAPACITY` set to 2 locally (not part of this PR, see #1034). Without this change the title stopped with `NGS2: waveform block 0 does not fit its data` at frame about 820, roughly 14 s after the first frame (2 of 2 runs). With it, 3 of 3 runs were still rendering after 60 s at 59.6 to 60.0 FPS. I cannot listen to the audio here, so how the music sounds is not verified. - The full test suite was not run locally, and nothing was run on Linux. Not verified on PS5 hardware. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
oneandonlydean commented 2026-10-07 05:05:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-07T05:05:41Z.


Thanks. #1032 has landed, and this now conflicts with main in docs/dev/TechnicalDebt.md only (the NGS2 lines); keeping both sides should be all it needs. Could you rebase it? It can go in once CI is green on the new head. The ngs2_atrac9 failure on #1020 is separate and doesn't block this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6031324956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1038#issuecomment-6031324956). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-07T05:05:41Z. --- Thanks. #1032 has landed, and this now conflicts with `main` in `docs/dev/TechnicalDebt.md` only (the NGS2 lines); keeping both sides should be all it needs. Could you rebase it? It can go in once CI is green on the new head. The `ngs2_atrac9` failure on #1020 is separate and doesn't block this one.
adriadam10 commented 2026-10-08 05:40:37 +00:00 (Migrated from github.com)

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


Rebased onto current main (only conflict: the foreach test list in libSceNgs2.native/CMakeLists.txt, now ... Custom Parse Stream). Build and ctest green locally (416/416, ngs2_stream included); without the change the new test doesn't build. Merging once CI is green on the rebased head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6053178631 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1038#issuecomment-6053178631). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T05:40:37Z. --- Rebased onto current `main` (only conflict: the `foreach` test list in `libSceNgs2.native/CMakeLists.txt`, now `... Custom Parse Stream`). Build and ctest green locally (416/416, `ngs2_stream` included); without the change the new test doesn't build. Merging once CI is green on the rebased head.
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!1038
No description provided.