feat(opusdec): implement sceOpusDecCtl and sceOpusCeltDecCtl #9764

Merged
hypermoist merged 14 commits from upstream-pr/9764 into main 2026-11-02 07:58:26 +00:00
hypermoist commented 2026-10-22 13:28:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T13:28:15Z.


What

sceOpusDecCtl and sceOpusCeltDecCtl threw. They take opus_decoder_ctl-style requests: the module stores each value in the decoder state and sends it to AJM with the next decode. It uses the libopus backend from #8739, now on main. It handles the requests and applies gain and phase inversion to libopus.

The behaviour is not measured on a console. The request numbers match libopus's CTLs. @BunnyFl ran the firmware 13.42 libSceOpusDec.sprx and libSceOpusCeltDec.sprx natively on a PC with AJM stubbed (report); the checks, errors, initial values, stored values and reset below match it.

Request Behaviour
Checks In order: null state +0, unknown state +1, any request outside 4012 to 4051 other than -1 +0xE. A GET with a null output +0xD. The bases are 0x81740000 and 0x81400000.
4028 RESET_STATE Zeroes the stored FEC, gain, 4050 flag and phase inversion, and resets the decoder. The sample rate and the final range are kept.
4029, 4031 Return the sample rate and the final range of the last decode.
4034 / 4045 GAIN Accepts the int16 range only, otherwise +0xC.
4046 / 4047 PHASE_INVERSION_DISABLED Accepts 0 or 1, compared unsigned. Otherwise +0x1B in OpusDec, +0x11 in CeltDec.
4012 / 4013 INBAND_FEC OpusDec only. Accepts 0 or 1, otherwise +0x10.
4050 / 4051 OpusDec only. A flag with no libopus counterpart. 0 or 1 is stored and read back, compared unsigned; otherwise +0x11.
-1 Both pointers are checked (+0xD); the request returns AJM result words. Before the first decode it writes 0 to both and returns 0.

CeltDec rejects 4012, 4013, 4050 and 4051 with +0xE.

The export reads its variadic arguments with the SysV va_list on Windows, each with the type the caller passes: an int for a setter, an int32_t* for a getter and two for request -1, and none for the reset and unknown requests. The handling is one Ctl in OpusDecoder.hpp that both modules share.

Differences, listed in the new debt entries:

  • Request -1 throws after a decode, because the host decoder has no AJM result words.
  • Decoding with 4050 set to 1 throws, because its effect is unknown.
  • In-band FEC is stored but only matters for packet loss concealment, which still throws.
  • That AJM applies gain and reports the final range the same way libopus does is not measured.

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

Tested

New guest_opus_dec_ctl test, run for both libraries. It checks:

  • every error above and the order of the first two;

  • GET and SET round trips, the gain and flag bounds, and what reset clears and keeps;

  • that the PCM and final range match a plain libopus decoder over CELT-only stereo packets, before and after setting gain -1536 and disabling phase inversion, and that the gain changes the output;

  • that after a reset the output matches a fresh decoder.

  • request -1 writing 0 to both outputs before a decode, and 4050 set to 1 reading back as 1 and cleared by reset;

  • every request BunnyFl measured as +0xE, and the INT32_MIN/INT32_MAX gain and phase inversion bounds.

The test does not assert that the unsupported paths (request -1 after a decode, decoding with 4050 set) throw.

  • Linux (CachyOS, GCC 16.2.1, Release): guest_opus_dec_ctl, guest_opus_dec and guest_opus_celt_dec pass. At 8f2335b92f all six ctest -R opus tests pass.
  • Windows build: cross-built with WinLibs GCC 15.2.0 (the release the Windows job uses) and run under Wine 11.20; the same three tests pass (before f8018a068; not rerun since).
  • Not run: a title.

