fix(audioout): play every AudioOut2 port buffer set between pushes, one per grain #2536

Merged
orbz22 merged 1 commit from upstream-pr/2536 into main 2026-10-10 09:17:19 +00:00
orbz22 commented 2026-10-10 02:12:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-10T02:12:52Z.


What

An AudioOut2 port kept one PCM pointer: each sceAudioOut2PortSetAttributes with attribute 0 overwrote it, and every push mixed whatever it pointed to. Two things went wrong when a title does not set exactly one buffer per push:

  • Several buffers set between two pushes: all but the last were dropped.
  • A push without a new buffer: the last buffer was mixed again, every grain, until the port was given another one.

PPSA12544 (Hollow Knight: Silksong) feeds its gameplay sound through an object port (type 6, created in game). Each set points at the next grain of a 64-grain ring buffer (the pointer advances by exactly 256 frames, 2048 bytes, and wraps at 128 KiB). The sets arrive in bursts: often two or three between pushes, then none for one to four pushes. So most grains were lost, and the stale one was replayed 187.5 times a second. Players hear a harsh buzz on loud sounds and after a sound ends: the needle falling in the opening sequence, and fights.

This change:

  • Queue: buffers set between pushes are queued per port and mixed one per grain, in order, at most 16 queued (the oldest is dropped beyond that).
  • Push without a new buffer:
    • A port that has always been given the same buffer repeats it, as before. The title rewrites it in place, and audio_out2_timing relies on this: it points once and changes the contents between pushes.
    • A port whose buffers move on to other addresses plays silence for that grain.
  • TechnicalDebt records this under Unknown function info. The console's behaviour for several sets per push, and for a push without a new buffer, is not documented; this is inferred from PPSA12544.

Tested

