feat(libSceNgs2): map waveform blocks of linear PCM and float types #8338

Merged
KernelPanicNT merged 1 commit from upstream-pr/8338 into main 2026-10-21 12:17:41 +00:00
KernelPanicNT commented 2026-10-20 10:22:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KernelPanicNT on 2026-10-20T10:22:14Z.


What

sceNgs2CalcWaveformBlock now maps a sample range of a linear PCM or float waveform (types 0x10 to 0x1b) to a waveform block, and returns 0x804A8432 for a type the module does not know. On main every type other than ATRAC9 throws.

Source of the behaviour. prosper's reading of the PS5 libSceNgs2.native.sprx, which gives file offsets into the module and rates everything it calls native "CONFIDENCE: HIGH (read from the disassembly and exercised by test_ngs2_waveform)". PS5 titles bind the native module, not libSceNgs2.sprx, whose errors and block layout differ.

The PCM mapping (calc_block, 0x120a5):

  • stride = channels × bytes per sample, from the table {1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 8, 8} for 0x10..0x1b (rodata 0x54d10);
  • data offset = position × stride, data size = (position + count) × stride − offset, both modulo 2^32;
  • number of samples = count; skip and repeats 0;
  • no channel or rate check: zero channels gives an empty block.

Around it (entry point): a null block returns 0x804A8010 before anything is written, the block is zeroed before the format is read, a null format returns 0x804A8431, and a type other than PCM, float, VAG (0x1c) and ATRAC9 returns 0x804A8432 (L395), with the block left zeroed. prosper's own test exercises the same cases.

VAG keeps throwing, and ATRAC9 keeps its current mapping and checks: both are recorded as debt, with how the ATRAC9 path differs from the reading (decoder delay, zero-count blocks, 32-bit wrap, config check). Draft #5797 adds VAG parsing and decoding but does not touch this function.

Changes:

  • Atrac9.cpp: the bytes-per-sample table and a PcmBlock helper (reused by the follow-up that parses PCM loops), the PCM branch before ATRAC9's channel and rate check, and 0x804A8432 for unknown types.
  • ngs2_atrac9_tests, new TestCalcPcmBlock: every type 0x10..0x1b, stereo 16-bit and float cases, zero channels, no rate, the modulo-2^32 wrap of offset and size, unknown types (0x0, 0xf, 0x1d, 0x20, 0x30, 0x43) with the block zeroed, and a null format.
  • docs/dev/debt/libSceNgs2.native.md: a new entry for VAG and the ATRAC9 differences.

Tested

Linux (GitHub Codespace, 4 cores, native build of this branch on d14a186f4):

  • ngs2_atrac9_tests: 5/5 runs pass.
  • Negative control: with Atrac9.cpp from main, ngs2_atrac9_tests aborts at the first PCM case, which main rejects (NGS2 check failed at line 202); 5/5 pass again after restoring it.
  • ctest -R ngs2_: all 13 ngs2_* tests pass.

Windows (fork CI, run 39403153111, this branch and an unrelated libSceSystemService branch merged into main at d14a186f4): build and the full test suite pass, 1734/1734.

Checks:

  • python3 tools/check_conventions.py --base origin/main passes.
  • python3 tools/pr_overlap.py --branch feat/ngs2-calc-waveform-block-pcm: reports no overlapping change. It could not compare draft #5797, which conflicts with main; checked by hand: #5797 sends VAGp data to its own parser before the RIFF path and adds its debt entry at the top of the file, so it touches neither the RIFF routing, the loops nor sceNgs2CalcWaveformBlock.
  • tools/progress.py: unchanged (4246/6515 on base and head).

