-
Notifications
You must be signed in to change notification settings - Fork 939
Normalize audio frame rate in AudioMixer output #1271
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
WalkthroughBuffer timestamping now uses each source's configured rate when buffering incoming frames; separately, the mixer enforces its fixed output rate on filtered frames and computes elapsed time using that mixer output rate for downstream timing. Changes
Sequence DiagramsequenceDiagram
participant Source as Upstream Source
participant Mixer as AudioMixer
participant Buffer as Per-Source Buffer
participant Timing as Downstream Timing
rect rgb(240,250,255)
Note over Source,Buffer: Incoming frame arrives (may report various rates)
Source->>Buffer: push frame (frame.rate() = variable)
end
rect rgb(245,240,255)
Note over Buffer,Mixer: Buffer timestamping uses source-configured rate
Buffer->>Buffer: update buffer_last using source.rate (per-source)
end
rect rgb(245,255,240)
Note over Mixer: Mixer normalizes output rate
Mixer->>Mixer: set filtered_frame.rate = AudioMixer::INFO.rate()
Mixer->>Timing: compute elapsed using AudioMixer::INFO.rate()
end
rect rgb(255,245,245)
Note over Mixer: Downstream receives frames with consistent mixer rate
Mixer->>Timing: emit frame with fixed output timestamps
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/recording/src/sources/audio_mixer.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs: Format Rust code usingrustfmtand 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/sources/audio_mixer.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/sources/audio_mixer.rs
⏰ 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 (aarch64-apple-darwin, macos-latest)
- GitHub Check: Build Desktop (x86_64-pc-windows-msvc, windows-latest)
- GitHub Check: Analyze (rust)
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 (2)
crates/recording/src/sources/audio_mixer.rs (2)
134-141: Avoid long‑run/32‑bit overflow in sample counter.
samples_out: usizecan overflow on 32‑bit or extremely long runs. Preferu64and cast at use sites.Apply:
@@ - samples_out: usize, + samples_out: u64, @@ - samples_out: 0, + samples_out: 0u64, @@ - let elapsed = Duration::from_secs_f64(self.samples_out as f64 / output_rate); + let elapsed = Duration::from_secs_f64(self.samples_out as f64 / output_rate); @@ - self.samples_out += filtered.samples(); + self.samples_out += filtered.samples() as u64;Also applies to: 206-220, 411-415
297-315: Use existing helpers for silence math (readability/consistency).You already have
samples_for_timeoutandduration_from_samples. Using them here reduces duplication and keeps rounding consistent.- let silence_samples_needed = (gap.as_secs_f64()) * rate as f64; - let silence_samples_count = silence_samples_needed.ceil() as usize; + let silence_samples_count = samples_for_timeout(rate, gap); @@ - let silence_duration = Duration::from_secs_f64( - silence_samples_count as f64 / rate as f64, - ); + let silence_duration = duration_from_samples(silence_samples_count, rate);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/recording/src/sources/audio_mixer.rs(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
**/*.rs: Format Rust code usingrustfmtand 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/sources/audio_mixer.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/sources/audio_mixer.rs
🧬 Code graph analysis (1)
crates/recording/src/sources/audio_mixer.rs (1)
crates/media-info/src/lib.rs (1)
rate(125-127)
⏰ 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 (aarch64-apple-darwin, macos-latest)
- GitHub Check: Build Desktop (x86_64-pc-windows-msvc, windows-latest)
- GitHub Check: Analyze (rust)
🔇 Additional comments (2)
crates/recording/src/sources/audio_mixer.rs (2)
403-411: Output rate normalization + elapsed at mixer rate — correct and necessary.Setting
filteredtoAudioMixer::INFO.rate()and computingelapsedfrom that fixed rate prevents downstream from inheriting bad upstream sample-rate metadata and keeps timestamps monotonic at 48 kHz. Nice.
323-326: Buffered-frame duration now uses source rate — fix verified and consistent.The change at line 325 correctly switches to
rate(per-source rate) for buffered-frame duration, keeping it aligned with silence generation at line 312 which already uses the sameratevariable. Verified no other Duration calculations depend onframe.rate(). Output elapsed time at line 411 correctly usesoutput_rate(mixer rate) for downstream encoders. No additional fixes needed.
Ensures that the audio frames output by AudioMixer have their rate set to AudioMixer::INFO.rate(), preventing downstream encoders from inheriting incorrect rates from upstream sources such as CoreAudio devices. This change also updates the elapsed time calculation to use the normalized output rate
Summary by CodeRabbit