feat(libSceAudiodec): decode MP3, M4AAC and ATRAC9 #236

Merged
adriadam10 merged 1 commit from upstream-pr/236 into main 2026-10-02 07:34:12 +00:00
adriadam10 commented 2026-10-01 17:37:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-01T17:37:43Z.


What

Implements all six libSceAudiodec exports with real decoding: MP3 and M4AAC through the bundled FFmpeg, ATRAC9 through LibAtrac9 (both already used by libSceAjm.native). libSceAudiodec.native only exported NotImplemented stubs of the same six functions; as asked in #228 and #241, its Export.cpp is now APS5_DUMMY_FUN only, like libkernel_sys, so the two libraries no longer export the same symbols.

  • sceAudiodecInitLibrary / TermLibrary count initialisations per codec type; CreateDecoder requires one.
  • CreateDecoder validates the control block (pointers, uiSize of param and BSI info, word size) and the codec parameters, and fills the BSI info: ATRAC9 from the config data (channels, rate, superframe size and frame count, bitrate); M4AAC from the configured rate index and channel count.
  • Decode decodes one unit per call and reports bytes consumed in uiAuSize and bytes written in uiPcmSize: one MP3 frame (the header fields go to the MP3 info), one ADTS frame or one raw block for M4AAC (uiConfigNumber 1 / 2; raw blocks get an AudioSpecificConfig built from the rate index and channel count), or one ATRAC9 superframe. Output is interleaved S16 or float. A too small PCM buffer returns INVALID_PCM_SIZE; truncated or corrupt input returns API_FAIL, with iResult -5 / -4 for M4AAC.
  • ClearContext flushes the decoder; DeleteDecoder frees it.

References. Structs and error codes (0x807F00xx, 0x807F03xx, 0x807F1000) agree in KytyPS5, fpPS4 and SharpProspero; the M4AAC parameter layout matches what prosper recovered from a title's call sites. Behavioural differences: KytyPS5 decodes only AAC and returns silence for MP3 and ATRAC9; fpPS4 does not decode.

Known gaps, listed in TechnicalDebt.md: the 24-bit word size (iBwPcm 0) throws because its layout is unknown; ATRAC9 decoding is only covered by configuration and error tests, since there is no free ATRAC9 encoder for a fixture.

Side finding, not changed here: this FFmpeg build has the fixed-point MP3 decoder, which outputs S16P. RunMp3 in libSceAjm.native only accepts FLTP and throws otherwise, so AJM MP3 decoding probably always fails. Fixed in #237.

Tested

Linux (CachyOS, GCC): new guest_audiodec test (core/libs/tests/GuestAudiodec.cpp) with small fixtures generated by FFmpeg (1 kHz sine, 48 kHz): stereo AAC decoded both as ADTS and as raw blocks, checking bytes consumed and produced per frame, the reported format and the tone's zero-crossing rate; mono MP3 decoded to float, checking frame sizes, header fields and amplitude; ATRAC9 config parsing, BSI info and error paths; and the control block validation. It fails on injected bugs (no partial-input check, wrong raw sample-rate index, MP3 mode not reported, wrong S16P scaling). Full suite passes. Windows only through CI. 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); 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:4707305528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/236). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-01T17:37:43Z. --- ### What Implements all six `libSceAudiodec` exports with real decoding: MP3 and M4AAC through the bundled FFmpeg, ATRAC9 through LibAtrac9 (both already used by `libSceAjm.native`). `libSceAudiodec.native` only exported `NotImplemented` stubs of the same six functions; as asked in #228 and #241, its `Export.cpp` is now `APS5_DUMMY_FUN` only, like `libkernel_sys`, so the two libraries no longer export the same symbols. - `sceAudiodecInitLibrary` / `TermLibrary` count initialisations per codec type; `CreateDecoder` requires one. - `CreateDecoder` validates the control block (pointers, `uiSize` of param and BSI info, word size) and the codec parameters, and fills the BSI info: ATRAC9 from the config data (channels, rate, superframe size and frame count, bitrate); M4AAC from the configured rate index and channel count. - `Decode` decodes one unit per call and reports bytes consumed in `uiAuSize` and bytes written in `uiPcmSize`: one MP3 frame (the header fields go to the MP3 info), one ADTS frame or one raw block for M4AAC (`uiConfigNumber` 1 / 2; raw blocks get an AudioSpecificConfig built from the rate index and channel count), or one ATRAC9 superframe. Output is interleaved S16 or float. A too small PCM buffer returns `INVALID_PCM_SIZE`; truncated or corrupt input returns `API_FAIL`, with `iResult` -5 / -4 for M4AAC. - `ClearContext` flushes the decoder; `DeleteDecoder` frees it. References. Structs and error codes (`0x807F00xx`, `0x807F03xx`, `0x807F1000`) agree in KytyPS5, fpPS4 and SharpProspero; the M4AAC parameter layout matches what prosper recovered from a title's call sites. Behavioural differences: KytyPS5 decodes only AAC and returns silence for MP3 and ATRAC9; fpPS4 does not decode. Known gaps, listed in `TechnicalDebt.md`: the 24-bit word size (`iBwPcm` 0) throws because its layout is unknown; ATRAC9 decoding is only covered by configuration and error tests, since there is no free ATRAC9 encoder for a fixture. Side finding, not changed here: this FFmpeg build has the fixed-point MP3 decoder, which outputs `S16P`. `RunMp3` in `libSceAjm.native` only accepts `FLTP` and throws otherwise, so AJM MP3 decoding probably always fails. Fixed in #237. ### Tested Linux (CachyOS, GCC): new `guest_audiodec` test (`core/libs/tests/GuestAudiodec.cpp`) with small fixtures generated by FFmpeg (1 kHz sine, 48 kHz): stereo AAC decoded both as ADTS and as raw blocks, checking bytes consumed and produced per frame, the reported format and the tone's zero-crossing rate; mono MP3 decoded to float, checking frame sizes, header fields and amplitude; ATRAC9 config parsing, BSI info and error paths; and the control block validation. It fails on injected bugs (no partial-input check, wrong raw sample-rate index, MP3 mode not reported, wrong S16P scaling). Full suite passes. Windows only through CI. No title tested. ### 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
github-actions[bot] commented 2026-10-01 17:38:10 +00:00 (Migrated from github.com)

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


