Skip to content

Commit 901c2f9

Browse files
Raymond Toychromium-wpt-export-bot
authored andcommitted
Fix flaky k-rate-panner test
Change the testing scheme for k-rate panner to verify that the output is piecewise constant for a constant source when the automation rate is set to k-rate. Reduce the duration of the test as well; Just a few render quanta is enough to verify that the output is piece-wise constant and different from the a-rate output. Also updated k-rate-constant-source.html to use the same doTest method since the special case is supported. Didn't actually figure out the underlying flakiness of the original test. Bug: 841856 Change-Id: I8e9807e530fc3b1452bae521a2660be3fbe104f9 Reviewed-on: https://chromium-review.googlesource.com/1076809 Reviewed-by: Hongchan Choi <[email protected]> Commit-Queue: Raymond Toy <[email protected]> Cr-Commit-Position: refs/heads/master@{#568100}
1 parent ba32f24 commit 901c2f9

File tree

3 files changed

+69
-60
lines changed

3 files changed

+69
-60
lines changed

webaudio/the-audio-api/the-audioparam-interface/automation-rate-testing.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
//
33
// |options| describes how the testing of the AudioParam should be done:
44
//
5+
// sourceNodeName: name of source node to use for testing; defaults to
6+
// 'OscillatorNode'. If set to 'none', then no source node
7+
// is created for testing and it is assumed that the AudioNode
8+
// under test are sources and need to be started.
9+
// verifyPieceWiseConstant: if true, verify that the k-rate output is
10+
// piecewise constant for each render quantum.
511
// nodeName: name of the AudioNode to be tested
612
// nodeOptions: options to be used in the AudioNode constructor
713
//
@@ -42,7 +48,14 @@ function doTest(context, should, options) {
4248
context, {numberOfInputs: context.destination.numberOfChannels});
4349
merger.connect(context.destination);
4450

45-
let src = new OscillatorNode(context);
51+
let src = null;
52+
53+
// Skip creating a source to drive the graph if |sourceNodeName| is 'none'.
54+
// If |sourceNodeName| is given, use that, else default to OscillatorNode.
55+
if (options.sourceNodeName !== 'none') {
56+
src = new window[options.sourceNodeName || 'OscillatorNode'](context);
57+
}
58+
4659
let kRateNode = new window[options.nodeName](context, options.nodeOptions);
4760
let aRateNode = new window[options.nodeName](context, options.nodeOptions);
4861
let inverter = new GainNode(context, {gain: -1});
@@ -81,16 +94,30 @@ function doTest(context, should, options) {
8194
});
8295
});
8396

97+
// Connect the source, if specified.
98+
if (src) {
99+
src.connect(kRateNode);
100+
src.connect(aRateNode);
101+
}
102+
84103
// The k-rate result is channel 0, and the a-rate result is channel 1.
85-
src.connect(kRateNode).connect(merger, 0, 0);
86-
src.connect(aRateNode).connect(merger, 0, 1);
104+
kRateNode.connect(merger, 0, 0);
105+
aRateNode.connect(merger, 0, 1);
87106

88107
// Compute the difference between the a-rate and k-rate results and send
89108
// that to channel 2.
90109
kRateNode.connect(merger, 0, 2);
91110
aRateNode.connect(inverter).connect(merger, 0, 2);
92111

