Skip to content

feat: add hardware latency reporting to ASIO, CoreAudio, JACK, WASAPI and WebAudio#1129

Open
roderickvd wants to merge 2 commits intomasterfrom
fix/hardware-latency
Open

feat: add hardware latency reporting to ASIO, CoreAudio, JACK, WASAPI and WebAudio#1129
roderickvd wants to merge 2 commits intomasterfrom
fix/hardware-latency

Conversation

@roderickvd
Copy link
Member

@roderickvd roderickvd commented Mar 17, 2026

Currently, playback - callback underreports host latency on several hosts because the hardware pipeline delay isn't included.

This PR fixes it using each host's native API:

  • CoreAudio: adds kAudioDevicePropertyLatency + kAudioDevicePropertySafetyOffset
  • WASAPI: adds GetStreamLatency() (hardware latency beyond the buffer)
  • ASIO: adds ASIOGetLatencies() (hardware latency beyond the buffer)
  • JACK: uses CycleTimes::next_usecs directly instead of estimating from current_usecs + buffer_duration
  • WebAudio: adds AudioContext.baseLatency + outputLatency

Supersedes #964
Fixes #773

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves cross-backend timestamp accuracy by incorporating driver-/platform-reported latency components into OutputStreamTimestamp (and related input timestamps where applicable), making callback timing metadata better reflect when audio is actually captured/played by hardware.

Changes:

  • WebAudio/WebAudioWorklet: incorporate baseLatency and outputLatency into output playback timestamps.
  • WASAPI: compute output playback timestamps using endpoint buffer padding plus IAudioClient::GetStreamLatency().
  • CoreAudio/JACK/ASIO: refine timestamps using device latency + safety offset (CoreAudio), cycle deadline (JACK), and ASIO driver-reported hardware latency (ASIO + asio-sys bindings).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/host/webaudio/mod.rs Adds base/output latency compensation when reporting output playback timestamps.
src/host/audioworklet/mod.rs Snapshots WebAudio latency values and factors them into worklet output playback timestamps.
src/host/wasapi/stream.rs Updates output timestamp calculation to use buffer padding + stored stream latency.
src/host/wasapi/device.rs Captures WASAPI stream latency during stream construction and stores it in StreamInner.
src/host/jack/stream.rs Uses JACK cycle next_usecs (when available) for more precise output playback timestamps.
src/host/coreaudio/macos/device.rs Adds device latency + safety offset to CoreAudio timestamp delay computation.
src/host/asio/stream.rs Incorporates ASIO driver latency frames into input/output timestamp delay calculations.
asio-sys/src/bindings/mod.rs Exposes Driver::latencies() wrapping ASIOGetLatencies.
asio-sys/build.rs Allowlists ASIOGetLatencies for bindgen-generated bindings.
asio-sys/asio_stub_bindings.rs Adds a stub ASIOGetLatencies symbol for docs/non-Windows builds.
CHANGELOG.md Documents improved timestamp behavior across backends.
asio-sys/CHANGELOG.md Documents the newly added Driver::latencies() API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can you get the system latency?

2 participants