Skip to content

Commit

Permalink
Cherry-pick 275237@main (33172df). https://bugs.webkit.org/show_bug.c…
Browse files Browse the repository at this point in the history
…gi?id=264247

    getOutputTimestamp() seems to use wrong time scale
    https://bugs.webkit.org/show_bug.cgi?id=264247
    rdar://118323705

    Reviewed by Eric Carlson.

    The time returned by getOutputTimestamp() was incorrectly divided by the
    sample rate. Fix this so the value returned is correct and matches Chrome
    and Firefox.

    * LayoutTests/webaudio/getOutputTimestamp-expected.txt: Added.
    * LayoutTests/webaudio/getOutputTimestamp.html: Added.
    * Source/WebCore/platform/audio/AudioDestinationResampler.cpp:
    (WebCore::AudioDestinationResampler::render):

    Canonical link: https://commits.webkit.org/275237@main

Canonical link: https://commits.webkit.org/274313.183@webkitglib/2.44
  • Loading branch information
cdumez authored and aperezdc committed Apr 30, 2024
1 parent cf8e66c commit 72e4315
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
11 changes: 11 additions & 0 deletions LayoutTests/webaudio/getOutputTimestamp-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Validate the value returned by AudioContext.getOutputTimestamp()

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS contextTime > 0.090 is true
PASS contextTime <= audioContext.currentTime is true
PASS successfullyParsed is true

TEST COMPLETE

28 changes: 28 additions & 0 deletions LayoutTests/webaudio/getOutputTimestamp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<DOCTYPE html>
<html>
<body>
<script src="../resources/js-test.js"></script>
<script>
description("Validate the value returned by AudioContext.getOutputTimestamp()");
jsTestIsAsync = true;

const audioContext = new AudioContext();
const gainNode = new GainNode(audioContext, { gain: 0.01 });
const oscillatorNode = new OscillatorNode(audioContext);

oscillatorNode.connect(gainNode).connect(audioContext.destination);
oscillatorNode.start();

handle = setInterval(() => {
if (audioContext.currentTime < 0.100)
return;
clearInterval(handle);

contextTime = audioContext.getOutputTimestamp().contextTime;
shouldBeTrue("contextTime > 0.090");
shouldBeTrue("contextTime <= audioContext.currentTime");
finishJSTest();
}, 10);
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 72e4315

Please sign in to comment.