| <!doctype html> |
| <html> |
| <head> |
| <script src="../resources/js-test.js"></script> |
| <script src="resources/compatibility.js"></script> |
| <script src="resources/audio-testing.js"></script> |
| <title>OfflineAudioContext.startRendering Promise with oncomplete</title> |
| </head> |
| |
| <body> |
| <script> |
| description("Test OfflineAudioContext.startRendering Promise with oncomplete"); |
| |
| var context; |
| var promise; |
| var renderedData; |
| var promiseData; |
| |
| var sampleRate = 48000; |
| var renderSeconds = 1; |
| var renderFrames = sampleRate * renderSeconds; |
| var contextChannels = 2; |
| |
| function compareData() { |
| // The spec implies that the same buffer is returned by both oncomplete and the promise. |
| // Check that they are identical. |
| if (renderedData === promiseData) { |
| testPassed("AudioBuffer returned by oncomplete and promise are identical"); |
| } else { |
| testFailed("AudioBuffer returned by oncomplete and promise are NOT identical"); |
| } |
| finishJSTest(); |
| } |
| |
| function checkResult (event) { |
| renderedData = event.renderedBuffer; |
| promise.then(function (result) { |
| promiseData = result; |
| compareData(); |
| }); |
| } |
| |
| // Create an offline context and verify that both the oncomplete and promise are returned with |
| // the same stuff. |
| function runTest() { |
| window.jsTestIsAsync = true; |
| |
| context = new OfflineAudioContext(contextChannels, renderFrames, sampleRate); |
| |
| var buffer = context.createBuffer(contextChannels, renderFrames, sampleRate); |
| for (var k = 0; k < renderFrames; ++k) { |
| buffer.getChannelData(0)[k] = 1; |
| buffer.getChannelData(1)[k] = 2; |
| } |
| |
| var source = context.createBufferSource(); |
| source.buffer = buffer; |
| source.connect(context.destination); |
| source.start(); |
| |
| context.oncomplete = checkResult; |
| |
| promise = context.startRendering(); |
| |
| } |
| |
| runTest(); |
| successfullyParsed = true; |
| </script> |
| |
| </body> |
| </html> |