feat(audio3d): implement the port queue #740

Merged
adriadam10 merged 2 commits from upstream-pr/740 into main 2026-10-05 23:40:57 +00:00
adriadam10 commented 2026-10-05 18:58:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T18:58:26Z.


What

Implements the libSceAudio3d port queue: sceAudio3dInitialize, sceAudio3dPortOpen, sceAudio3dPortClose, sceAudio3dPortSetAttribute, sceAudio3dPortGetQueueLevel, sceAudio3dPortAdvance, sceAudio3dPortPush.

Sources, per behaviour:

  • Validation order, error codes, port count: prosper (hle_audio_spatial.cpp), which reads them from the PS5 module: one port (id 0, a second open is OUT_OF_RESOURCES), NOT_READY before Initialize checked before the arguments, user id must be 0xFF, parameter sizes 0x20/0x28 exactly (no masking), 48 kHz only, granularity a multiple of 256, non-zero objects and depth, buffer mode ≤ 2, 2 or 3 beds; a failed open leaves *id untouched; Close/per-port calls return INVALID_PORT (0x80EA0002) for anything but the open port. Error values also match shadPS4's audio3d_error.h.
  • Queue and pacing: KytyPS5 (audio3d.cpp) and shadPS4 agree that a frame is queued by Advance, Push hands the queued frames over, and a blocking push (1) returns once a slot is free. Here each pushed frame plays for granularity / 48000 s (KytyPS5's data_delay), so the level drains at the port's rate and a blocking push actually paces the caller. prosper's port is a sink whose queue always reads empty and does not pace (it notes a title's audio thread spins on it); this follows KytyPS5 instead.
  • Attributes: the three ids KytyPS5 knows (0x10001 late reverb level, 0x10002 downmix spread radius, 0x10003 downmix spread height aware), size 4. They are accepted and have no effect (listed in Silent stubs).

Where the references disagree or say nothing, the call throws (listed under Unknown function info):

  • buffer modes 0/1 (and the 0x10/0x18 sizes that select them) and 3 beds: the module accepts them only behind an SDK version check (prosper);
  • repeated Initialize: NOT_READY in shadPS4, 0 in prosper;
  • Advance on a full queue: NOT_READY in shadPS4, unhandled in KytyPS5;
  • unknown attribute ids, attribute sizes other than 4, blocking modes other than 0/1.

The port produces no sound: AnyPS5's libSceAudio3d has no bed/object exports (BedWrite, ObjectReserve...) to feed it, so Push only paces. Listed in Silent stubs. sceAudio3dTerminate is not exported, so there is no Initialize/Terminate pair to complete.

Tested

Linux, GCC Release. New guest_audio3d_port (registered in ctest): every error path above (before/after Initialize, each rejected parameter with *id unchanged, the throwing cases, port 1, double close), queue levels through two Advance calls, a blocking push that waits at least one frame (6144-sample granularity = 128 ms) and returns with one free slot, an async push that does not wait, and the queue draining to empty at the port's rate. Fails on main (the stubs throw). Negative checks (each made the test fail): no sleep in blocking push, NOT_READY after the argument check, no OUT_OF_RESOURCES, frames never retired, rate not checked, no throw on a full queue, close not resetting the port, 3 beds accepted, attribute size not checked, reserved not checked, wrong port id written. guest_audio3d_parameters still passes.

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:4749540421 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/740). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T18:58:26Z. --- ### What Implements the libSceAudio3d port queue: `sceAudio3dInitialize`, `sceAudio3dPortOpen`, `sceAudio3dPortClose`, `sceAudio3dPortSetAttribute`, `sceAudio3dPortGetQueueLevel`, `sceAudio3dPortAdvance`, `sceAudio3dPortPush`. Sources, per behaviour: - **Validation order, error codes, port count**: [prosper](https://github.com/mattias800/prosper) (`hle_audio_spatial.cpp`), which reads them from the PS5 module: one port (id 0, a second open is `OUT_OF_RESOURCES`), `NOT_READY` before `Initialize` checked before the arguments, user id must be `0xFF`, parameter sizes 0x20/0x28 exactly (no masking), 48 kHz only, granularity a multiple of 256, non-zero objects and depth, buffer mode ≤ 2, 2 or 3 beds; a failed open leaves `*id` untouched; `Close`/per-port calls return `INVALID_PORT` (0x80EA0002) for anything but the open port. Error values also match shadPS4's `audio3d_error.h`. - **Queue and pacing**: KytyPS5 (`audio3d.cpp`) and shadPS4 agree that a frame is queued by `Advance`, `Push` hands the queued frames over, and a blocking push (`1`) returns once a slot is free. Here each pushed frame plays for `granularity / 48000` s (KytyPS5's `data_delay`), so the level drains at the port's rate and a blocking push actually paces the caller. prosper's port is a sink whose queue always reads empty and does not pace (it notes a title's audio thread spins on it); this follows KytyPS5 instead. - **Attributes**: the three ids KytyPS5 knows (`0x10001` late reverb level, `0x10002` downmix spread radius, `0x10003` downmix spread height aware), size 4. They are accepted and have no effect (listed in Silent stubs). Where the references disagree or say nothing, the call throws (listed under Unknown function info): - buffer modes 0/1 (and the 0x10/0x18 sizes that select them) and 3 beds: the module accepts them only behind an SDK version check (prosper); - repeated `Initialize`: `NOT_READY` in shadPS4, 0 in prosper; - `Advance` on a full queue: `NOT_READY` in shadPS4, unhandled in KytyPS5; - unknown attribute ids, attribute sizes other than 4, blocking modes other than 0/1. The port produces no sound: AnyPS5's libSceAudio3d has no bed/object exports (`BedWrite`, `ObjectReserve`...) to feed it, so `Push` only paces. Listed in Silent stubs. `sceAudio3dTerminate` is not exported, so there is no Initialize/Terminate pair to complete. ### Tested Linux, GCC Release. New `guest_audio3d_port` (registered in ctest): every error path above (before/after `Initialize`, each rejected parameter with `*id` unchanged, the throwing cases, port 1, double close), queue levels through two `Advance` calls, a blocking push that waits at least one frame (6144-sample granularity = 128 ms) and returns with one free slot, an async push that does not wait, and the queue draining to empty at the port's rate. Fails on `main` (the stubs throw). Negative checks (each made the test fail): no sleep in blocking push, `NOT_READY` after the argument check, no `OUT_OF_RESOURCES`, frames never retired, rate not checked, no throw on a full queue, close not resetting the port, 3 beds accepted, attribute size not checked, reserved not checked, wrong port id written. `guest_audio3d_parameters` still passes. ### 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 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-05 18:59:54 +00:00 (Migrated from github.com)

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