tools/check_conventions.py is clean. Overlap:

  • #9752 (also mine) touches the same #include line in both Export.cpp files, line 16 of libSceOpusDec/CMakeLists.txt and line 5 of both debt files, where each PR removes its own names. Merge order: #9752 first. Once #9752 lands I'll merge main here and resolve those lines.
  • #6044 moves test registrations to add_library_test. Whichever of the two lands second converts the guest_opus_dec_ctl registration: if #6044 lands first, I'll merge main here and switch it.

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: #9752
  • Fixes: none
  • Unblocks: none known
  • GPUs tested: n/a
  • AI-assisted: yes

Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4968187337 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9764). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-22T13:28:15Z. --- ### What `sceOpusDecCtl` and `sceOpusCeltDecCtl` threw. They take `opus_decoder_ctl`-style requests: the module stores each value in the decoder state and sends it to AJM with the next decode. It uses the libopus backend from #8739, now on `main`. It handles the requests and applies gain and phase inversion to libopus. The behaviour is not measured on a console. The request numbers match libopus's CTLs. @BunnyFl ran the firmware 13.42 `libSceOpusDec.sprx` and `libSceOpusCeltDec.sprx` natively on a PC with AJM stubbed ([report](https://github.com/boykopovar/AnyPS5/pull/9764#issuecomment-6412392825)); the checks, errors, initial values, stored values and reset below match it. | Request | Behaviour | |---|---| | Checks | In order: null state +0, unknown state +1, any request outside 4012 to 4051 other than -1 +0xE. A GET with a null output +0xD. The bases are 0x81740000 and 0x81400000. | | 4028 `RESET_STATE` | Zeroes the stored FEC, gain, 4050 flag and phase inversion, and resets the decoder. The sample rate and the final range are kept. | | 4029, 4031 | Return the sample rate and the final range of the last decode. | | 4034 / 4045 `GAIN` | Accepts the int16 range only, otherwise +0xC. | | 4046 / 4047 `PHASE_INVERSION_DISABLED` | Accepts 0 or 1, compared unsigned. Otherwise +0x1B in OpusDec, +0x11 in CeltDec. | | 4012 / 4013 `INBAND_FEC` | OpusDec only. Accepts 0 or 1, otherwise +0x10. | | 4050 / 4051 | OpusDec only. A flag with no libopus counterpart. 0 or 1 is stored and read back, compared unsigned; otherwise +0x11. | | -1 | Both pointers are checked (+0xD); the request returns AJM result words. Before the first decode it writes 0 to both and returns 0. | CeltDec rejects 4012, 4013, 4050 and 4051 with +0xE. The export reads its variadic arguments with the SysV `va_list` on Windows, each with the type the caller passes: an `int` for a setter, an `int32_t*` for a getter and two for request -1, and none for the reset and unknown requests. The handling is one `Ctl` in `OpusDecoder.hpp` that both modules share. Differences, listed in the new debt entries: - Request -1 throws after a decode, because the host decoder has no AJM result words. - Decoding with 4050 set to 1 throws, because its effect is unknown. - In-band FEC is stored but only matters for packet loss concealment, which still throws. - That AJM applies gain and reports the final range the same way libopus does is not measured. The code is written from the observed behaviour; nothing from the modules is copied. ### Tested New `guest_opus_dec_ctl` test, run for both libraries. It checks: - every error above and the order of the first two; - GET and SET round trips, the gain and flag bounds, and what reset clears and keeps; - that the PCM and final range match a plain libopus decoder over CELT-only stereo packets, before and after setting gain -1536 and disabling phase inversion, and that the gain changes the output; - that after a reset the output matches a fresh decoder. - request -1 writing 0 to both outputs before a decode, and 4050 set to 1 reading back as 1 and cleared by reset; - every request BunnyFl measured as +0xE, and the `INT32_MIN`/`INT32_MAX` gain and phase inversion bounds. The test does not assert that the unsupported paths (request -1 after a decode, decoding with 4050 set) throw. - **Linux** (CachyOS, GCC 16.2.1, Release): `guest_opus_dec_ctl`, `guest_opus_dec` and `guest_opus_celt_dec` pass. At 8f2335b92f all six `ctest -R opus` tests pass. - **Windows build:** cross-built with WinLibs GCC 15.2.0 (the release the Windows job uses) and run under Wine 11.20; the same three tests pass (before f8018a068; not rerun since). - **Not run:** a title. `tools/check_conventions.py` is clean. Overlap: - #9752 (also mine) touches the same `#include` line in both `Export.cpp` files, line 16 of `libSceOpusDec/CMakeLists.txt` and line 5 of both debt files, where each PR removes its own names. Merge order: #9752 first. Once #9752 lands I'll merge `main` here and resolve those lines. - #6044 moves test registrations to `add_library_test`. Whichever of the two lands second converts the `guest_opus_dec_ctl` registration: if #6044 lands first, I'll merge `main` here and switch it. ### 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: #9752 - [x] Fixes: none - [x] Unblocks: none known - [x] GPUs tested: n/a - [x] AI-assisted: yes Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.
MarcZX10 commented 2026-10-22 14:47:40 +00:00 (Migrated from github.com)

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

