Preserve Bluetooth playback quality during recording - #267
Conversation
Regular capture previously used an AVAudioEngine input tap that participated in the default hardware graph and changed macOS's global default input device. That could switch Bluetooth output into call mode even when Hex was configured to use the MacBook microphone, then leave playback degraded after recording. Use an on-demand input Audio Queue with no output graph, bind it directly to the selected microphone's persistent Core Audio UID, and dispose it deterministically at stop. Resolve saved microphone selections against the current device list without changing the system default. Bind Super Fast capture directly to the selected input while preserving pre-roll behavior. Release the sound-effects engine after playback so temporary Bluetooth routes return to normal, with a timeout fallback for missed completion callbacks. Report empty input-only captures as recording failures and add regression coverage for selected-device resolution and stale capture callbacks. Manual validation and automated tests were completed on the original backed-up stack.
📝 WalkthroughWalkthroughChangesAudio capture and playback
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant RecordingClient
participant DeviceResolver
participant InputOnlyCaptureController
participant AudioQueue
participant AVAudioFile
RecordingClient->>DeviceResolver: resolve capture input device
DeviceResolver-->>RecordingClient: selected AudioDeviceID
RecordingClient->>InputOnlyCaptureController: begin recording
InputOnlyCaptureController->>AudioQueue: start input capture
AudioQueue->>InputOnlyCaptureController: deliver audio buffers
InputOnlyCaptureController->>AVAudioFile: write converted PCM
RecordingClient->>InputOnlyCaptureController: finish recording
InputOnlyCaptureController-->>RecordingClient: captured or failed result
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.changeset/calm-airpods-routing.md:
- Line 5: Append the relevant GitHub issue or pull-request number to the
changeset summary in .changeset/calm-airpods-routing.md, using the required
(`#123`) format. Preserve the existing user-facing description and only add the
reference.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5ba03f18-43b9-46c8-a998-5b1792ea99cb
📒 Files selected for processing (6)
.changeset/calm-airpods-routing.mdHex/Clients/InputOnlyCaptureController.swiftHex/Clients/RecordingClient.swiftHex/Clients/SoundEffect.swiftHex/Clients/SuperFastCaptureController.swiftHexTests/RecordingRaceTests.swift
| "hex-app": patch | ||
| --- | ||
|
|
||
| Keep Bluetooth playback in high-quality mode when Hex records from another microphone, and restore normal quality promptly after recording and sound effects finish. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add the GitHub issue/PR reference to the changeset summary.
The summary describes user-facing impact but omits the issue/PR number. Append the relevant reference (e.g. one of the issues this PR addresses) in the (#123) format so release notes and GitHub linking work.
As per coding guidelines: .changeset/*.md should "Include user-facing impact and GitHub issue/PR number in the format 'Improve Fn hotkey stability (#89)'".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.changeset/calm-airpods-routing.md at line 5, Append the relevant GitHub
issue or pull-request number to the changeset summary in
.changeset/calm-airpods-routing.md, using the required (`#123`) format. Preserve
the existing user-facing description and only add the reference.
Source: Coding guidelines
I noticed two issues when using Hex with the following settings:
Activating Hex would:
This PR resolves both issues in my testing.
Summary by CodeRabbit
New Features
Bug Fixes