ASIO: TimeBase treats small backward steps in systemTime as timeGetTime wraps, so stream instants race ahead and overflow after ~10 minutes
维护者通常 1 天内回复
评估
调研方向
Start with TimeBase::to_stream_instant in src/host/asio/stream.rs and inspect how it distinguishes clock wraparound from backward jitter. The report includes a Focusrite ASIO reproduction and suggests checking callback timestamps for large jumps. Done means genuine wraps are handled without treating small backward steps as wraps, and callback instants avoid overflow; an open pull request is already linked.
由索引模型根据 Issue 内容生成。
描述
cpal: 0.18.2, asio feature. Driver: Focusrite USB ASIO 4.150.0.432, Scarlett 2i2 1st Gen, 128-frame buffers at 48 kHz, Windows 11.
What happens
TimeBase::to_stream_instant (src/host/asio/stream.rs) treats any ns < prev as a timeGetTime() wrap, and adds TIMEGETIME_WRAP_NS (about 49.7 days) to the epoch:
let prev = self.last_ns.swap(ns, Ordering::Relaxed);
let epoch = if ns < prev {
self.epoch_ns.fetch_add(TIMEGETIME_WRAP_NS, Ordering::Relaxed) + TIMEGETIME_WRAP_NS
} else { ... };
StreamInstant::from_nanos(epoch + ns)
Focusrite's ASIOTimeInfo::systemTime jitters: from one buffer switch to the next it sometimes steps back by tens to hundreds of microseconds. Over 10 s (3,746 callbacks) I counted 78 such steps, between 17 µs and 667 µs back. The normal step between callbacks ranged from 2.4 µs to 4.7 ms, against the nominal 2.67 ms. Each backward step adds 49.7 days, so:
- the callback instant reaches about 10 years after 10 s;
epoch + nsoverflowsu64after about 10 minutes. In a debug build this panics on the audio thread. In release it wraps.
Around that point, the latency an app reads as playback.checked_duration_since(callback) came out as about 1.6 × 10¹⁶ µs.
Suggested fix
Only count a wrap when the step back is large: a real timeGetTime wrap goes back by nearly 2³² ms. For example:
let epoch = if ns < prev && prev - ns > TIMEGETIME_WRAP_NS / 2 { /* wrap */ } else { /* jitter: keep epoch */ };
Optionally, clamp so the instant never runs backwards (max(prev_instant, new)) to keep instants monotonic through the jitter.
Repro
Build an output stream on the Focusrite USB ASIO driver. Log info.timestamp().callback for each callback, and look for callback-to-callback deltas of about 4.29 × 10¹⁵ ns.
- 主要语言
- Rust
- 星标
- 4k
- 派生
- 554
- 平均合并
- 3 天 3 小时
- 30 天内合并 PR
- 4
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
RustAudio/cpal 的其他 Issue
-
aaudio: dynamic buffer tuning never grows the buffer (set_buffer_size_in_frames reports Err on success)可能已有人在做 @dannyward630 于 4 天前认领。 未关闭host - aaudio platform - android
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
WebAudio wasm build fails with wasm-bindgen panic=unwind closures可能已有人在做 @bogusyogi 于 13 天前认领。 未关闭host - webaudio platform - web
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
code quality dependencies host - wasapi platform - windows
难度 5/5 一周以上 新手友好度 35/100
维护者通常 1 天内回复
-
host - pipewire platform - linux
难度 4/5 1-2 天 新手友好度 52/100
维护者通常 1 天内回复
-
WASAPI: default-device activation fails with RPC_E_CHANGED_MODE after endpoint-notification callbacks put thread-pool threads into an STA可能已有人在做 @dannyward630 于 5 天前认领。 未关闭correctness host - wasapi platform - windows
难度 4/5 3-5 天 新手友好度 20/100
维护者通常 1 天内回复
相似的 Issue
-
good first issue help wanted r-docs
难度 2/5 1-3 小时 新手友好度 72/100
servo/rust-smallvec#824 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 76/100
superradcompany/microsandbox#1974 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
priority middle
难度 1/5 1 小时以内 新手友好度 62/100
KATO-Hiro/AtCoderClans#12940 ·
维护者通常 1 天内回复