fix(audio): preserve completed AudioOut2 grains across threads #5198

Merged
eljackjoestar-cmd merged 1 commit from upstream-pr/5198 into main 2026-10-14 18:22:51 +00:00
eljackjoestar-cmd commented 2026-10-13 14:23:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eljackjoestar-cmd on 2026-10-13T14:23:21Z.


What

Lost Soul Aside (PPSA26358) rewrites the same 512-frame, 12-channel float PCM buffer on its producer thread, calls sceAudioOut2ContextAdvance, and pushes from another thread. Advance previously did nothing; Push retained the borrowed pointer and read it on the next Push. This read repeated or partially rewritten buffers, causing startup crackles.

Snapshot PCM and gain at Advance and consume completed grains in order at Push. A blocking Push waits for the producer when no completed grain is available. Callers that never Advance keep their existing deferred-buffer behavior. Snapshot timing is inferred from the title, not measured on console hardware; the ownership and error-code gaps are recorded in audio debt. Unsupported empty nonblocking pushes and more than 16 outstanding completed grains throw.

Tested

Rebased onto main 84b01f9cd042e1d2e9e112f8783aa5a9d26399ee on 2026-10-14; PR head bb4ec482d2868af3f6bbe3ecd9eee03b10e9cbd2. Standalone branch verification (this PR alone), Windows 11 Pro 10.0.26300, WinLibs GCC 15.2, Release, SPIRV-Tools OFF: runtime and selected native test targets built successfully. All 11 focused tests passed without skips in 10.58 s. Conventions and whitespace checks passed. The conflict resolution retains main's controller-audio routing, including the main-output route for pad speakers when no pad device is selected, while retaining the captured PCM and gain. No new title/gameplay run, Linux, full-suite or CI result is claimed.

Earlier validation, on the bases stated below:
Windows 11, Ryzen 7 7800X3D, RTX 5070, WinLibs GCC 15.2, Release.

Standalone build: current main 759c66564f0890541ca0e59afd89ed686ed64ec9 plus this PR alone. Full Windows build passes. All 10 audio_out* tests pass without skips in 9.66 s. Conventions and whitespace checks pass.

The new native regressions check reuse of one mutable PCM buffer, volume changes between Advance and Push, and a pushing thread waiting for the producer. With the new tests retained but all three runtime files restored to main 91ed4ce62 (audio files byte-identical to 759c66564), audio_out2_port_buffers fails; restoring the fix passes. Existing no-Advance buffer, timing, routing and layout checks remain included.

Separate game A/B: the same playable integration based on main 5b083445852c3dc2a02231f97b6f2c254c39791b, with identical rendering/memory fixes, differing in this audio fix. Bounded in-memory instrumentation captured 43.69 seconds of generated stereo float input before SDL output per run:

Measurement Baseline Fixed
Repeated adjacent non-silent 512-frame blocks 1,083 / 3,067 (35.31%) 0 / 3,068 (0%)
Block-boundary jumps larger than 0.03 86 0
Nonfinite samples 0 0

