Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit ea70288

Browse files
Raymond Toychromium-wpt-export-bot
authored andcommitted
Update current_frame
When a setTargetAtTime event has converged (10 time constants), we basically hold the value. However, if there's a setValue event after convergence, and this setValue is within the current render quantum, the current_frame was not getting updated, so when this event and the next are getting processed, the currentTime has the incorrect value. Update current_frame appropriately in this case. Bug: 990393 Test: the-audioparam-interface/set-target-conv.html Change-Id: I4b364d3972e1f5acb454916fdb6455fb75b7e7b6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1736173 Reviewed-by: Hongchan Choi <[email protected]> Commit-Queue: Raymond Toy <[email protected]> Cr-Commit-Position: refs/heads/master@{#684137}
1 parent 7849029 commit ea70288

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2+
<html>
3+
<head>
4+
<title>Test convergence of setTargetAtTime</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/webaudio/resources/audit.js"></script>
8+
<script src='/webaudio/resources/audio-param.js'></script>
9+
</head>
10+
11+
<body>
12+
<script>
13+
let audit = Audit.createTaskRunner();
14+
15+
audit.define(
16+
{task: 'setTargetAtTime', label: 'convergence handled correctly'},
17+
(task, should) => {
18+
// Two channels:
19+
// 0 - actual result
20+
// 1 - expected result
21+
const context = new OfflineAudioContext(
22+
{numberOfChannels: 2, sampleRate: 8000, length: 8000});
23+
24+
const merger = new ChannelMergerNode(
25+
context, {numberOfChannels: context.destination.channelCount});
26+
merger.connect(context.destination);
27+
28+
// Construct test source that will have tha AudioParams being tested
29+
// to verify that the AudioParams are working correctly.
30+
let src;
31+
32+
should(
33+
() => src = new ConstantSourceNode(context),
34+
'src = new ConstantSourceNode(context)')
35+
.notThrow();
36+
37+
src.connect(merger, 0, 0);
38+
src.offset.setValueAtTime(1, 0);
39+
40+
const timeConstant = 0.01;
41+
42+
// testTime must be at least 10*timeConstant. Also, this must not
43+
// lie on a render boundary.
44+
const testTime = 0.15;
45+
const rampEnd = testTime + 0.001;
46+
47+
should(
48+
() => src.offset.setTargetAtTime(0.5, 0.01, timeConstant),
49+
`src.offset.setTargetAtTime(0.5, 0.01, ${timeConstant})`)
50+
.notThrow();
51+
should(
52+
() => src.offset.setValueAtTime(0.5, testTime),
53+
`src.offset.setValueAtTime(0.5, ${testTime})`)
54+
.notThrow();
55+
should(
56+
() => src.offset.linearRampToValueAtTime(1, rampEnd),
57+
`src.offset.linearRampToValueAtTime(1, ${rampEnd})`)
58+
.notThrow();
59+
60+
// The reference node that will generate the expected output. We do
61+
// the same automations, except we don't apply the setTarget
62+
// automation.
63+
const refSrc = new ConstantSourceNode(context);
64+
refSrc.connect(merger, 0, 1);
65+
66+
refSrc.offset.setValueAtTime(0.5, 0);
67+
refSrc.offset.setValueAtTime(0.5, testTime);
68+
refSrc.offset.linearRampToValueAtTime(1, rampEnd);
69+
70+
src.start();
71+
refSrc.start();
72+
73+
context.startRendering()
74+
.then(audio => {
75+
const actual = audio.getChannelData(0);
76+
const expected = audio.getChannelData(1);
77+
78+
// Just verify that the actual output matches the expected
79+
// starting a little bit before testTime.
80+
let testFrame =
81+
Math.floor(testTime * context.sampleRate) - 128;
82+
should(actual.slice(testFrame), `output[${testFrame}:]`)
83+
.beCloseToArray(
84+
expected.slice(testFrame),
85+
{relativeThreshold: 4.1724e-6});
86+
})
87+
.then(() => task.done());
88+
});
89+
90+
audit.run();
91+
</script>
92+
</body>
93+
</html>

0 commit comments

Comments
 (0)