Progress report (bc24783 → 42869ef)

📈 System libraries: 79.75% (+0.21%, +7 implemented functions)

✅ 7 implemented
Library Name
libSceAudio3d sceAudio3dInitialize
libSceAudio3d sceAudio3dPortAdvance
libSceAudio3d sceAudio3dPortClose
libSceAudio3d sceAudio3dPortGetQueueLevel
libSceAudio3d sceAudio3dPortOpen
libSceAudio3d sceAudio3dPortPush
libSceAudio3d sceAudio3dPortSetAttribute
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6001103456 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/740#issuecomment-6001103456). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T18:59:54Z. --- <!-- progress-report --> ### Progress report (bc24783 → 42869ef) 📈 **System libraries**: 79.75% (+0.21%, +7 implemented functions) <details> <summary>✅ 7 implemented</summary> | Library | Name | | - | - | | libSceAudio3d | `sceAudio3dInitialize` | | libSceAudio3d | `sceAudio3dPortAdvance` | | libSceAudio3d | `sceAudio3dPortClose` | | libSceAudio3d | `sceAudio3dPortGetQueueLevel` | | libSceAudio3d | `sceAudio3dPortOpen` | | libSceAudio3d | `sceAudio3dPortPush` | | libSceAudio3d | `sceAudio3dPortSetAttribute` | </details>
oneandonlydean commented 2026-10-05 20:30:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T20:30:21Z.


Thanks for this. The Windows job fails in the new test (run 37359993426): guest_audio3d_port aborts at "blocking push returns with one free slot", right after the blocking sceAudio3dPortPush.

The elapsed-time check just before it allows 2 ms of slack, but the level check doesn't, so the push most likely returned a little before wait_until. For a steady clock, libstdc++'s sleep_until calls sleep_for once and doesn't check the time again, and the Windows sleep can come back slightly early. In that case the first frame is still in playing and the level is still full, which a title would see too, not only the test. Looping until Clock::now() >= wait_until in sceAudio3dPortPush should fix both.

The rest looks good to me: Linux passes, the test fails on main's code, and the unsupported modes and attributes throw.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6002367921 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/740#issuecomment-6002367921). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T20:30:21Z. --- Thanks for this. The Windows job fails in the new test ([run 37359993426](https://github.com/boykopovar/AnyPS5/actions/runs/37359993426/job/111931905157)): `guest_audio3d_port` aborts at "blocking push returns with one free slot", right after the blocking `sceAudio3dPortPush`. The elapsed-time check just before it allows 2 ms of slack, but the level check doesn't, so the push most likely returned a little before `wait_until`. For a steady clock, libstdc++'s `sleep_until` calls `sleep_for` once and doesn't check the time again, and the Windows sleep can come back slightly early. In that case the first frame is still in `playing` and the level is still full, which a title would see too, not only the test. Looping until `Clock::now() >= wait_until` in `sceAudio3dPortPush` should fix both. The rest looks good to me: Linux passes, the test fails on main's code, and the unsupported modes and attributes throw.
adriadam10 commented 2026-10-05 22:28:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T22:28:37Z.


Thanks, that's it. sceAudio3dPortPush now loops on Clock::now() < wait_until around sleep_until, so a blocking push never returns before the slot frees. Rebased on current main; guest_audio3d_port and guest_audio3d_parameters pass (5 runs in a row, Linux).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6004454647 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/740#issuecomment-6004454647). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T22:28:37Z. --- Thanks, that's it. `sceAudio3dPortPush` now loops on `Clock::now() < wait_until` around `sleep_until`, so a blocking push never returns before the slot frees. Rebased on current `main`; `guest_audio3d_port` and `guest_audio3d_parameters` pass (5 runs in a row, Linux).
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!740
No description provided.