OLD | NEW |
| (Empty) |
1 <!doctype html> | |
2 <html> | |
3 <head> | |
4 <script src="../resources/js-test.js"></script> | |
5 <script src="resources/compatibility.js"></script> | |
6 <script src="resources/audit-util.js"></script> | |
7 <script src="resources/audio-testing.js"></script> | |
8 <title>OfflineAudioContext.startRendering Promise with oncomplete</title> | |
9 </head> | |
10 | |
11 <body> | |
12 <script> | |
13 description("Test OfflineAudioContext.startRendering Promise with oncomple
te"); | |
14 | |
15 var context; | |
16 var promise; | |
17 var renderedData; | |
18 var promiseData; | |
19 | |
20 var sampleRate = 48000; | |
21 var renderSeconds = 1; | |
22 var renderFrames = sampleRate * renderSeconds; | |
23 var contextChannels = 2; | |
24 | |
25 function compareData() { | |
26 // The spec implies that the same buffer is returned by both oncomplete
and the promise. | |
27 // Check that they are identical. | |
28 if (renderedData === promiseData) { | |
29 testPassed("AudioBuffer returned by oncomplete and promise are identic
al"); | |
30 } else { | |
31 testFailed("AudioBuffer returned by oncomplete and promise are NOT ide
ntical"); | |
32 } | |
33 finishJSTest(); | |
34 } | |
35 | |
36 function checkResult (event) { | |
37 renderedData = event.renderedBuffer; | |
38 promise.then(function (result) { | |
39 promiseData = result; | |
40 compareData(); | |
41 }); | |
42 } | |
43 | |
44 // Create an offline context and verify that both the oncomplete and promi
se are returned with | |
45 // the same stuff. | |
46 function runTest() { | |
47 window.jsTestIsAsync = true; | |
48 | |
49 context = new OfflineAudioContext(contextChannels, renderFrames, sampleR
ate); | |
50 | |
51 var buffer = context.createBuffer(contextChannels, renderFrames, sampleR
ate); | |
52 for (var k = 0; k < renderFrames; ++k) { | |
53 buffer.getChannelData(0)[k] = 1; | |
54 buffer.getChannelData(1)[k] = 2; | |
55 } | |
56 | |
57 var source = context.createBufferSource(); | |
58 source.buffer = buffer; | |
59 source.connect(context.destination); | |
60 source.start(); | |
61 | |
62 context.oncomplete = checkResult; | |
63 | |
64 promise = context.startRendering(); | |
65 | |
66 } | |
67 | |
68 runTest(); | |
69 successfullyParsed = true; | |
70 </script> | |
71 | |
72 </body> | |
73 </html> | |
OLD | NEW |