The tester confirmed startup/title audio sounds clean. The temporary probes are absent from this PR. These are generated-input measurements, not a host loopback recording or a clean-main title run. Complete gameplay, console semantics, Linux and CI are not claimed.

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 added to code
  • Unimplemented paths throw; inferred behavior and remaining gaps are documented in technical debt
  • No investigation files, recordings, logs, game assets or images added to the repository
  • No third-party code added
  • Generic behavior, not specific to one title
  • Depends on: none
  • Unblocks: PPSA26358 #4401 (startup/title audio crackles)
  • GPUs tested: n/a (audio change; title A/B hardware listed above)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4844694801 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5198). Originally posted by [eljackjoestar-cmd](https://github.com/eljackjoestar-cmd) on 2026-10-13T14:23:21Z. --- ### What Lost Soul Aside (PPSA26358) rewrites the same 512-frame, 12-channel float PCM buffer on its producer thread, calls `sceAudioOut2ContextAdvance`, and pushes from another thread. Advance previously did nothing; Push retained the borrowed pointer and read it on the next Push. This read repeated or partially rewritten buffers, causing startup crackles. Snapshot PCM and gain at Advance and consume completed grains in order at Push. A blocking Push waits for the producer when no completed grain is available. Callers that never Advance keep their existing deferred-buffer behavior. Snapshot timing is inferred from the title, not measured on console hardware; the ownership and error-code gaps are recorded in audio debt. Unsupported empty nonblocking pushes and more than 16 outstanding completed grains throw. ### Tested Rebased onto main `84b01f9cd042e1d2e9e112f8783aa5a9d26399ee` on 2026-10-14; PR head `bb4ec482d2868af3f6bbe3ecd9eee03b10e9cbd2`. Standalone branch verification (this PR alone), Windows 11 Pro 10.0.26300, WinLibs GCC 15.2, Release, SPIRV-Tools OFF: runtime and selected native test targets built successfully. All 11 focused tests passed without skips in 10.58 s. Conventions and whitespace checks passed. The conflict resolution retains main's controller-audio routing, including the main-output route for pad speakers when no pad device is selected, while retaining the captured PCM and gain. No new title/gameplay run, Linux, full-suite or CI result is claimed. Earlier validation, on the bases stated below: Windows 11, Ryzen 7 7800X3D, RTX 5070, WinLibs GCC 15.2, Release. Standalone build: current main `759c66564f0890541ca0e59afd89ed686ed64ec9` plus this PR alone. Full Windows build passes. All 10 `audio_out*` tests pass without skips in 9.66 s. Conventions and whitespace checks pass. The new native regressions check reuse of one mutable PCM buffer, volume changes between Advance and Push, and a pushing thread waiting for the producer. With the new tests retained but all three runtime files restored to main `91ed4ce62` (audio files byte-identical to `759c66564`), `audio_out2_port_buffers` fails; restoring the fix passes. Existing no-Advance buffer, timing, routing and layout checks remain included. Separate game A/B: the same playable integration based on main `5b083445852c3dc2a02231f97b6f2c254c39791b`, with identical rendering/memory fixes, differing in this audio fix. Bounded in-memory instrumentation captured 43.69 seconds of generated stereo float input before SDL output per run: | Measurement | Baseline | Fixed | | --- | ---: | ---: | | Repeated adjacent non-silent 512-frame blocks | 1,083 / 3,067 (35.31%) | 0 / 3,068 (0%) | | Block-boundary jumps larger than 0.03 | 86 | 0 | | Nonfinite samples | 0 | 0 | The tester confirmed startup/title audio sounds clean. The temporary probes are absent from this PR. These are generated-input measurements, not a host loopback recording or a clean-main title run. Complete gameplay, console semantics, Linux and CI are not claimed. ### 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 added to code - [x] Unimplemented paths throw; inferred behavior and remaining gaps are documented in technical debt - [x] No investigation files, recordings, logs, game assets or images added to the repository - [x] No third-party code added - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA26358 [#4401](https://github.com/boykopovar/AnyPS5/discussions/4401) (startup/title audio crackles) - [x] GPUs tested: n/a (audio change; title A/B hardware listed above) - [x] AI-assisted: yes
xXPBSXx commented 2026-10-13 14:56:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T14:56:46Z.


Windows test: head 79dae11d1 merged onto current main ef42c5f2a, together with 9 other open pull requests in one build (the merges were conflict-free); a failure would have been bisected per PR. Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest for the tests this change adds or touches: audio_out2_port_buffers passed; python tools/check_conventions.py --base upstream/main passed for the combined tree. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148438493 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5198#issuecomment-6148438493). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T14:56:46Z. --- Windows test: head `79dae11d1` merged onto current `main` `ef42c5f2a`, together with 9 other open pull requests in one build (the merges were conflict-free); a failure would have been bisected per PR. Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j2`: full build 0 errors; ctest for the tests this change adds or touches: audio_out2_port_buffers passed; `python tools/check_conventions.py --base upstream/main` passed for the combined tree. I did not run the new tests against `main` without the change. AI-assisted (Claude Code).
coltken95 commented 2026-10-13 18:47:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T18:47:42Z.


Tested on Linux x86-64 (Release build), with 79dae11d1 merged into main 9d0a41d5a:

  • With the PR: audio_out2_port_buffers passes.
  • With main's sources and the PR's test: audio_out2_port_buffers aborts.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152728581 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5198#issuecomment-6152728581). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-13T18:47:42Z. --- Tested on Linux x86-64 (Release build), with 79dae11d1 merged into main 9d0a41d5a: - With the PR: `audio_out2_port_buffers` passes. - With main's sources and the PR's test: `audio_out2_port_buffers` aborts. AI-assisted: yes (Claude Code)
github-actions[bot] commented 2026-10-14 17:49:08 +00:00 (Migrated from github.com)

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


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3607 docs/dev/debt/libSceAudioOut.md L4-5
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6174688726 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5198#issuecomment-6174688726). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T17:49:08Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #3607 | `docs/dev/debt/libSceAudioOut.md` [L4-5](https://github.com/boykopovar/AnyPS5/blob/f25386b90b285ef264fa1e3fa6540e047e364bbf/docs/dev/debt/libSceAudioOut.md#L4-L5) | | |
adriadam10 commented 2026-10-14 18:00:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T18:00:39Z.


Checked the Advance/Push grain snapshot (PCM + gain), the blocking wait, the no-Advance fallback and the debt entry. Linux build and audio_out2_port_buffers pass, and the test fails with the runtime changes reverted. The third-party Windows and Linux runs above agree; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6174902554 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5198#issuecomment-6174902554). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T18:00:39Z. --- Checked the Advance/Push grain snapshot (PCM + gain), the blocking wait, the no-Advance fallback and the debt entry. Linux build and `audio_out2_port_buffers` pass, and the test fails with the runtime changes reverted. The third-party Windows and Linux runs above agree; merging.
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!5198
No description provided.