feat(opus): decode to float and with a priority in libSceOpusDec and libSceOpusCeltDec #9752

Merged
hypermoist merged 7 commits from upstream-pr/9752 into main 2026-10-26 11:39:24 +00:00
hypermoist commented 2026-10-22 12:41:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T12:41:18Z.


What

Eight decode exports of libSceOpusDec and libSceOpusCeltDec threw. In both modules every decode export is a wrapper around one worker, so these differ from the existing Decode only in a priority check, the float output and, for two of them, a timeout. This PR implements them on top of the existing decoder:

  • sceOpusDecDecodeWithPriority, sceOpusDecDecodeWithPriorityAndTimeout, sceOpusDecDecodeFloat, sceOpusDecDecodeFloatWithPriority, sceOpusDecDecodeFloatWithPriorityAndTimeout
  • sceOpusCeltDecDecodeWithPriority, sceOpusCeltDecDecodeFloat, sceOpusCeltDecDecodeFloatWithPriority

They follow the decrypted PS5 13.60 libSceOpusDec.sprx and libSceOpusCeltDec.sprx (read from disassembly, not measured on a console). Both workers sit at 0x550:

Part Behaviour
Arguments (state, data, bytes, pcm, capacity, priority). The AndTimeout exports add a uint32_t timeout, which goes to the AJM batch wait, and a uint32_t* that gets the batch ID only when that wait fails (0x734 to 0x743). Decode passes priority 40 and timeout -1.
Errors In order: null state +0, missing packet +6, negative size +7, null PCM +8, negative capacity +9, priority outside 20 to 100 +0xA (0x5b3), unknown state +1. The bases are 0x81740000 and 0x81400000. The priority check sits between checks Decode already makes, so Decode's own order does not change.
Float Decodes 16-bit PCM into capacity >> 2 samples of the caller's buffer (0x69f), then widens it in place: positive samples are divided by 32767, the rest by 32768 (constants at 0x46dc in OpusDec, 0x4324 in CeltDec). The result is the float byte count (0x8a6).

The variants are in a new include/OpusDecodeVariants.hpp, which both Export.cpp files call. OpusDecoder.hpp is unchanged.

Differences, listed in the new debt entry:

  • Decoding is synchronous, so the AndTimeout exports decode only for the infinite timeout 0xFFFFFFFF, the value Decode passes. The batch ID is then never written, as on the console when the wait succeeds. Any other timeout returns the argument errors and then throws (NotImplemented_nid_no_patch), because on the console it either succeeds or returns 0x81740015 with the batch ID, depending on how long the decode takes.
  • The priority is checked but schedules nothing.

Not included, still throwing:

  • sceOpusDecCtl and sceOpusCeltDecCtl. They are opus_decoder_ctl-style requests. The module stores each SET value in the state and sends it to AJM with the next decode, so they need a backend that applies gain, FEC and phase inversion. That fits after #8739.
  • sceOpusDecCancel. It cancels an AJM batch ID, and this decoder never hands one out.

The code is written from the observed behaviour; nothing from the modules is copied.

Tested

New guest_opus_dec_variants test. It checks:

  • the error order for each library, including priorities -1, 0, 19, 20, 40, 100, 101 and 255;
  • that the priority variants give the same PCM as Decode, over three frames;
  • that the float output equals the 16-bit output converted sample by sample, and that nothing is written past it;
  • the float capacity rule, including that a buffer one byte too small is left untouched;
  • that the timeout variants decode the same PCM at timeout 0xFFFFFFFF, return the argument errors at finite timeouts, and throw at timeouts 0, 1, 1000 and 0xFFFFFFFE without writing PCM or the batch ID.

Changing either float divisor or the lower priority bound makes it fail, and so does letting a finite timeout decode. On main all eight calls throw.

Run on main 7e69be6793 merged in (e879fbf700), head aff42e2c4b:

  • Linux (CachyOS, GCC 16.2.1, Release): guest_opus_dec_variants, guest_opus_dec and guest_opus_celt_dec pass.
  • Windows build: cross-built with WinLibs GCC 15.2.0 (the CI toolchain) and run under Wine 11.20; the same three tests pass.
  • Not run: a title.

