Skip to content

Commit

Permalink
AudioWorkletGlobalScope has valid currentFrame during construction.
Browse files Browse the repository at this point in the history
AudioWorkletGlobalScope is created with 0 currentFrame count,
which make currentTime as 0 even though audio context has
non zero currentTime.

The fix is to pass the currentFrame info during creation through
AudioWorkletObjectProxy.

Bug: 372866278
Change-Id: I717744005588ebc571862367662b0ac2cdb947ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5958713
Commit-Queue: Sunggook Chue <[email protected]>
Reviewed-by: Michael Wilson <[email protected]>
Reviewed-by: Hongchan Choi <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1379851}
  • Loading branch information
cpsgchue authored and chromium-wpt-export-bot committed Nov 7, 2024
1 parent 1e4fb39 commit e8a7298
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!doctype html>
<title>Test consistency of processing after resume()</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>

const get_node_and_reply = (context) => {
const node = new AudioWorkletNode(context, 'port-processor');
return new Promise((resolve) => {
node.port.onmessage = (event) => resolve({node: node, reply: event.data});
});
};

const modulePath = '/webaudio/the-audio-api/' +
'the-audioworklet-interface/processors/port-processor.js';

promise_test(async t => {
const realtime = new AudioContext();
const sampleRate = realtime.sampleRate;

// Create a basic oscillator to form an audio graph.
const oscillator = realtime.createOscillator();
oscillator.connect(realtime.destination);
oscillator.start();

// Start rendering and suspend after a delay.
await new Promise(resolve => t.step_timeout(resolve, 1000));
await realtime.suspend();

// Capture currentTime after suspending.
const contextTime = realtime.currentTime;

// Load the audio module.
await realtime.audioWorklet.addModule(modulePath);

// creates AudioWorkletNode.
const construct1 = await get_node_and_reply(realtime);

// workletFrame should be the currentFrame sent in the message
// by the AudioWorkletNode.
const workletFrame = construct1.reply.currentFrame;

// Assert that contextTime * sampleRate equals workletFrame.
assert_equals(
Math.floor(contextTime * sampleRate), workletFrame,
`Expected workletFrame (${
workletFrame}) to be equal to contextTime * sampleRate (${
contextTime * sampleRate})`);
}, 'currentTime vs currentFrames in Audio Worklet global scope');

</script>

0 comments on commit e8a7298

Please sign in to comment.