Progress report (c00bc19 → 569c2ec)

📈 System libraries: 78.55% (+0.36%, +6 implemented, -6 removed functions)

✅ 6 implemented
Library Name
libSceAudiodec sceAudiodecClearContext
libSceAudiodec sceAudiodecCreateDecoder
libSceAudiodec sceAudiodecDecode
libSceAudiodec sceAudiodecDeleteDecoder
libSceAudiodec sceAudiodecInitLibrary
libSceAudiodec sceAudiodecTermLibrary
🗑️ 6 removed
Library Name
libSceAudiodec.native sceAudiodecClearContext
libSceAudiodec.native sceAudiodecCreateDecoder
libSceAudiodec.native sceAudiodecDecode
libSceAudiodec.native sceAudiodecDeleteDecoder
libSceAudiodec.native sceAudiodecInitLibrary
libSceAudiodec.native sceAudiodecTermLibrary
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5936989884 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/236#issuecomment-5936989884). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-01T17:38:10Z. --- <!-- progress-report --> ### Progress report (c00bc19 → 569c2ec) 📈 **System libraries**: 78.55% (+0.36%, +6 implemented, -6 removed functions) <details> <summary>✅ 6 implemented</summary> | Library | Name | | - | - | | libSceAudiodec | `sceAudiodecClearContext` | | libSceAudiodec | `sceAudiodecCreateDecoder` | | libSceAudiodec | `sceAudiodecDecode` | | libSceAudiodec | `sceAudiodecDeleteDecoder` | | libSceAudiodec | `sceAudiodecInitLibrary` | | libSceAudiodec | `sceAudiodecTermLibrary` | </details> <details> <summary>🗑️ 6 removed</summary> | Library | Name | | - | - | | libSceAudiodec.native | `sceAudiodecClearContext` | | libSceAudiodec.native | `sceAudiodecCreateDecoder` | | libSceAudiodec.native | `sceAudiodecDecode` | | libSceAudiodec.native | `sceAudiodecDeleteDecoder` | | libSceAudiodec.native | `sceAudiodecInitLibrary` | | libSceAudiodec.native | `sceAudiodecTermLibrary` | </details>
adriadam10 commented 2026-10-02 07:23:14 +00:00 (Migrated from github.com)

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


Following the review on #228/#241: libSceAudiodec.native no longer shares the sources. Its Export.cpp is now APS5_DUMMY_FUN only, like libkernel_sys, because all six of its exports are implemented in libSceAudiodec. AudiodecLibrary.cmake is gone. Rebased on main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5947319062 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/236#issuecomment-5947319062). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T07:23:14Z. --- Following the review on #228/#241: `libSceAudiodec.native` no longer shares the sources. Its `Export.cpp` is now `APS5_DUMMY_FUN` only, like `libkernel_sys`, because all six of its exports are implemented in `libSceAudiodec`. `AudiodecLibrary.cmake` is gone. Rebased on `main`.
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!236
No description provided.