93-
src.start();
112+
if (src) {
113+
src.start();
114+
} else {
115+
// If there's no source, then assume the test nodes are sources and start
116+
// them.
117+
kRateNode.start();
118+
aRateNode.start();
119+
}
120+
94121
return context.startRendering().then(renderedBuffer => {
95122
let kRateOutput = renderedBuffer.getChannelData(0);
96123
let aRateOutput = renderedBuffer.getChannelData(1);
@@ -113,5 +140,16 @@ function doTest(context, should, options) {
113140
options.prefix
114141
}: Difference between a-rate and k-rate ${options.nodeName}`)
115142
.notBeConstantValueOf(0);
143+
144+
if (options.verifyPieceWiseConstant) {
145+
// Verify that the output from the k-rate parameter is step-wise
146+
// constant.
147+
for (let k = 0; k < kRateOutput.length; k += 128) {
148+
should(
149+
kRateOutput.slice(k, k + 128),
150+
`${options.prefix} k-rate output [${k}: ${k + 127}]`)
151+
.beConstantValueOf(kRateOutput[k]);
152+
}
153+
}
116154
});
117155
}

webaudio/the-audio-api/the-audioparam-interface/k-rate-constant-source.html

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<script src="/resources/testharnessreport.js"></script>
77
<script src="/webaudio/resources/audit-util.js"></script>
88
<script src="/webaudio/resources/audit.js"></script>
9+
<script src="automation-rate-testing.js"></script>
910
</head>
1011

1112
<body>
@@ -25,54 +26,22 @@
2526
length: testDuration * sampleRate
2627
});
2728

28-
let merger = new ChannelMergerNode(
29-
context, {numberOfInputs: context.numberOfChannels});
30-
merger.connect(context.destination);
31-
let inverter = new GainNode(context, {gain: -1});
32-
inverter.connect(merger, 0, 2);
33-
34-
let kRateNode = new ConstantSourceNode(context);
35-
let aRateNode = new ConstantSourceNode(context);
36-
37-
kRateNode.connect(merger, 0, 0);
38-
aRateNode.connect(merger, 0, 1);
39-
40-
kRateNode.connect(merger, 0, 2);
41-
aRateNode.connect(inverter);
42-
43-
// Set the rate
44-
kRateNode.offset.automationRate = 'k-rate';
45-
46-
// Automate the offset
47-
kRateNode.offset.setValueAtTime(0, 0);
48-
kRateNode.offset.linearRampToValueAtTime(10, testDuration);
49-
50-
aRateNode.offset.setValueAtTime(0, 0);
51-
aRateNode.offset.linearRampToValueAtTime(10, testDuration);
52-
53-
kRateNode.start();
54-
aRateNode.start();
55-
56-
context.startRendering()
57-
.then(audioBuffer => {
58-
let kRateOut = audioBuffer.getChannelData(0);
59-
let aRateOut = audioBuffer.getChannelData(1);
60-
let diff = audioBuffer.getChannelData(2);
61-
62-
// Verify that the outputs are different.
63-
should(diff, 'Difference between a-rate and k-rate outputs')
64-
.notBeConstantValueOf(0);
65-
66-
// Verify that the constant source node output is step-wise
67-
// constant.
68-
for (let k = 0; k < kRateOut.length; k += 128) {
69-
should(
70-
kRateOut.slice(k, k + 128),
71-
`k-rate output [${k}: ${k + 127}]`)
72-
.beConstantValueOf(kRateOut[k]);
29+
doTest(context, should, {
30+
sourceNodeName: 'none',
31+
verifyPieceWiseConstant: true,
32+
nodeName: 'ConstantSourceNode',
33+
prefix: 'k-rate offset',
34+
rateSettings: [{name: 'offset', value: 'k-rate'}],
35+
automations: [{
36+
name: 'offset',
37+
methods: [
38+
{name: 'setValueAtTime', options: [0, 0]}, {
39+
name: 'linearRampToValueAtTime',
40+
options: [10, testDuration]
7341
}
74-
})
75-
.then(() => task.done());
42+
]
43+
}]
44+
}).then(() => task.done());
7645
});
7746

7847
audit.run();

webaudio/the-audio-api/the-audioparam-interface/k-rate-panner.html

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@
2323

2424
[{name: 'positionX', initial: 0, final: 1000},
2525
{name: 'positionY', initial: 0, final: 1000},
26-
{name: 'orientationX', initial: .1, final: 1000},
27-
{name: 'orientationY', initial: .1, final: 1000},
28-
{name: 'orientationZ', initial: .1, final: 1000},
26+
{name: 'orientationX', initial: 1, final: 10},
27+
{name: 'orientationY', initial: 1, final: 10},
28+
{name: 'orientationZ', initial: 1, final: 10},
2929
].forEach(paramProperty => {
3030
audit.define('Panner k-rate ' + paramProperty.name, (task, should) => {
3131
// Arbitrary sample rate and duration.
3232
let sampleRate = 8000;
33-
let testDuration = 1;
33+
let testDuration = 5 * 128 / sampleRate;
3434
let context = new OfflineAudioContext({
3535
numberOfChannels: 3,
3636
sampleRate: sampleRate,
3737
length: testDuration * sampleRate
3838
});
3939

4040
doTest(context, should, {
41+
sourceNodeName: 'ConstantSourceNode',
42+
verifyPieceWiseConstant: true,
4143
nodeName: 'PannerNode',
4244
// Make the source directional so orientation matters, and set some
4345
// defaults for the position and orientation so that we're not on an
@@ -46,11 +48,11 @@
4648
nodeOptions: {
4749
distanceModel: 'inverse',
4850
coneOuterAngle: 360,
49-
coneInnerAngle: 10,
50-
positionX: 10,
51-
positionY: 10,
52-
positionZ: 10,
53-
orientationX: 1,
51+
coneInnerAngle: 0,
52+
positionX: 1,
53+
positionY: 1,
54+
positionZ: 1,
55+
orientationX: 0,
5456
orientationY: 1,
5557
orientationZ: 1
5658
},

0 commit comments

Comments
 (0)