feat(libSceNgs2.native): decode ATRAC9 sampler voices, parse and size ATRAC9 waveforms #248

Merged
adriadam10 merged 2 commits from upstream-pr/248 into main 2026-10-02 07:47:15 +00:00
adriadam10 commented 2026-10-01 18:59:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-01T18:59:09Z.


What

Second NGS2 pull request, on top of #247 (its two commits are included until it merges; only the last commit is new here).

  • Sampler voices play ATRAC9 (waveform_type 0x40, config_data as the 4 big-endian config bytes) through LibAtrac9, already in the tree for AJM. Superframes are decoded whole: frames inside a superframe have variable size, only the superframe size is fixed. The decoder state carries across consecutive blocks (split streams) and restarts on a block repeat or a reset of the waveform blocks. num_skip_samples, num_samples, repeats, callbacks and the sampler state (decoded_data_size, waveform_data) work as for PCM.
  • sceNgs2ParseWaveformData: RIFF/WAVE with a WAVE_FORMAT_EXTENSIBLE ATRAC9 fmt (GUID, config at +0x2C), fact (samples, delay, skip) and data. Other format tags and files with smpl loops throw: how NGS2 splits a looped file into blocks is not known.
  • sceNgs2CalcWaveformBlock for ATRAC9: superframe-aligned offset and size, skip within the superframe. Other waveform types throw.
  • Error codes from KytyPS5 (PS5 numbering): INVALID_WAVEFORM_DATA 0x804A8430, INVALID_WAVEFORM_FORMAT 0x804A8431, UNKNOWN_WAVEFORM_FORMAT 0x804A8432. AT9 chunk layout cross-checked with vgmstream riff.c.
  • Not implemented: interpolation across an ATRAC9 block boundary holds the last sample (exact at pitch 1.0).
  • LibAtrac9 symbols are kept out of the .prx exports with --exclude-libs on Linux, as AJM gets through ffmpeg.

The test helpers move to tests/Ngs2Test.hpp, shared by ngs2_render and the new ngs2_atrac9.

Pan and geometry (sceNgs2Pan*, sceNgs2Geom*) stay unimplemented: KytyPS5 returns identity matrices, shadPS4 and prosper only log, so there is no reference for the real panning law.

Tested

Linux (GCC, Release). ngs2_atrac9 renders a real ATRAC9 superframe (mono, 48 kHz) and compares every sample with LibAtrac9 decoding the same data directly: skip + block end, repeat + state; parses a built AT9 file (fields and error codes); checks CalcWaveformBlock math and errors. Full ctest: 94/94 pass. NID patching of both .prx succeeds; exports are only sceNgs2*. No title tested.

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); no silent stubs
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none new)
  • Generic behaviour, not specific to one title
  • Depends on: #247
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4708221088 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/248). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-01T18:59:09Z. --- ### What Second NGS2 pull request, on top of #247 (its two commits are included until it merges; only the last commit is new here). - Sampler voices play ATRAC9 (`waveform_type 0x40`, `config_data` as the 4 big-endian config bytes) through LibAtrac9, already in the tree for AJM. Superframes are decoded whole: frames inside a superframe have variable size, only the superframe size is fixed. The decoder state carries across consecutive blocks (split streams) and restarts on a block repeat or a reset of the waveform blocks. `num_skip_samples`, `num_samples`, repeats, callbacks and the sampler state (`decoded_data_size`, `waveform_data`) work as for PCM. - `sceNgs2ParseWaveformData`: RIFF/WAVE with a `WAVE_FORMAT_EXTENSIBLE` ATRAC9 `fmt ` (GUID, config at +0x2C), `fact` (samples, delay, skip) and `data`. Other format tags and files with `smpl` loops throw: how NGS2 splits a looped file into blocks is not known. - `sceNgs2CalcWaveformBlock` for ATRAC9: superframe-aligned offset and size, skip within the superframe. Other waveform types throw. - Error codes from KytyPS5 (PS5 numbering): `INVALID_WAVEFORM_DATA 0x804A8430`, `INVALID_WAVEFORM_FORMAT 0x804A8431`, `UNKNOWN_WAVEFORM_FORMAT 0x804A8432`. AT9 chunk layout cross-checked with vgmstream `riff.c`. - Not implemented: interpolation across an ATRAC9 block boundary holds the last sample (exact at pitch 1.0). - LibAtrac9 symbols are kept out of the `.prx` exports with `--exclude-libs` on Linux, as AJM gets through ffmpeg. The test helpers move to `tests/Ngs2Test.hpp`, shared by `ngs2_render` and the new `ngs2_atrac9`. Pan and geometry (`sceNgs2Pan*`, `sceNgs2Geom*`) stay unimplemented: KytyPS5 returns identity matrices, shadPS4 and prosper only log, so there is no reference for the real panning law. ### Tested Linux (GCC, Release). `ngs2_atrac9` renders a real ATRAC9 superframe (mono, 48 kHz) and compares every sample with LibAtrac9 decoding the same data directly: skip + block end, repeat + state; parses a built AT9 file (fields and error codes); checks `CalcWaveformBlock` math and errors. Full `ctest`: 94/94 pass. NID patching of both `.prx` succeeds; exports are only `sceNgs2*`. No title tested. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); no silent stubs - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none new) - [x] Generic behaviour, not specific to one title - [x] Depends on: #247 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-01 18:59:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-01T18:59:31Z.