tools/check_conventions.py is clean. Overlap:

  • #8739 rewrites OpusDecoder.hpp, the Functional entries of both debt files and the first 12 lines of both CMake files. This PR changes none of those lines: it adds a header, appends a test registration after line 16 of libSceOpusDec/CMakeLists.txt and edits the Unknown function info entries. tools/pr_overlap.py could not compare them automatically because #8739 conflicts with main.
  • #9764 (sceOpusDecCtl/sceOpusCeltDecCtl, also ours) conflicts with this PR in both Export.cpp files and both debt files. Merge order: this PR first, since #9764 also waits on #8739. #9764 declares Depends on: #8739, #9752 and will merge main and resolve the conflicts after this lands.
  • #6044 moves test registrations to add_library_test. Whichever of the two lands second converts the guest_opus_dec_variants registration: if #6044 lands first, I'll merge main here and switch it to add_library_test.

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 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 known
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01SNqSvnFwRBz3D76n476yw6

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4967516150 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9752). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-22T12:41:18Z. --- ### What Eight decode exports of `libSceOpusDec` and `libSceOpusCeltDec` threw. In both modules every decode export is a wrapper around one worker, so these differ from the existing `Decode` only in a priority check, the float output and, for two of them, a timeout. This PR implements them on top of the existing decoder: - `sceOpusDecDecodeWithPriority`, `sceOpusDecDecodeWithPriorityAndTimeout`, `sceOpusDecDecodeFloat`, `sceOpusDecDecodeFloatWithPriority`, `sceOpusDecDecodeFloatWithPriorityAndTimeout` - `sceOpusCeltDecDecodeWithPriority`, `sceOpusCeltDecDecodeFloat`, `sceOpusCeltDecDecodeFloatWithPriority` They follow the decrypted PS5 13.60 `libSceOpusDec.sprx` and `libSceOpusCeltDec.sprx` (read from disassembly, not measured on a console). Both workers sit at 0x550: | Part | Behaviour | |---|---| | Arguments | `(state, data, bytes, pcm, capacity, priority)`. The `AndTimeout` exports add a `uint32_t` timeout, which goes to the AJM batch wait, and a `uint32_t*` that gets the batch ID only when that wait fails (0x734 to 0x743). `Decode` passes priority 40 and timeout -1. | | Errors | In order: null state +0, missing packet +6, negative size +7, null PCM +8, negative capacity +9, priority outside 20 to 100 +0xA (0x5b3), unknown state +1. The bases are 0x81740000 and 0x81400000. The priority check sits between checks `Decode` already makes, so `Decode`'s own order does not change. | | Float | Decodes 16-bit PCM into `capacity >> 2` samples of the caller's buffer (0x69f), then widens it in place: positive samples are divided by 32767, the rest by 32768 (constants at 0x46dc in OpusDec, 0x4324 in CeltDec). The result is the float byte count (0x8a6). | The variants are in a new `include/OpusDecodeVariants.hpp`, which both `Export.cpp` files call. `OpusDecoder.hpp` is unchanged. Differences, listed in the new debt entry: - Decoding is synchronous, so the `AndTimeout` exports decode only for the infinite timeout 0xFFFFFFFF, the value `Decode` passes. The batch ID is then never written, as on the console when the wait succeeds. Any other timeout returns the argument errors and then throws (`NotImplemented_nid_no_patch`), because on the console it either succeeds or returns 0x81740015 with the batch ID, depending on how long the decode takes. - The priority is checked but schedules nothing. Not included, still throwing: - `sceOpusDecCtl` and `sceOpusCeltDecCtl`. They are `opus_decoder_ctl`-style requests. The module stores each SET value in the state and sends it to AJM with the next decode, so they need a backend that applies gain, FEC and phase inversion. That fits after #8739. - `sceOpusDecCancel`. It cancels an AJM batch ID, and this decoder never hands one out. The code is written from the observed behaviour; nothing from the modules is copied. ### Tested New `guest_opus_dec_variants` test. It checks: - the error order for each library, including priorities -1, 0, 19, 20, 40, 100, 101 and 255; - that the priority variants give the same PCM as `Decode`, over three frames; - that the float output equals the 16-bit output converted sample by sample, and that nothing is written past it; - the float capacity rule, including that a buffer one byte too small is left untouched; - that the timeout variants decode the same PCM at timeout 0xFFFFFFFF, return the argument errors at finite timeouts, and throw at timeouts 0, 1, 1000 and 0xFFFFFFFE without writing PCM or the batch ID. Changing either float divisor or the lower priority bound makes it fail, and so does letting a finite timeout decode. On `main` all eight calls throw. Run on `main` 7e69be6793 merged in (e879fbf700), head aff42e2c4b: - **Linux** (CachyOS, GCC 16.2.1, Release): `guest_opus_dec_variants`, `guest_opus_dec` and `guest_opus_celt_dec` pass. - **Windows build:** cross-built with WinLibs GCC 15.2.0 (the CI toolchain) and run under Wine 11.20; the same three tests pass. - **Not run:** a title. `tools/check_conventions.py` is clean. Overlap: - #8739 rewrites `OpusDecoder.hpp`, the Functional entries of both debt files and the first 12 lines of both CMake files. This PR changes none of those lines: it adds a header, appends a test registration after line 16 of `libSceOpusDec/CMakeLists.txt` and edits the Unknown function info entries. `tools/pr_overlap.py` could not compare them automatically because #8739 conflicts with `main`. - #9764 (`sceOpusDecCtl`/`sceOpusCeltDecCtl`, also ours) conflicts with this PR in both `Export.cpp` files and both debt files. Merge order: this PR first, since #9764 also waits on #8739. #9764 declares `Depends on: #8739, #9752` and will merge `main` and resolve the conflicts after this lands. - #6044 moves test registrations to `add_library_test`. Whichever of the two lands second converts the `guest_opus_dec_variants` registration: if #6044 lands first, I'll merge `main` here and switch it to `add_library_test`. ### 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 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 known - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01SNqSvnFwRBz3D76n476yw6
MarcZX10 commented 2026-10-22 14:53:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T14:53:01Z.

