feat(libSceNgs2.native): implement sceNgs2ParseWaveformFile and parse 16-bit PCM waveforms #1020

Merged
gjonn merged 5 commits from upstream-pr/1020 into main 2026-10-07 20:21:17 +00:00
gjonn commented 2026-10-07 00:38:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-07T00:38:21Z.


What

Implements sceNgs2ParseWaveformFile(path, offset, info) (resolves the guest path, reads the file from offset to its end, and reuses sceNgs2ParseWaveformData) and adds 16-bit PCM RIFF parsing to sceNgs2ParseWaveformData. Previously only ATRAC9 was parsed and any other format tag threw. A data chunk that runs past the buffer or ends inside a frame returns SCE_NGS2_ERROR_INVALID_WAVEFORM_DATA (assumed, recorded in TechnicalDebt); looped PCM and other PCM formats still throw.

PPSA21402 (Balatro) imports sceNgs2ParseWaveformFile. Its call site sets only three argument registers (path, offset, info), which is where the signature comes from. It loads its sound effects as 16-bit PCM .wav files (80 of 80 have a data chunk that exactly fills the file). It failed at startup with an unresolved import, then with parsing waveform format tag 0x1 is not implemented.

Tested

  • Windows 11, NVIDIA GeForce RTX 5090 Mobile (laptop GPU), MinGW-w64 GCC 15.2.0: ctest -R ngs2 passes (render, atrac9, filter, custom), including new tests for PCM parsing (a data chunk past the buffer or ending inside a frame, 8-bit and zero-channel files are rejected) and file parsing (offset, offset past the end, null path and info).
  • PPSA21402 (same machine): the title parses its sound files through this call and gets past the waveform parse; progress beyond that depends on other changes that are not part of this PR.
  • 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:4766314965 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1020). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-07T00:38:21Z. --- ### What Implements `sceNgs2ParseWaveformFile(path, offset, info)` (resolves the guest path, reads the file from `offset` to its end, and reuses `sceNgs2ParseWaveformData`) and adds 16-bit PCM RIFF parsing to `sceNgs2ParseWaveformData`. Previously only ATRAC9 was parsed and any other format tag threw. A `data` chunk that runs past the buffer or ends inside a frame returns `SCE_NGS2_ERROR_INVALID_WAVEFORM_DATA` (assumed, recorded in TechnicalDebt); looped PCM and other PCM formats still throw. PPSA21402 (Balatro) imports `sceNgs2ParseWaveformFile`. Its call site sets only three argument registers (path, offset, info), which is where the signature comes from. It loads its sound effects as 16-bit PCM `.wav` files (80 of 80 have a `data` chunk that exactly fills the file). It failed at startup with an unresolved import, then with `parsing waveform format tag 0x1 is not implemented`. ### Tested - Windows 11, NVIDIA GeForce RTX 5090 Mobile (laptop GPU), MinGW-w64 GCC 15.2.0: `ctest -R ngs2` passes (render, atrac9, filter, custom), including new tests for PCM parsing (a `data` chunk past the buffer or ending inside a frame, 8-bit and zero-channel files are rejected) and file parsing (offset, offset past the end, null path and info). - PPSA21402 (same machine): the title parses its sound files through this call and gets past the waveform parse; progress beyond that depends on other changes that are not part of this PR. - Not verified on PS5 hardware. ### 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
oneandonlydean commented 2026-10-07 01:48:05 +00:00 (Migrated from github.com)

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


Thanks. A named title with the exact stop on main is what we look for, and the change fits the existing ATRAC9 parser well (linking libc and libkernel for ResolvePath_nid_no_patch matches libSceAjm.native).

Two small things before it can go in:

  • In TestParseFile, out.write("", 3) reads three bytes from a one-byte string literal, which is undefined behaviour. Something like const char pad[3]{}; out.write(pad, sizeof(pad)); does the same thing safely.
  • ParsePcm16 quietly shortens a data chunk that runs past the end of the buffer (your truncated test expects SCE_NGS2_OK with 50 samples). We don't know that the console does that. Could you either return SCE_NGS2_ERROR_INVALID_WAVEFORM_DATA there, or add the truncation to your TechnicalDebt line as an assumption? If Balatro's files hit that case, please say so; that decides it.

The CI run needs a maintainer's approval because this is your first PR here; that's on our side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6029133904 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1020#issuecomment-6029133904). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-07T01:48:05Z. --- Thanks. A named title with the exact stop on main is what we look for, and the change fits the existing ATRAC9 parser well (linking `libc` and `libkernel` for `ResolvePath_nid_no_patch` matches `libSceAjm.native`). Two small things before it can go in: - In `TestParseFile`, `out.write("", 3)` reads three bytes from a one-byte string literal, which is undefined behaviour. Something like `const char pad[3]{}; out.write(pad, sizeof(pad));` does the same thing safely. - `ParsePcm16` quietly shortens a `data` chunk that runs past the end of the buffer (your truncated test expects `SCE_NGS2_OK` with 50 samples). We don't know that the console does that. Could you either return `SCE_NGS2_ERROR_INVALID_WAVEFORM_DATA` there, or add the truncation to your TechnicalDebt line as an assumption? If Balatro's files hit that case, please say so; that decides it. The CI run needs a maintainer's approval because this is your first PR here; that's on our side.
github-actions[bot] commented 2026-10-07 01:48:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T01:48:16Z.


