Skip to content

feat: get output timestamp in the audiocontext - #1359

Draft
mdydek wants to merge 3 commits into
mainfrom
feat/get-output-timestamp
Draft

mdydek wants to merge 3 commits into
mainfrom
feat/get-output-timestamp

Conversation

@mdydek

@mdydek mdydek commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Closes #

⚠️ Breaking changes ⚠️

Introduced changes

  • getOutputTimeStamp function of the audio context implementation
  1. Precise "what is playing now"
  • The platform asks for a buffer of N frames, and we render it as ceil(N / 128) quanta back to back, as fast as the code runs. The buffer is played later, when the device gets to it.
    currentTime advances by the whole buffer during that short render burst and then stays frozen until the next callback. A caller polling it can't tell where in that period they are.

  • currentTime also marks what was rendered, not what is heard. The device plays it about one output latency later (10–40 ms on the speaker, 150–250 ms on Bluetooth).

  • Scheduling at currentTime + x is therefore late by the output latency. Subtracting outputLatency fixes the average, but the click still lands 0 to N frames late, depending on when currentTime was read. With large buffers that's tens of ms.

  • getOutputTimestamp() returns contextTime, the frame leaving the speaker, together with the performance.now() moment it does so (of course is OS estimation, but its the best we can get). Because performance.now() advances continuously, you can extrapolate from that pair to any moment without the buffer-sized error. Our implementation already extrapolates to the moment of the call, so contextTime is the audible position now.

  1. Linking context time and performance.now()
  • The pair connects the context's clock to the performance.now() clock, which everything else uses: animations, gestures, video, network messages, other devices.

  • To convert in either direction: contextTime + (perfMs − performanceTime) / 1000 and performanceTime + (ctxS − contextTime) × 1000. That lets visuals follow the audible position, sounds land on a visual event, taps be judged against what the user heard, or several devices sound in sync.

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added/Conducted relevant tests
  • Performed self-review of the code
  • Updated Web Audio API coverage
  • Added support for web
  • Updated old arch android spec file

@mdydek mdydek added the feature New user-facing features or major capabilities label Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

WPT non-regression comparison

ERROR — the run produced no report.

Workflow run · this comment is updated on every push.

@mdydek
mdydek added this pull request to stack #1361 October 22, 2026 16:07
@mdydek
mdydek force-pushed the feat/get-output-timestamp branch from f515df0 to 9b0f86a Compare October 23, 2026 08:38

This branch has not been deployed

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

Labels

feature New user-facing features or major capabilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant