audio: stop AudioOut2 contexts from stalling each other (PPSA09809) #1745

Manually merged
github merged 1 commit from gh-pr/1745/head into gh-pr/1745/base 2026-11-26 10:04:29 +00:00
Owner

@⁠MrBigBritches on GitHub · 2026-10-20 02:48 UTC · original
MrBigBritches:octopath-fixes → main · +118 −19 · 2 files · 1 commits · merged 2026-10-22 00:52 UTC

audioout2_queue_context_audio held the global AudioOut2 state mutex across AudioOutOutputs, which sleeps while pacing a blocking push. Titles with several contexts on separate threads (Octopath Traveler II: CRI ADX + Unreal AudioMixer, 2 x 256-sample grains) serialized on it, along with every PortSetAttributes/GetQueueLevel call, causing heavy stutter. Snapshot the PCM under the state mutex and submit outside it; a shared_mutex keeps backend handles alive until submission finishes.

Also:

  • Derive the AudioOut2 queue level from the host device's queued frames (plus a 40 ms cushion) instead of a wall-clock model.
  • Count underruns on async SDL submissions and cap their latency.
  • Log per-context push rate and device queue every 5 s.

Co-Authored-By: Claude Opus 5.5 [email protected]

Partial Fix: #1617

**@⁠MrBigBritches** on GitHub · 2026-10-20 02:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1745) `MrBigBritches:octopath-fixes` → `main` · +118 −19 · 2 files · 1 commits · merged 2026-10-22 00:52 UTC audioout2_queue_context_audio held the global AudioOut2 state mutex across AudioOutOutputs, which sleeps while pacing a blocking push. Titles with several contexts on separate threads (Octopath Traveler II: CRI ADX + Unreal AudioMixer, 2 x 256-sample grains) serialized on it, along with every PortSetAttributes/GetQueueLevel call, causing heavy stutter. Snapshot the PCM under the state mutex and submit outside it; a shared_mutex keeps backend handles alive until submission finishes. Also: - Derive the AudioOut2 queue level from the host device's queued frames (plus a 40 ms cushion) instead of a wall-clock model. - Count underruns on async SDL submissions and cap their latency. - Log per-context push rate and device queue every 5 s. Co-Authored-By: Claude Opus 5.5 <[email protected]> Partial Fix: https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1617
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:04:26 +00:00
github manually merged commit 392966bf34 into gh-pr/1745/base 2026-11-26 10:04:29 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-20 02:54 UTC · original · edited 2026-10-22 00:51 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bc61a3a6-09f2-436a-b390-eb84b62c2244
📥 Commits

Reviewing files that changed from the base of the PR and between 903861cba9f96dd5f22c0b285fdb4eb08a2f1ded and 392966bf34.

📒 Files selected for processing: 2
  • src/libs/libAudio2.cpp
  • tests/AudioOut2PortTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

Audio queueing now stores each context’s PCM, gain, and object mix data in dedicated submission storage. It releases the global state mutex before backend output. Context and port destruction wait for in-flight submissions before closing audio handles. A new test checks cross-context progress, stable submission data, and concurrent destruction while output is blocked.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 39296

No outstanding audio submission issue is established; the PR is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 3.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preventing AudioOut2 contexts from stalling each other.
Description check Passed The description directly explains the mutex, queueing, backend submission, and audio-stutter changes covered by the pull request.
Linked Issues check Passed Active direct issue #1617 requires undistorted audio. The change addresses the AudioOut2 contention that can cause audio stutter or distortion. It snapshots PCM and gain data under the state mutex, su…
Out of Scope Changes check Passed The changed implementation and test code support the AudioOut2 audio objective in #1617. Submission buffering, per-context synchronization, safe handle destruction, and the blocked-push regression tes…
Full details: Linked Issues check

Explanation

Active direct issue #1617 requires undistorted audio. The change addresses the AudioOut2 contention that can cause audio stutter or distortion. It snapshots PCM and gain data under the state mutex, submits outside that mutex, and protects each context submission until backend output completes. The regression test verifies that a blocked push in one context does not block another context and that destruction does not close in-use devices. The issue's completed illumination item is not an active requirement.