Progress report (c00bc19 → 69bd750)

📈 System libraries: 79.57% (+1.38%, +24 implemented, -25 removed functions)

✅ 24 implemented
Library Name
libSceNgs2.native Allocate
libSceNgs2.native OnBlock
libSceNgs2.native Release
libSceNgs2.native sceNgs2CalcWaveformBlock
libSceNgs2.native sceNgs2ParseWaveformData
libSceNgs2.native sceNgs2RackCreate
libSceNgs2.native sceNgs2RackCreateWithAllocator
libSceNgs2.native sceNgs2RackDestroy
libSceNgs2.native sceNgs2RackGetVoiceHandle
libSceNgs2.native sceNgs2RackLock
libSceNgs2.native sceNgs2RackQueryBufferSize
libSceNgs2.native sceNgs2RackUnlock
libSceNgs2.native sceNgs2SystemCreate
libSceNgs2.native sceNgs2SystemCreateWithAllocator
libSceNgs2.native sceNgs2SystemDestroy
libSceNgs2.native sceNgs2SystemGetInfo
libSceNgs2.native sceNgs2SystemQueryBufferSize
libSceNgs2.native sceNgs2SystemRender
libSceNgs2.native sceNgs2SystemResetOption
libSceNgs2.native sceNgs2SystemSetGrainSamples
libSceNgs2.native sceNgs2VoiceControl
libSceNgs2.native sceNgs2VoiceGetState
libSceNgs2.native sceNgs2VoiceGetStateFlags
libSceNgs2.native sceNgs2VoiceRunCommands
🗑️ 25 removed
Library Name
libSceNgs2 sceNgs2CalcWaveformBlock
libSceNgs2 sceNgs2GeomApply
libSceNgs2 sceNgs2GeomCalcListener
libSceNgs2 sceNgs2GeomResetListenerParam
libSceNgs2 sceNgs2GeomResetSourceParam
libSceNgs2 sceNgs2PanGetVolumeMatrix
libSceNgs2 sceNgs2PanInit
libSceNgs2 sceNgs2ParseWaveformData
libSceNgs2 sceNgs2RackCreate
libSceNgs2 sceNgs2RackCreateWithAllocator
libSceNgs2 sceNgs2RackDestroy
libSceNgs2 sceNgs2RackGetVoiceHandle
libSceNgs2 sceNgs2RackLock
libSceNgs2 sceNgs2RackQueryBufferSize
libSceNgs2 sceNgs2RackUnlock
libSceNgs2 sceNgs2SystemCreate
libSceNgs2 sceNgs2SystemCreateWithAllocator
libSceNgs2 sceNgs2SystemDestroy
libSceNgs2 sceNgs2SystemGetInfo
libSceNgs2 sceNgs2SystemQueryBufferSize
libSceNgs2 sceNgs2SystemRender
libSceNgs2 sceNgs2SystemSetGrainSamples
libSceNgs2 sceNgs2VoiceControl
libSceNgs2 sceNgs2VoiceGetState
libSceNgs2 sceNgs2VoiceGetStateFlags
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5938453266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/248#issuecomment-5938453266). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-01T18:59:31Z. --- <!-- progress-report --> ### Progress report (c00bc19 → 69bd750) 📈 **System libraries**: 79.57% (+1.38%, +24 implemented, -25 removed functions) <details> <summary>✅ 24 implemented</summary> | Library | Name | | - | - | | libSceNgs2.native | `Allocate` | | libSceNgs2.native | `OnBlock` | | libSceNgs2.native | `Release` | | libSceNgs2.native | `sceNgs2CalcWaveformBlock` | | libSceNgs2.native | `sceNgs2ParseWaveformData` | | libSceNgs2.native | `sceNgs2RackCreate` | | libSceNgs2.native | `sceNgs2RackCreateWithAllocator` | | libSceNgs2.native | `sceNgs2RackDestroy` | | libSceNgs2.native | `sceNgs2RackGetVoiceHandle` | | libSceNgs2.native | `sceNgs2RackLock` | | libSceNgs2.native | `sceNgs2RackQueryBufferSize` | | libSceNgs2.native | `sceNgs2RackUnlock` | | libSceNgs2.native | `sceNgs2SystemCreate` | | libSceNgs2.native | `sceNgs2SystemCreateWithAllocator` | | libSceNgs2.native | `sceNgs2SystemDestroy` | | libSceNgs2.native | `sceNgs2SystemGetInfo` | | libSceNgs2.native | `sceNgs2SystemQueryBufferSize` | | libSceNgs2.native | `sceNgs2SystemRender` | | libSceNgs2.native | `sceNgs2SystemResetOption` | | libSceNgs2.native | `sceNgs2SystemSetGrainSamples` | | libSceNgs2.native | `sceNgs2VoiceControl` | | libSceNgs2.native | `sceNgs2VoiceGetState` | | libSceNgs2.native | `sceNgs2VoiceGetStateFlags` | | libSceNgs2.native | `sceNgs2VoiceRunCommands` | </details> <details> <summary>🗑️ 25 removed</summary> | Library | Name | | - | - | | libSceNgs2 | `sceNgs2CalcWaveformBlock` | | libSceNgs2 | `sceNgs2GeomApply` | | libSceNgs2 | `sceNgs2GeomCalcListener` | | libSceNgs2 | `sceNgs2GeomResetListenerParam` | | libSceNgs2 | `sceNgs2GeomResetSourceParam` | | libSceNgs2 | `sceNgs2PanGetVolumeMatrix` | | libSceNgs2 | `sceNgs2PanInit` | | libSceNgs2 | `sceNgs2ParseWaveformData` | | libSceNgs2 | `sceNgs2RackCreate` | | libSceNgs2 | `sceNgs2RackCreateWithAllocator` | | libSceNgs2 | `sceNgs2RackDestroy` | | libSceNgs2 | `sceNgs2RackGetVoiceHandle` | | libSceNgs2 | `sceNgs2RackLock` | | libSceNgs2 | `sceNgs2RackQueryBufferSize` | | libSceNgs2 | `sceNgs2RackUnlock` | | libSceNgs2 | `sceNgs2SystemCreate` | | libSceNgs2 | `sceNgs2SystemCreateWithAllocator` | | libSceNgs2 | `sceNgs2SystemDestroy` | | libSceNgs2 | `sceNgs2SystemGetInfo` | | libSceNgs2 | `sceNgs2SystemQueryBufferSize` | | libSceNgs2 | `sceNgs2SystemRender` | | libSceNgs2 | `sceNgs2SystemSetGrainSamples` | | libSceNgs2 | `sceNgs2VoiceControl` | | libSceNgs2 | `sceNgs2VoiceGetState` | | libSceNgs2 | `sceNgs2VoiceGetStateFlags` | </details>
adriadam10 commented 2026-10-02 07:25:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T07:25:20Z.


Rebased on the updated #247, where libSceNgs2/Export.cpp is now APS5_DUMMY_FUN only (review on #228/#241). Nothing in this PR's own commit changed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5947343026 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/248#issuecomment-5947343026). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T07:25:20Z. --- Rebased on the updated #247, where `libSceNgs2/Export.cpp` is now `APS5_DUMMY_FUN` only (review on #228/#241). Nothing in this PR's own commit changed.
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!248
No description provided.