OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 | 3 |
4 <head> | 4 <head> |
5 <script src="../resources/js-test.js"></script> | 5 <script src="../resources/js-test.js"></script> |
6 <script src="resources/compatibility.js"></script> | 6 <script src="resources/compatibility.js"></script> |
7 <script src="resources/audio-testing.js"></script> | 7 <script src="resources/audio-testing.js"></script> |
8 <script src="resources/late-start-testing.js"></script> | |
9 </head> | 8 </head> |
10 | 9 |
11 <body> | 10 <body> |
12 <script> | 11 <script> |
13 description('Test the late call of start(0) of BufferSource.'); | 12 description('Test the late call of start(0) of BufferSource.'); |
14 window.jsTestIsAsync = true; | 13 window.jsTestIsAsync = true; |
15 | 14 |
15 var sampleRate = 44100; | |
16 var renderDuration = 0.25; | |
17 | |
16 var audit = Audit.createTaskRunner(); | 18 var audit = Audit.createTaskRunner(); |
17 | 19 |
18 var sampleRate = 44100; | 20 audit.defineTask('test-late-start', function (done) { |
21 var context = new OfflineAudioContext(1, renderDuration * sampleRate, samp leRate); | |
22 var dcOffsetbuffer = createConstantBuffer(context, 1, 1.0); | |
23 var source = context.createBufferSource(); | |
24 source.buffer = dcOffsetbuffer; | |
25 source.loop = true; | |
26 source.connect(context.destination); | |
19 | 27 |
20 // The long render length (30 seconds) is to make sure the |onstatechange| | 28 // Schedule source.start(0) at 0.01 second. The specified timing of |
21 // event gets fired to start the source, which can take quite a bit of time. | 29 // start() call is already passed in terms of the context time. So the |
22 var renderLength = 30; | 30 // argument |0| will be clamped to the current context time. |
31 // | |
32 // With the sample rate of 44100, 0.01 second is 441 samples. Rounding | |
33 // it down to the render quantum gives 384 samples. This is clearly larger | |
34 // than a single render quantum. | |
35 // | |
36 // See issue: crbug.com/462167 | |
37 context.suspend(0.01).then(function () { | |
38 source.start(0); | |
39 context.resume(); | |
40 }); | |
23 | 41 |
24 var context = new OfflineAudioContext(1, sampleRate * renderLength, sampleRa te); | 42 // Start rendering and verify result: this verifies if 1) the rendered |
25 var dcOffsetbuffer = createConstantBuffer(context, 1000, 1.0); | 43 // buffer contains at least one non-zero value and 2) the non-zero value i s |
26 var source = context.createBufferSource(); | 44 // found later than the first output sample. |
27 source.buffer = dcOffsetbuffer; | 45 context.startRendering().then(function (buffer) { |
28 | 46 |
29 // Test the buffer node is rendered correctly when the start time of start() | 47 var channelData = buffer.getChannelData(0); |
30 // call is in the past in terms of the context time. | 48 var nonZeroValueIndex = channelData.findIndex(function (element, index) { |
31 runLateStartTest(audit, context, source); | 49 if (element !== 0) |
50 return index; | |
Raymond Toy
2015/12/02 19:33:41
Would it be better to return explicitly true or fa
hongchan
2015/12/03 19:28:31
Done.
| |
51 }); | |
52 | |
53 if (nonZeroValueIndex === -1) | |
54 testFailed('The rendered buffer was all zeros.'); | |
55 else if (nonZeroValueIndex === 0) | |
56 testFailed('The first sample was non-zero value. It should be zero.'); | |
57 else | |
58 testPassed('The rendered buffer contains non-zero values after the fir st sample.'); | |
Raymond Toy
2015/12/02 19:33:41
Should we check that the first nonZeroValueIndex i
hongchan
2015/12/03 19:28:31
Done.
| |
59 | |
60 }).then(done); | |
61 }); | |
62 | |
63 audit.defineTask('finish-test', function (done) { | |
64 done(); | |
65 finishJSTest(); | |
66 }); | |
67 | |
68 audit.runTasks(); | |
32 | 69 |
33 successfullyParsed = true; | 70 successfullyParsed = true; |
34 </script> | 71 </script> |
35 </body> | 72 </body> |
36 | 73 |
37 </html> | 74 </html> |
OLD | NEW |