Full details: Out of Scope Changes check

Explanation

The changed implementation and test code support the AudioOut2 audio objective in #1617. Submission buffering, per-context synchronization, safe handle destruction, and the blocked-push regression test are connected to that objective. No unrelated change is shown.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-20 02:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1745#issuecomment-6282232537) · edited 2026-10-22 00:51 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1745?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `bc61a3a6-09f2-436a-b390-eb84b62c2244` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 903861cba9f96dd5f22c0b285fdb4eb08a2f1ded and 392966bf3408da3a65222abe46164893edaa0980. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 2</strong></summary> <dl> <dd> * `src/libs/libAudio2.cpp` * `tests/AudioOut2PortTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> Audio queueing now stores each context’s PCM, gain, and object mix data in dedicated submission storage. It releases the global state mutex before backend output. Context and port destruction wait for in-flight submissions before closing audio handles. A new test checks cross-context progress, stable submission data, and concurrent destruction while output is blocked. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"392966bf3408da3a65222abe46164893edaa0980" --> **Change:** Bug fix · **Severity of issue fixed:** Low <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>39296</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `39296` --> <!-- final_review_risk_coverage:{"sourceCommitId":"392966bf3408da3a65222abe46164893edaa0980","coveredCommitId":"392966bf3408da3a65222abe46164893edaa0980","kind":"reviewed"} --> No outstanding audio submission issue is established; the PR is mergeable after normal checks. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 warning</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 3.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 4 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the primary change: preventing AudioOut2 contexts from stalling each other. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the mutex, queueing, backend submission, and audio-stutter changes covered by the pull request. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Active direct issue `#1617` requires undistorted audio. The change addresses the AudioOut2 contention that can cause audio stutter or distortion. It snapshots PCM and gain data under the state mutex, su… | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The changed implementation and test code support the AudioOut2 audio objective in `#1617`. Submission buffering, per-context synchronization, safe handle destruction, and the blocked-push regression tes… | <details> <summary><strong>Full details: Linked Issues check</strong></summary> <dl> <dd> **Explanation** Active direct issue `#1617` requires undistorted audio. The change addresses the AudioOut2 contention that can cause audio stutter or distortion. It snapshots PCM and gain data under the state mutex, submits outside that mutex, and protects each context submission until backend output completes. The regression test verifies that a blocked push in one context does not block another context and that destruction does not close in-use devices. The issue's completed illumination item is not an active requirement. </dd> </dl> </details> <details> <summary><strong>Full details: Out of Scope Changes check</strong></summary> <dl> <dd> **Explanation** The changed implementation and test code support the AudioOut2 audio objective in `#1617`. Submission buffering, per-context synchronization, safe handle destruction, and the blocked-push regression test are connected to that objective. No unrelated change is shown. </dd> </dl> </details> </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1745)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-20 02:54 UTC · original · edited 2026-10-20 07:59 UTC
On src/libs/libAudio2.cpp line 353 (outdated):

@@ -313,11 +327,31 @@ static bool audioout2_port_type_is_object(uint16_t port_type) {
 	return (port_type & 0xff00u) == 0x0100u;
 }
 
