Bug 264247 - getOutputTimestamp() seems to use wrong time scale
Summary: getOutputTimestamp() seems to use wrong time scale
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Audio (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-11-06 02:33 PST by chrisguttandin
Modified: 2024-02-23 07:59 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description chrisguttandin 2023-11-06 02:33:21 PST
The contextTime returned by getOutputTimestamp() seems to be devided by the sampleRate of the AudioContext. Please take a look at this demo to reproduce the bug: https://stackblitz.com/edit/js-ndbao2?file=index.html,index.js. The contextTime is very small but ends up being a reasonable value when multiplied by the sampleRate.

Please also note that the contextTime currently seems to drift away in relation to currentTime. It starts out being smaller than currentTime (as it is in Chrome and Firefox) but soon drifts away until it eventually gets larger than currentTime.
Comment 1 Radar WebKit Bug Importer 2023-11-13 02:34:14 PST
<rdar://problem/118323705>
Comment 2 Chris Dumez 2024-02-22 21:01:42 PST
```
diff --git a/Source/WebCore/platform/audio/AudioDestinationResampler.cpp b/Source/WebCore/platform/audio/AudioDestinationResampler.cpp
index efd262000a29..257d72887a19 100644
--- a/Source/WebCore/platform/audio/AudioDestinationResampler.cpp
+++ b/Source/WebCore/platform/audio/AudioDestinationResampler.cpp
@@ -109,7 +109,7 @@ size_t AudioDestinationResampler::pullRendered(size_t numberOfFrames)
 bool AudioDestinationResampler::render(double sampleTime, MonotonicTime hostTime,  size_t framesToRender)
 {
     m_outputTimestamp = {
-        Seconds { sampleTime / sampleRate() },
+        Seconds { sampleTime },
         hostTime
     };
     // When there is a AudioWorklet, we do rendering on the AudioWorkletThread.
```
Need to write a test case.
Comment 3 Chris Dumez 2024-02-22 21:23:05 PST
Pull request: https://github.com/WebKit/WebKit/pull/24994
Comment 4 EWS 2024-02-23 07:59:28 PST
Committed 275237@main (33172dfe163a): <https://commits.webkit.org/275237@main>

Reviewed commits have been landed. Closing PR #24994 and removing active labels.