OLD | NEW |
1 function runLateStartTest(audit, context, node) { | 1 function runLateStartTest(audit, context, node) { |
2 | 2 |
3 // Set up a dummy signal path to keep the audio context running and spend | 3 // Set up a dummy signal path to keep the audio context running and spend |
4 // processing time before calling start(0). | 4 // processing time before calling start(0). |
5 var osc = context.createOscillator(); | 5 var osc = context.createOscillator(); |
6 var silent = context.createGain(); | 6 var silent = context.createGain(); |
7 | 7 |
8 osc.connect(silent); | 8 osc.connect(silent); |
9 silent.connect(context.destination); | 9 silent.connect(context.destination); |
10 silent.gain.setValueAtTime(0.0, 0); | 10 silent.gain.setValueAtTime(0.0, 0); |
11 osc.start(); | 11 osc.start(); |
12 | 12 |
13 node.connect(context.destination); | 13 node.connect(context.destination); |
14 | 14 |
15 // Task: schedule a suspend and start rendering. | 15 // Task: schedule a suspend and start rendering. |
16 audit.defineTask('test-late-start', function (done) { | 16 audit.define('test-late-start', (task, should) => { |
17 // The node's start time will be clamped to the render quantum boundary | 17 // The node's start time will be clamped to the render quantum boundary |
18 // >0.1 sec. Thus the rendered buffer will have non-zero frames. | 18 // >0.1 sec. Thus the rendered buffer will have non-zero frames. |
19 // See issue: crbug.com/462167 | 19 // See issue: crbug.com/462167 |
20 context.suspend(0.1).then(() => { | 20 context.suspend(0.1).then(() => { |
21 node.start(0); | 21 node.start(0); |
22 context.resume(); | 22 context.resume(); |
23 }); | 23 }); |
24 | 24 |
25 // Start rendering and verify result: this verifies if 1) the rendered | 25 // Start rendering and verify result: this verifies if 1) the rendered |
26 // buffer contains at least one non-zero value and 2) the non-zero value is | 26 // buffer contains at least one non-zero value and 2) the non-zero value is |
27 // found later than the first output sample. | 27 // found later than the first output sample. |
28 context.startRendering().then(function (buffer) { | 28 context.startRendering().then(function (buffer) { |
29 var nonZeroValueIndex = -1; | 29 var nonZeroValueIndex = -1; |
30 var channelData = buffer.getChannelData(0); | 30 var channelData = buffer.getChannelData(0); |
31 for (var i = 0; i < channelData.length; i++) { | 31 for (var i = 0; i < channelData.length; i++) { |
32 if (channelData[i] !== 0) { | 32 if (channelData[i] !== 0) { |
33 nonZeroValueIndex = i; | 33 nonZeroValueIndex = i; |
34 break; | 34 break; |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 var success = | 38 should(nonZeroValueIndex, 'The index of first non-zero value') |
39 Should('The index of first non-zero value',nonZeroValueIndex) | |
40 .notBeEqualTo(-1); | 39 .notBeEqualTo(-1); |
41 success = Should('The first sample value', channelData[0]) | 40 should(channelData[0], 'The first sample value') |
42 .beEqualTo(0) && success; | 41 .beEqualTo(0); |
43 Should('The rendered buffer', success) | 42 task.done(); |
44 .summarize('contains non-zero values after the first sample', | |
45 'was all zeros or has non-zero first sample.'); | |
46 done(); | |
47 }); | 43 }); |
48 }); | 44 }); |
49 | 45 |
50 audit.runTasks(); | 46 audit.run(); |
51 } | 47 } |
OLD | NEW |