Windows 11, WinLibs GCC 15.2, RTX 3060 Laptop.

  • New audio_out2_port_buffers (SDL disk driver, like audio_out2_port_layouts), four cases:

    • three buffers set before one push play in order over three grains;
    • a burst after a push plays in full, then the port stops;
    • a port whose buffer moved on plays silence when no new one is set;
    • a buffer rewritten in place repeats until the port is cleared.

    It fails on current main and passes with this change.

  • All seven audio_out* tests pass, including audio_out2_timing. tools/check_conventions.py --base upstream/main passes.

  • PPSA12544, measured on the final mix written to disk. main does not run the title on its own, so this ran on a local branch with the Silksong PRs (#1836, #1968, #1969, #846, #1599, #1495) and the same queue behind a switch.

    • Before: in 14 s around the needle scene, 212 sample jumps larger than 8x the local average step, 208 of them exactly on a 256-sample grain boundary. In 53% of the grains of the worst stretch, a grain was a copy of the previous one (correlation above 0.95).
    • After, over 51 s of the same scenes: 6 such jumps, 1 on a grain boundary, and no repeated grains among 1723 audible grains. Both ports are fed every grain (3760 port grains in 10 s, none empty). The buzz is gone by ear in the needle scene and the fights.

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 (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4807945333 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2536). Originally posted by [orbz22](https://github.com/orbz22) on 2026-10-10T02:12:52Z. --- ### What An AudioOut2 port kept one PCM pointer: each `sceAudioOut2PortSetAttributes` with attribute 0 overwrote it, and every push mixed whatever it pointed to. Two things went wrong when a title does not set exactly one buffer per push: - **Several buffers set between two pushes:** all but the last were dropped. - **A push without a new buffer:** the last buffer was mixed again, every grain, until the port was given another one. PPSA12544 (Hollow Knight: Silksong) feeds its gameplay sound through an object port (type 6, created in game). Each set points at the next grain of a 64-grain ring buffer (the pointer advances by exactly 256 frames, 2048 bytes, and wraps at 128 KiB). The sets arrive in bursts: often two or three between pushes, then none for one to four pushes. So most grains were lost, and the stale one was replayed 187.5 times a second. Players hear a harsh buzz on loud sounds and after a sound ends: the needle falling in the opening sequence, and fights. This change: - **Queue:** buffers set between pushes are queued per port and mixed one per grain, in order, at most 16 queued (the oldest is dropped beyond that). - **Push without a new buffer:** - A port that has always been given the same buffer repeats it, as before. The title rewrites it in place, and `audio_out2_timing` relies on this: it points once and changes the contents between pushes. - A port whose buffers move on to other addresses plays silence for that grain. - **TechnicalDebt** records this under Unknown function info. The console's behaviour for several sets per push, and for a push without a new buffer, is not documented; this is inferred from PPSA12544. ### Tested Windows 11, WinLibs GCC 15.2, RTX 3060 Laptop. - **New `audio_out2_port_buffers`** (SDL disk driver, like `audio_out2_port_layouts`), four cases: - three buffers set before one push play in order over three grains; - a burst after a push plays in full, then the port stops; - a port whose buffer moved on plays silence when no new one is set; - a buffer rewritten in place repeats until the port is cleared. It fails on current `main` and passes with this change. - **All seven `audio_out*` tests pass**, including `audio_out2_timing`. `tools/check_conventions.py --base upstream/main` passes. - **PPSA12544, measured on the final mix written to disk.** `main` does not run the title on its own, so this ran on a local branch with the Silksong PRs (#1836, #1968, #1969, #846, #1599, #1495) and the same queue behind a switch. - **Before:** in 14 s around the needle scene, 212 sample jumps larger than 8x the local average step, 208 of them exactly on a 256-sample grain boundary. In 53% of the grains of the worst stretch, a grain was a copy of the previous one (correlation above 0.95). - **After, over 51 s of the same scenes:** 6 such jumps, 1 on a grain boundary, and no repeated grains among 1723 audible grains. Both ports are fed every grain (3760 port grains in 10 s, none empty). The buzz is gone by ear in the needle scene and the fights. ### 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 (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-10 02:13:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T02:13:02Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092584628 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2536#issuecomment-6092584628). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T02:13:02Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
adriadam10 commented 2026-10-10 09:17:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T09:17:17Z.


Checked on the PR merged onto main: libSceAudioOut builds and all 7 audio_out* tests pass (including audio_out2_timing); audio_out2_port_buffers aborts without the source change and passes with it. The inferred queue/repeat behaviour is recorded under Unknown function info in TechnicalDebt; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096041233 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2536#issuecomment-6096041233). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T09:17:17Z. --- Checked on the PR merged onto `main`: libSceAudioOut builds and all 7 `audio_out*` tests pass (including `audio_out2_timing`); `audio_out2_port_buffers` aborts without the source change and passes with it. The inferred queue/repeat behaviour is recorded under Unknown function info in TechnicalDebt; merging.
orbz22 commented 2026-10-10 15:33:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-10T15:33:32Z.


Thanks for merging. A correction to my description: in PPSA12544, port 3 is type 6, which is AUDIO_OUT2_PORT_TYPE_PAD_VIBRATION in AudioOut2PadMix.hpp. It is not an object port. The buffers on it are the DualSense haptics waveform, not gameplay sound.

  • Why I heard it through the speakers: my build predated #2032. Without a DualSense USB audio device, every port went to the main mix, the vibration port included. On current main (be403084, plus #846 for the plugins) that port is dropped in this case. In a 250 s run through the opening and into Moss Grotto, only the main port (type 0) is mixed, and nothing reaches full scale: the peak is 0.35 after the master gain.
  • What the queue still does for this title: the change does not depend on the port type. It matters here when a DualSense is on USB and the vibration port plays on the controller. Without the queue, the controller would get the same stale grain 187.5 times a second. I have not tested that case.
  • TechnicalDebt: the line merged with this PR says "object port (type 6)". It should say "vibration port (type 6)". New PRs from me are closed by the intake rule, so I'm noting it here for whoever next edits that file.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099141675 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2536#issuecomment-6099141675). Originally posted by [orbz22](https://github.com/orbz22) on 2026-10-10T15:33:32Z. --- Thanks for merging. A correction to my description: in PPSA12544, port 3 is type 6, which is `AUDIO_OUT2_PORT_TYPE_PAD_VIBRATION` in `AudioOut2PadMix.hpp`. It is not an object port. The buffers on it are the DualSense haptics waveform, not gameplay sound. - **Why I heard it through the speakers:** my build predated #2032. Without a DualSense USB audio device, every port went to the main mix, the vibration port included. On current `main` (be403084, plus #846 for the plugins) that port is dropped in this case. In a 250 s run through the opening and into Moss Grotto, only the main port (type 0) is mixed, and nothing reaches full scale: the peak is 0.35 after the master gain. - **What the queue still does for this title:** the change does not depend on the port type. It matters here when a DualSense is on USB and the vibration port plays on the controller. Without the queue, the controller would get the same stale grain 187.5 times a second. I have not tested that case. - **TechnicalDebt:** the line merged with this PR says "object port (type 6)". It should say "vibration port (type 6)". New PRs from me are closed by the intake rule, so I'm noting it here for whoever next edits that file. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!2536
No description provided.