Bug 264247

Summary: getOutputTimestamp() seems to use wrong time scale
Product: WebKit Reporter: chrisguttandin
Component: Web AudioAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, jer.noble, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   

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.