Checklist

  • Based on current main (d14a186f4); 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
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4934366903 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8338). Originally posted by [KernelPanicNT](https://github.com/KernelPanicNT) on 2026-10-20T10:22:14Z. --- ### What `sceNgs2CalcWaveformBlock` now maps a sample range of a linear PCM or float waveform (types 0x10 to 0x1b) to a waveform block, and returns `0x804A8432` for a type the module does not know. On `main` [every type other than ATRAC9 throws](https://github.com/boykopovar/AnyPS5/blob/d14a186f46155a3e87d5d070d8fda9dae382c180/core/libs/prx/libSceNgs2.native/src/Atrac9.cpp#L407-L425). **Source of the behaviour.** [prosper's reading of the PS5 `libSceNgs2.native.sprx`](https://github.com/mattias800/prosper/blob/40d95db32efe1ad00106a5b9a84e018fffa9ecff/prosper/src/hle/audio/ngs2_waveform.cpp#L1-L15), which gives file offsets into the module and rates everything it calls native "CONFIDENCE: HIGH (read from the disassembly and exercised by test_ngs2_waveform)". PS5 titles bind the native module, not `libSceNgs2.sprx`, whose errors and block layout differ. The PCM mapping ([calc_block, `0x120a5`](https://github.com/mattias800/prosper/blob/40d95db32efe1ad00106a5b9a84e018fffa9ecff/prosper/src/hle/audio/ngs2_waveform.cpp#L348-L360)): - stride = channels × bytes per sample, from the table `{1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 8, 8}` for 0x10..0x1b ([rodata `0x54d10`](https://github.com/mattias800/prosper/blob/40d95db32efe1ad00106a5b9a84e018fffa9ecff/prosper/src/hle/audio/ngs2_waveform.cpp#L58-L59)); - data offset = position × stride, data size = (position + count) × stride − offset, both modulo 2^32; - number of samples = count; skip and repeats 0; - no channel or rate check: zero channels gives an empty block. Around it ([entry point](https://github.com/mattias800/prosper/blob/40d95db32efe1ad00106a5b9a84e018fffa9ecff/prosper/src/hle/audio/ngs2_waveform.cpp#L444-L466)): a null block returns `0x804A8010` before anything is written, the block is zeroed before the format is read, a null format returns `0x804A8431`, and a type other than PCM, float, VAG (0x1c) and ATRAC9 returns `0x804A8432` ([L395](https://github.com/mattias800/prosper/blob/40d95db32efe1ad00106a5b9a84e018fffa9ecff/prosper/src/hle/audio/ngs2_waveform.cpp#L395)), with the block left zeroed. [prosper's own test](https://github.com/mattias800/prosper/blob/40d95db32efe1ad00106a5b9a84e018fffa9ecff/prosper/tests/hle/test_ngs2_waveform.cpp#L432-L476) exercises the same cases. VAG keeps throwing, and ATRAC9 keeps its current mapping and checks: both are recorded as debt, with how the ATRAC9 path differs from the reading (decoder delay, zero-count blocks, 32-bit wrap, config check). Draft #5797 adds VAG parsing and decoding but does not touch this function. Changes: - `Atrac9.cpp`: the bytes-per-sample table and a `PcmBlock` helper (reused by the follow-up that parses PCM loops), the PCM branch before ATRAC9's channel and rate check, and `0x804A8432` for unknown types. - `ngs2_atrac9_tests`, new `TestCalcPcmBlock`: every type 0x10..0x1b, stereo 16-bit and float cases, zero channels, no rate, the modulo-2^32 wrap of offset and size, unknown types (0x0, 0xf, 0x1d, 0x20, 0x30, 0x43) with the block zeroed, and a null format. - `docs/dev/debt/libSceNgs2.native.md`: a new entry for VAG and the ATRAC9 differences. ### Tested Linux (GitHub Codespace, 4 cores, native build of this branch on `d14a186f4`): - `ngs2_atrac9_tests`: 5/5 runs pass. - Negative control: with `Atrac9.cpp` from `main`, `ngs2_atrac9_tests` aborts at the first PCM case, which `main` rejects (`NGS2 check failed at line 202`); 5/5 pass again after restoring it. - `ctest -R ngs2_`: all 13 `ngs2_*` tests pass. Windows (fork CI, [run 39403153111](https://github.com/KernelPanicNT/AnyPS5/actions/runs/39403153111), this branch and an unrelated libSceSystemService branch merged into `main` at `d14a186f4`): build and the full test suite pass, 1734/1734. Checks: - `python3 tools/check_conventions.py --base origin/main` passes. - `python3 tools/pr_overlap.py --branch feat/ngs2-calc-waveform-block-pcm`: reports no overlapping change. It could not compare draft #5797, which conflicts with `main`; checked by hand: #5797 sends `VAGp` data to its own parser before the RIFF path and adds its debt entry at the top of the file, so it touches neither the RIFF routing, the loops nor `sceNgs2CalcWaveformBlock`. - `tools/progress.py`: unchanged (4246/6515 on base and head). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main` (`d14a186f4`); 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 - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-20 10:34:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T10:34:39Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 8528 core/libs/prx/libSceNgs2.native/tests/Ngs2Atrac9.cpp L197, L506

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5797 core/libs/prx/libSceNgs2.native/src/Atrac9.cpp
docs/dev/debt/libSceNgs2.native.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288955270 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8338#issuecomment-6288955270). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T10:34:39Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 8528](https://www.github.com/boykopovar/AnyPS5/pull/8528) | `core/libs/prx/libSceNgs2.native/tests/Ngs2Atrac9.cpp` [L197](https://github.com/boykopovar/AnyPS5/blob/0a5080477f3a59cfb21fe49f5b992475a5ec151b/core/libs/prx/libSceNgs2.native/tests/Ngs2Atrac9.cpp#L197), [L506](https://github.com/boykopovar/AnyPS5/blob/0a5080477f3a59cfb21fe49f5b992475a5ec151b/core/libs/prx/libSceNgs2.native/tests/Ngs2Atrac9.cpp#L506) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5797](https://www.github.com/boykopovar/AnyPS5/pull/5797) | `core/libs/prx/libSceNgs2.native/src/Atrac9.cpp`<br>`docs/dev/debt/libSceNgs2.native.md` |
adriadam10 commented 2026-10-21 12:19:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T12:19:37Z.


Checked the PCM/float mapping, the error order and the wrap tests against prosper's calc_block and calc_waveform_block; the debt entry covers VAG and the ATRAC9 differences; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6315736031 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8338#issuecomment-6315736031). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-21T12:19:37Z. --- Checked the PCM/float mapping, the error order and the wrap tests against prosper's `calc_block` and `calc_waveform_block`; the debt entry covers VAG and the ATRAC9 differences; merged.
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!8338
No description provided.