Progress report (3c05400 → fb56ff2)

📈 System libraries: 86.14% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceNgs2.native sceNgs2ParseWaveformFile
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6029135896 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1020#issuecomment-6029135896). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T01:48:16Z. --- <!-- progress-report --> ### Progress report (3c05400 → fb56ff2) 📈 **System libraries**: 86.14% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libSceNgs2.native | `sceNgs2ParseWaveformFile` | </details>
gjonn commented 2026-10-07 01:54:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-07T01:54:22Z.


Thanks for the review. Pushed an update (e59b99b):

  • TestParseFile: now const char pad[3]{}; out.write(pad, sizeof(pad));. (For the record, the original literal held raw 0x01 0x02 0x03 bytes that GitHub does not render, so it wrote 3 of its 4 bytes, but raw control characters in source are fragile anyway.)
  • Truncated data chunk: none of Balatro's 80 .wav files hit it (every data chunk exactly fills its file), so I dropped the truncation. A data chunk that runs past the buffer or ends inside a frame now returns SCE_NGS2_ERROR_INVALID_WAVEFORM_DATA, with tests, and the error code is listed as an assumption in TechnicalDebt.
  • A correction on my side: sceNgs2ParseWaveformFile takes three arguments, (path, offset, info), not four. PPSA21402's call site only sets rdi, rsi and rdx. I had added a size argument, which made the title's info pointer come from a stale register. Fixed, with the test, the test header and the TechnicalDebt entry updated.

ctest -R ngs2 passes on Windows 11. I also updated the PR description, which still described the four-argument version.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6029209740 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1020#issuecomment-6029209740). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-07T01:54:22Z. --- Thanks for the review. Pushed an update (e59b99b): - `TestParseFile`: now `const char pad[3]{}; out.write(pad, sizeof(pad));`. (For the record, the original literal held raw 0x01 0x02 0x03 bytes that GitHub does not render, so it wrote 3 of its 4 bytes, but raw control characters in source are fragile anyway.) - Truncated `data` chunk: none of Balatro's 80 `.wav` files hit it (every `data` chunk exactly fills its file), so I dropped the truncation. A `data` chunk that runs past the buffer or ends inside a frame now returns `SCE_NGS2_ERROR_INVALID_WAVEFORM_DATA`, with tests, and the error code is listed as an assumption in TechnicalDebt. - A correction on my side: `sceNgs2ParseWaveformFile` takes three arguments, `(path, offset, info)`, not four. PPSA21402's call site only sets rdi, rsi and rdx. I had added a `size` argument, which made the title's `info` pointer come from a stale register. Fixed, with the test, the test header and the TechnicalDebt entry updated. `ctest -R ngs2` passes on Windows 11. I also updated the PR description, which still described the four-argument version.
gjonn commented 2026-10-07 02:10:12 +00:00 (Migrated from github.com)

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


The Linux ngs2_atrac9 failure was the new test, not the implementation. It wrote its temporary file to the host's /tmp, but sceNgs2ParseWaveformFile resolves /tmp/... as a guest path, and on Linux every absolute guest path is mapped under the working directory (on Windows a path with a drive letter is passed through unchanged, which is why that job passed).

Pushed 13f0370: the test now asks ResolvePath_nid_no_patch for the host path of a guest path (/aps5_ngs2_parse_file.wav) and writes the file there. I could only run it on Windows, where a driveless guest path takes the same working-directory mapping route, so the Linux run is the real check. This push supersedes the run still waiting for approval on e59b99b.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6029400641 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1020#issuecomment-6029400641). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-07T02:10:12Z. --- The Linux `ngs2_atrac9` failure was the new test, not the implementation. It wrote its temporary file to the host's `/tmp`, but `sceNgs2ParseWaveformFile` resolves `/tmp/...` as a guest path, and on Linux every absolute guest path is mapped under the working directory (on Windows a path with a drive letter is passed through unchanged, which is why that job passed). Pushed 13f0370: the test now asks `ResolvePath_nid_no_patch` for the host path of a guest path (`/aps5_ngs2_parse_file.wav`) and writes the file there. I could only run it on Windows, where a driveless guest path takes the same working-directory mapping route, so the Linux run is the real check. This push supersedes the run still waiting for approval on e59b99b.
oneandonlydean commented 2026-10-07 04:56:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-07T04:56:40Z.


Thanks for the fixes. The Linux CI job still fails on the new head, in the ATRAC9 test this PR changes: ngs2_atrac9 aborts ("Subprocess aborted", after 0.09 s), while the Windows job passes. The log is here: https://github.com/boykopovar/AnyPS5/actions/runs/37561141516/job/112620804339

Could you take a look? It can go in once both jobs are green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6031229752 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1020#issuecomment-6031229752). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-07T04:56:40Z. --- Thanks for the fixes. The Linux CI job still fails on the new head, in the ATRAC9 test this PR changes: `ngs2_atrac9` aborts ("Subprocess aborted", after 0.09 s), while the Windows job passes. The log is here: https://github.com/boykopovar/AnyPS5/actions/runs/37561141516/job/112620804339 Could you take a look? It can go in once both jobs are green.
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!1020
No description provided.