Review: CHANGES_REQUESTED


Local focused check: compiled and ran the exact OpusDecodeVariant helper with boundary samples (-32768, -1, 1, 32767), buffer guards, and undersized capacity; it passed. git diff --check and current-main conventions pass. I could not run guest_opus_dec_variants: this checkout has no Opus headers/submodule and less than 700 MB free, and hosted product Linux/Windows jobs are skipped.

I found a behavior gap in the timeout exports, plus required integration work. See the inline comment for the timeout behavior. The current branch is based on 8b3a6ba, 50 commits behind main b7d1d47; refresh it and rerun the focused Linux/Windows tests. Also agree and record the order for this PR and #9764, whose Opus exports and debt files have pairwise merge conflicts; #9764 already carries #8739. The CMake test registration also needs coordination with #6044's add_library_test migration. Update Depends on on whichever branch must land second/rebase first. No local semantic blocker found in the ordinary priority and float paths beyond the documented timeout mismatch.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5616184670 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9752#pullrequestreview-5616184670). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T14:53:01Z. **Review:** CHANGES_REQUESTED --- Local focused check: compiled and ran the exact `OpusDecodeVariant` helper with boundary samples (-32768, -1, 1, 32767), buffer guards, and undersized capacity; it passed. `git diff --check` and current-main conventions pass. I could not run `guest_opus_dec_variants`: this checkout has no Opus headers/submodule and less than 700 MB free, and hosted product Linux/Windows jobs are skipped. I found a behavior gap in the timeout exports, plus required integration work. See the inline comment for the timeout behavior. The current branch is based on `8b3a6ba`, 50 commits behind `main` `b7d1d47`; refresh it and rerun the focused Linux/Windows tests. Also agree and record the order for this PR and #9764, whose Opus exports and debt files have pairwise merge conflicts; #9764 already carries #8739. The CMake test registration also needs coordination with #6044's `add_library_test` migration. Update `Depends on` on whichever branch must land second/rebase first. No local semantic blocker found in the ordinary priority and float paths beyond the documented timeout mismatch.
MarcZX10 commented 2026-10-22 17:03:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T17:03:36Z.

Review: DISMISSED


The ordinary priority and float paths remain well supported by the reported Linux and WinLibs/Wine runs, but the timeout exports still discard the timeout and batch-ID parameters and report the synchronous decode result. The focused test explicitly exercises timeout 0 and expects the same completed PCM while asserting the batch ID remains untouched. The PR’s own disassembly notes say the console passes timeout to the AJM batch wait and writes the batch ID when that wait fails, so this does not establish equivalent behavior for a finite timeout. Please implement the timeout/batch-ID path or throw for timeout cases that cannot be modeled, with a test for the chosen contract.

Integration is also outstanding: this head is based on 8b3a6ba88d, 71 commits behind current main (11f976b27c16ed91633f00039dba5dfd97dd7cc1); current main includes the separate #9764 CTL implementation, whose exports overlap this branch. The PR still says Depends on: none, while #9764’s own dependency is #8739. Please coordinate and record a merge order, rebase both contributions as needed, and adapt the CMake registration to #6044’s test-registration migration. Current-main merge-tree, diff-check, and conventions pass. Hosted product jobs are skipped, and I did not run the Opus suite locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5617938012 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9752#pullrequestreview-5617938012). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T17:03:36Z. **Review:** DISMISSED --- The ordinary priority and float paths remain well supported by the reported Linux and WinLibs/Wine runs, but the timeout exports still discard the timeout and batch-ID parameters and report the synchronous decode result. The focused test explicitly exercises timeout 0 and expects the same completed PCM while asserting the batch ID remains untouched. The PR’s own disassembly notes say the console passes timeout to the AJM batch wait and writes the batch ID when that wait fails, so this does not establish equivalent behavior for a finite timeout. Please implement the timeout/batch-ID path or throw for timeout cases that cannot be modeled, with a test for the chosen contract. Integration is also outstanding: this head is based on `8b3a6ba88d`, 71 commits behind current `main` (`11f976b27c16ed91633f00039dba5dfd97dd7cc1`); current main includes the separate #9764 CTL implementation, whose exports overlap this branch. The PR still says `Depends on: none`, while #9764’s own dependency is #8739. Please coordinate and record a merge order, rebase both contributions as needed, and adapt the CMake registration to #6044’s test-registration migration. Current-main merge-tree, diff-check, and conventions pass. Hosted product jobs are skipped, and I did not run the Opus suite locally.
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!9752
No description provided.