+static bool audioout2_device_queued_frames_locked(const AudioOut2ContextState& context,
+                                                  uint32_t*                    max_frames);
+
 static void audioout2_update_context_locked(AudioOut2ContextState* state) {
 	if (state == nullptr) {
 		return;
 	}
 
+	// With a real host device, report the guest queue level from what the device has not played
+	// yet. A wall-clock model drifts from the device clock and lets a tiny guest queue (e.g.
+	// 2 x 256 grains) starve the host device, which is heard as constant stutter.
+	uint32_t device_frames = 0;
+	if (audioout2_device_queued_frames_locked(*state, &device_frames)) {
+		const auto grains = state->num_grains == 0 ? 512u : state->num_grains;
+		const auto level  = device_frames > AUDIO_OUT2_DEVICE_CUSHION_FRAMES
+		                        ? (device_frames - AUDIO_OUT2_DEVICE_CUSHION_FRAMES + grains - 1) /
+		                              grains
+		                        : 0u;
+		state->queued      = std::min(level, state->queue_depth);
+		state->last_update = LibKernel::KernelGetProcessTime();
+		state->stat_min_frames = std::min(state->stat_min_frames, device_frames);
+		state->stat_max_frames = std::max(state->stat_max_frames, device_frames);
+		return;
+	}

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use the device-derived queue level only when the context feeds the device.

audioout2_device_queued_frames_locked returns true for any port or object handle with an open SDL stream. It does not check whether PCM is being submitted. The branch then sets state->queued from the device queue on every update.

Consider a context that has open streams and empty pcm_data. This happens before the first PCM attribute, and after AudioOut2PortSetAttributes clears PCM with a null pointer. In that state:

  1. device_frames stays at 0, so state->queued resets to 0 on every update.
  2. use_device_clock is false because audioout2_context_has_queueable_device requires PCM.
  3. The state->queued < state->queue_depth check always passes.
  4. audioout2_queue_context_audio has no params and returns at once.

As a result, blocking AudioOut2ContextPush calls never sleep. Async pushes never return AUDIO_OUT2_ERROR_NOT_READY. A guest audio thread that relies on push backpressure spins at full CPU, and its audio clock runs faster than real time.

The comment at Lines 696-698 says that pushes without PCM depend on queue-depth backpressure. The old wall-clock model gave that backpressure because queued++ accumulated and drained over time. The new branch overwrites queued on every update, so that backpressure is lost.

Fix: guard the device branch with audioout2_context_has_queueable_device(*state). In all other cases, fall back to the wall-clock model.

🐛 Proposed fix
--- "a/src/libs/libAudio2.cpp"
+++ "b/src/libs/libAudio2.cpp"
@@ -338,8 +338,9 @@
 	// With a real host device, report the guest queue level from what the device has not played
 	// yet. A wall-clock model drifts from the device clock and lets a tiny guest queue (e.g.
 	// 2 x 256 grains) starve the host device, which is heard as constant stutter.
 	uint32_t device_frames = 0;
-	if (audioout2_device_queued_frames_locked(*state, &device_frames)) {
+	if (audioout2_context_has_queueable_device(*state) &&
+	    audioout2_device_queued_frames_locked(*state, &device_frames)) {
 		const auto grains = state->num_grains == 0 ? 512u : state->num_grains;
 		const auto level  = device_frames > AUDIO_OUT2_DEVICE_CUSHION_FRAMES
 		                        ? (device_frames - AUDIO_OUT2_DEVICE_CUSHION_FRAMES + grains - 1) /

audioout2_context_has_queueable_device is defined at Line 416, after this function. Add a forward declaration next to the one at Lines 330-331.

✅ Addressed in commit e0166ff

**@⁠coderabbitai[bot]** on GitHub · 2026-10-20 02:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1745#discussion_r4320997370) · edited 2026-10-20 07:59 UTC On `src/libs/libAudio2.cpp` line 353 (outdated): ```diff @@ -313,11 +327,31 @@ static bool audioout2_port_type_is_object(uint16_t port_type) { return (port_type & 0xff00u) == 0x0100u; } +static bool audioout2_device_queued_frames_locked(const AudioOut2ContextState& context, + uint32_t* max_frames); + static void audioout2_update_context_locked(AudioOut2ContextState* state) { if (state == nullptr) { return; } + // With a real host device, report the guest queue level from what the device has not played + // yet. A wall-clock model drifts from the device clock and lets a tiny guest queue (e.g. + // 2 x 256 grains) starve the host device, which is heard as constant stutter. + uint32_t device_frames = 0; + if (audioout2_device_queued_frames_locked(*state, &device_frames)) { + const auto grains = state->num_grains == 0 ? 512u : state->num_grains; + const auto level = device_frames > AUDIO_OUT2_DEVICE_CUSHION_FRAMES + ? (device_frames - AUDIO_OUT2_DEVICE_CUSHION_FRAMES + grains - 1) / + grains + : 0u; + state->queued = std::min(level, state->queue_depth); + state->last_update = LibKernel::KernelGetProcessTime(); + state->stat_min_frames = std::min(state->stat_min_frames, device_frames); + state->stat_max_frames = std::max(state->stat_max_frames, device_frames); + return; + } ``` **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** **Use the device-derived queue level only when the context feeds the device.** `audioout2_device_queued_frames_locked` returns `true` for any port or object handle with an open SDL stream. It does not check whether PCM is being submitted. The branch then sets `state->queued` from the device queue on every update. Consider a context that has open streams and empty `pcm_data`. This happens before the first PCM attribute, and after `AudioOut2PortSetAttributes` clears PCM with a null pointer. In that state: 1. `device_frames` stays at 0, so `state->queued` resets to 0 on every update. 2. `use_device_clock` is `false` because `audioout2_context_has_queueable_device` requires PCM. 3. The `state->queued < state->queue_depth` check always passes. 4. `audioout2_queue_context_audio` has no params and returns at once. As a result, blocking `AudioOut2ContextPush` calls never sleep. Async pushes never return `AUDIO_OUT2_ERROR_NOT_READY`. A guest audio thread that relies on push backpressure spins at full CPU, and its audio clock runs faster than real time. The comment at Lines 696-698 says that pushes without PCM depend on queue-depth backpressure. The old wall-clock model gave that backpressure because `queued++` accumulated and drained over time. The new branch overwrites `queued` on every update, so that backpressure is lost. Fix: guard the device branch with `audioout2_context_has_queueable_device(*state)`. In all other cases, fall back to the wall-clock model. <details> <summary>🐛 Proposed fix</summary> ```diff --- "a/src/libs/libAudio2.cpp" +++ "b/src/libs/libAudio2.cpp" @@ -338,8 +338,9 @@ // With a real host device, report the guest queue level from what the device has not played // yet. A wall-clock model drifts from the device clock and lets a tiny guest queue (e.g. // 2 x 256 grains) starve the host device, which is heard as constant stutter. uint32_t device_frames = 0; - if (audioout2_device_queued_frames_locked(*state, &device_frames)) { + if (audioout2_context_has_queueable_device(*state) && + audioout2_device_queued_frames_locked(*state, &device_frames)) { const auto grains = state->num_grains == 0 ? 512u : state->num_grains; const auto level = device_frames > AUDIO_OUT2_DEVICE_CUSHION_FRAMES ? (device_frames - AUDIO_OUT2_DEVICE_CUSHION_FRAMES + grains - 1) / ``` `audioout2_context_has_queueable_device` is defined at Line 416, after this function. Add a forward declaration next to the one at Lines 330-331. </details> <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:42101678e8895d45c4ab4a1e --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit e0166ff
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-20 02:54 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9de56410-93dd-4ad4-ac79-a66386bd4df7
📥 Commits

Reviewing files that changed from the base of the PR and between f186b35706 and 1b6f5ec330be4b3a6a1e18c3a1adac01b7ed1468.

📒 Files selected for processing: 3
  • src/libs/audio.cpp
  • src/libs/audio_internal.h
  • src/libs/libAudio2.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-20 02:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1745#pullrequestreview-5580232638) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `9de56410-93dd-4ad4-ac79-a66386bd4df7` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between f186b35706ddbc3faf5513f326e2335d224802f7 and 1b6f5ec330be4b3a6a1e18c3a1adac01b7ed1468. </details> <details> <summary>📒 Files selected for processing: 3</summary> * `src/libs/audio.cpp` * `src/libs/audio_internal.h` * `src/libs/libAudio2.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=74d9bbbe-b627-4ce1-bf23-bb5b5c1406de attempt=52cfa1c1-5add-455c-b1e2-b9b44237c7ca batch=1/1 -->
Author
Owner

@⁠MrBigBritches on GitHub · 2026-10-20 08:00 UTC · original

Fixed in e0166ff: the device-derived queue level is only used when the context is submitting PCM (audioout2_context_has_queueable_device); otherwise the wall-clock model keeps push backpressure.

**@⁠MrBigBritches** on GitHub · 2026-10-20 08:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1745#issuecomment-6286306898) Fixed in e0166ff: the device-derived queue level is only used when the context is submitting PCM (audioout2_context_has_queueable_device); otherwise the wall-clock model keeps push backpressure.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-20 08:19 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Normalize queued frames before the device-queue comparison. · libAudio2.cpp:400-418

src/libs/libAudio2.cpp:400-418
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Normalize queued frames before the device-queue comparison.

AudioOutGetQueuedFrames returns frames in the stream's sampling-rate units. Ordinary ports can use params->sampling_freq, while the object port and the 1,920-frame cushion use 48 kHz. The raw std::max therefore compares incompatible units and can produce incorrect queue levels and asynchronous backpressure. Normalize each port to 48 kHz before taking the maximum.

Suggested fix
-	auto     consider = [&](int handle) {
+	auto     consider = [&](int handle, uint32_t sampling_freq) {
 		uint32_t queued = 0;
 		if (handle > 0 && AudioInternal::AudioOutGetQueuedFrames(handle, &queued)) {
 			found  = true;
-			frames = std::max(frames, queued);
+			const auto normalized =
+			    static_cast<uint32_t>((static_cast<uint64_t>(queued) * 48000u) / sampling_freq);
+			frames = std::max(frames, normalized);
 		}
 	};
-	consider(context.object_audio_handle);
+	consider(context.object_audio_handle, 48000);
 	for (const auto& state: g_audioout2_ports) {
 		if (state.used && state.context == context.handle) {
-			consider(state.audio_handle);
+			consider(state.audio_handle, state.sampling_freq);
 		}
 	}

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3bb6ea07-e3e6-4587-89a5-7f9580436290
📥 Commits

Reviewing files that changed from the base of the PR and between e0166ff99074fdbcdd2d8ddc794a2076ec973590 and 903861cba9f96dd5f22c0b285fdb4eb08a2f1ded.

📒 Files selected for processing: 1
  • tests/AudioOut2PortTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-20 08:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1745#pullrequestreview-5582500249) · **reviewed** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong>🟡 Minor</strong> · Normalize queued frames before the device-queue comparison. · <code>libAudio2.cpp:400-418</code></summary><blockquote> > > `src/libs/libAudio2.cpp:400-418` > **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** > > **Normalize queued frames before the device-queue comparison.** > > `AudioOutGetQueuedFrames` returns frames in the stream's sampling-rate units. Ordinary ports can use `params->sampling_freq`, while the object port and the 1,920-frame cushion use 48 kHz. The raw `std::max` therefore compares incompatible units and can produce incorrect queue levels and asynchronous backpressure. Normalize each port to 48 kHz before taking the maximum. > > <details><summary>Suggested fix</summary> > > ```diff > - auto consider = [&](int handle) { > + auto consider = [&](int handle, uint32_t sampling_freq) { > uint32_t queued = 0; > if (handle > 0 && AudioInternal::AudioOutGetQueuedFrames(handle, &queued)) { > found = true; > - frames = std::max(frames, queued); > + const auto normalized = > + static_cast<uint32_t>((static_cast<uint64_t>(queued) * 48000u) / sampling_freq); > + frames = std::max(frames, normalized); > } > }; > - consider(context.object_audio_handle); > + consider(context.object_audio_handle, 48000); > for (const auto& state: g_audioout2_ports) { > if (state.used && state.context == context.handle) { > - consider(state.audio_handle); > + consider(state.audio_handle, state.sampling_freq); > } > } > ``` > > </details> > > <!-- cr-comment:v1:a0bfd03d8f3909f1a6405c36 --> > > </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `3bb6ea07-e3e6-4587-89a5-7f9580436290` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e0166ff99074fdbcdd2d8ddc794a2076ec973590 and 903861cba9f96dd5f22c0b285fdb4eb08a2f1ded. </details> <details> <summary>📒 Files selected for processing: 1</summary> * `tests/AudioOut2PortTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=81f58d05-bfb9-41c7-9e70-abcfccc73c8c attempt=0f0343cf-a1d6-4423-9d44-5b850826f617 batch=1/1 -->
This discussion has been locked. Commenting is limited to contributors.
No description provided.