fix sample drop in resampler on rate change boundary#1802
Conversation
✅ Deploy Preview for hyprnote ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughAdded a Changes
Sequence DiagramsequenceDiagram
participant Source
participant ResamplerDynamicNew
participant Backend
participant Consumer
loop poll_next
alt pending_sample exists
ResamplerDynamicNew->>ResamplerDynamicNew: Check for rate change
alt rate changed
ResamplerDynamicNew->>Backend: Rebuild with new_rate
ResamplerDynamicNew->>Backend: Push pending sample
ResamplerDynamicNew->>ResamplerDynamicNew: Clear pending_sample
else rate same
ResamplerDynamicNew->>Backend: Push pending_sample
ResamplerDynamicNew->>ResamplerDynamicNew: Clear pending_sample
end
else no pending_sample
ResamplerDynamicNew->>Source: Consume next sample
alt source produced sample
ResamplerDynamicNew->>ResamplerDynamicNew: Detect rate change
alt rate changed
ResamplerDynamicNew->>ResamplerDynamicNew: Store as pending_sample
else rate same
ResamplerDynamicNew->>Backend: Push sample immediately
end
end
end
ResamplerDynamicNew->>Backend: try_yield_chunk()
alt chunk available
ResamplerDynamicNew->>Consumer: Yield chunk
else no chunk
ResamplerDynamicNew->>Backend: Drain remaining
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
crates/audio-utils/src/resampler/dynamic_new.rs (2)
122-135: Pending-sample state addition looks consistent with struct invariantsThe new
pending_sample: Option<(f32, u32)>field and its initialization toNoneinnew(...)integrate cleanly with the existing private state; there’s no API break since fields remain non‑pub, and the tuple carries exactly what is needed to replay the boundary sample under the correct rate.If you want to make this a bit more self‑documenting, a small type alias (e.g.
type PendingSample = (f32, u32);) or a short field comment explaining(sample, source_rate)would help future readers, but that’s purely optional.Also applies to: 157-166
219-280: Rate‑change handling viapending_sampleappears correct; relies on backend drain contractThe revised
poll_nextloop that prioritizespending_sampleand callsdrain_for_rate_change()before rebuilding the backend looks sound:
- For both
PassthroughandResamplerbackends,Ok(false)fromdrain_for_rate_change()implies there is still output buffered, and the subsequenttry_yield_chunk(true)will always yield a chunk before re‑queuingpending_sample, so there’s no risk of spinning without progress.Ok(true)only occurs once the backend has no more output, at which point rebuilding withnew_rateand then pushing the stored sample ensures the boundary sample is processed exactly once under the new configuration.- The EOS path still goes through
drain_at_eos()+draining+try_yield_chunk(true)and cannot intersect with a livepending_sample, so there’s no way to “strand” the boundary sample during shutdown.Overall this fixes the original boundary drop without introducing ordering or duplication issues; the control flow is a bit dense but coherent.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
crates/audio-utils/src/resampler/dynamic_new.rs(4 hunks)crates/audio-utils/src/resampler/mod.rs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
crates/audio-utils/src/resampler/mod.rs (4)
crates/audio-utils/src/resampler/dynamic_new.rs (1)
new(140-167)crates/audio-utils/src/resampler/dynamic_old.rs (1)
new(23-37)crates/audio-utils/src/resampler/driver.rs (1)
new(20-35)crates/audio-utils/src/resampler/static_new.rs (1)
new(35-47)
⏰ 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). (1)
- GitHub Check: fmt
No description provided.