Review: DISMISSED


I found one blocker in the variadic argument bridge. The focused review and checks are summarized in the inline comment; the same extraction is duplicated in the CeltDec export.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5616109308 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9764#pullrequestreview-5616109308). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T14:47:40Z. **Review:** DISMISSED --- I found one blocker in the variadic argument bridge. The focused review and checks are summarized in the inline comment; the same extraction is duplicated in the CeltDec export.
MarcZX10 commented 2026-10-22 17:01:30 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Thanks for fixing the variadic argument-type mismatch. I verified the shared ReadCtlArguments dispatch now reads promoted int setters, typed int32_t* getters, both pointers for request -1, and consumes no argument for reset/unknown requests; both decoder exports use it. Current-main conventions, diff-check, and merge-tree pass. The author reports fresh Linux and WinLibs/Wine runs of guest_opus_dec_ctl, guest_opus_dec, and guest_opus_celt_dec; hosted product builds are skipped, and I did not rerun them locally. The PR correctly declares dependency #8739 and documents the #9752 rebase coordination; no remaining blocker found in the reviewed change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5617913611 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9764#pullrequestreview-5617913611). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T17:01:30Z. **Review:** COMMENTED --- Thanks for fixing the variadic argument-type mismatch. I verified the shared `ReadCtlArguments` dispatch now reads promoted `int` setters, typed `int32_t*` getters, both pointers for request `-1`, and consumes no argument for reset/unknown requests; both decoder exports use it. Current-main conventions, diff-check, and merge-tree pass. The author reports fresh Linux and WinLibs/Wine runs of `guest_opus_dec_ctl`, `guest_opus_dec`, and `guest_opus_celt_dec`; hosted product builds are skipped, and I did not rerun them locally. The PR correctly declares dependency #8739 and documents the #9752 rebase coordination; no remaining blocker found in the reviewed change.
BunnyFl commented 2026-10-28 15:06:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-10-28T15:06:56Z.

Review: APPROVED


Approving head 8f2335b92f. I read the whole diff and re-ran its Export.cpp files and OpusDecoder.hpp (built with AnyPS5's libopus) next to firmware 13.42's decrypted libSceOpusDec.sprx and libSceOpusCeltDec.sprx, natively on a PC (not a console), same AJM stubs and fresh states as before. Three identical runs.

  • All eleven sequences match in both libraries, including the new one: SET 4050 1, reset, then GET 4051 returns 0 here as on the module.
  • The five one-change copies of OpusDecoder.hpp (gain bound, phase-inversion code, unknown-request code, NULL-GET code, FEC bound) are each caught.
  • The test now expects 0 from GET 4051 after reset, the debt entry says "stored until reset", and the ...WithPriorityAndTimeout entry is back to main's wording.
  • Hosted Windows, conventions, eligibility, labels and report pass on this head.

Still not compared: decoding, so the gain and phase inversion effect on PCM, the final range after a decode and request -1 after a decode stay as the debt entry lists them.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5684897555 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9764#pullrequestreview-5684897555). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-10-28T15:06:56Z. **Review:** APPROVED --- Approving head `8f2335b92f`. I read the whole diff and re-ran its `Export.cpp` files and `OpusDecoder.hpp` (built with AnyPS5's libopus) next to firmware 13.42's decrypted `libSceOpusDec.sprx` and `libSceOpusCeltDec.sprx`, natively on a PC (not a console), same AJM stubs and fresh states as before. Three identical runs. - All eleven sequences match in both libraries, including the new one: `SET 4050 1`, reset, then GET 4051 returns 0 here as on the module. - The five one-change copies of `OpusDecoder.hpp` (gain bound, phase-inversion code, unknown-request code, NULL-GET code, FEC bound) are each caught. - The test now expects 0 from GET 4051 after reset, the debt entry says "stored until reset", and the `...WithPriorityAndTimeout` entry is back to `main`'s wording. - Hosted Windows, conventions, eligibility, labels and report pass on this head. Still not compared: decoding, so the gain and phase inversion effect on PCM, the final range after a decode and request -1 after a decode stay as the debt entry lists them.
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!9764
No description provided.