-
Notifications
You must be signed in to change notification settings - Fork 904
Improve device config selection for microphone feed #1209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe microphone device selection logic is refactored to dynamically determine suitable audio sample rates instead of requiring fixed 48kHz support. A new helper function selects optimal rates (48kHz or 44.1kHz) within device constraints, falling back to the device's maximum supported rate. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/recording/src/feeds/microphone.rs (1)
159-169
: Helper function logic is sound.The
select_sample_rate
function implements a sensible fallback strategy:
- Prefers 48kHz (industry standard for professional audio)
- Falls back to 44.1kHz (CD audio quality standard)
- Uses device's max rate if neither preferred rate is supported
The boundary checks correctly ensure the selected rate falls within the device's
min_sample_rate
andmax_sample_rate
range.Consider adding a doc comment to explain the rate selection strategy:
+/// Selects an optimal sample rate for the given config. +/// +/// Prefers 48kHz or 44.1kHz if supported within the device's range, +/// otherwise falls back to the device's maximum supported rate. fn select_sample_rate(config: &SupportedStreamConfigRange) -> cpal::SampleRate { const PREFERRED_RATES: [u32; 2] = [48_000, 44_100];
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/recording/src/feeds/microphone.rs
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs
: Format Rust code usingrustfmt
and ensure all Rust code passes workspace-level clippy lints.
Rust modules should be named with snake_case, and crate directories should be in kebab-case.
Files:
crates/recording/src/feeds/microphone.rs
crates/*/src/**/*
📄 CodeRabbit inference engine (AGENTS.md)
Rust crates should place tests within the
src/
and/or a siblingtests/
directory for each crate insidecrates/*
.
Files:
crates/recording/src/feeds/microphone.rs
🧬 Code graph analysis (1)
crates/recording/src/feeds/microphone.rs (1)
crates/media-info/src/lib.rs (2)
ffmpeg_sample_format_for
(277-287)rate
(118-120)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Build Desktop (x86_64-pc-windows-msvc, windows-latest)
- GitHub Check: Build Desktop (aarch64-apple-darwin, macos-latest)
- GitHub Check: Analyze (rust)
🔇 Additional comments (2)
crates/recording/src/feeds/microphone.rs (2)
5-5
: LGTM! Import is necessary for the new helper function.The
SupportedStreamConfigRange
import is correctly added to support the parameter type in the newselect_sample_rate
helper function.
150-154
: Good refactor! The dynamic sample rate selection is more flexible.The refactored logic correctly replaces the rigid 48kHz requirement with a flexible approach that:
- Filters configs by FFmpeg format compatibility
- Dynamically selects an appropriate sample rate for each compatible config
- Maintains the existing quality-based sorting (highest sample size and max rate first)
This should successfully include devices like AirPods that may support 44.1kHz or other standard rates instead of 48kHz.
To confirm this resolves the AirPods issue, please verify that AirPods (or similar devices without 48kHz support) now appear in the device list after these changes.
This pull request updates the logic for selecting and configuring audio input devices in the microphone feed code.
Fixes the issue of AirPods not showing in the list of available devices.
Summary by CodeRabbit