Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test Start Grain with Delayed Buffer Setting </title> | 4 <title>Test Start Grain with Delayed Buffer Setting </title> |
| 5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | |
| 6 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 8 </head> | 9 </head> |
| 9 | 10 |
| 10 <body> | 11 <body> |
| 11 <script> | 12 <script> |
| 12 description("Test setting the source buffer after starting the grain"); | 13 let audit = Audit.createTaskRunner(); |
| 14 let context; | |
| 15 let source; | |
| 16 let buffer; | |
| 17 let renderedData; | |
| 13 | 18 |
| 14 var context; | 19 let sampleRate = 44100; |
| 15 var source; | |
| 16 var buffer; | |
| 17 var renderedData; | |
| 18 | 20 |
| 19 var sampleRate = 44100; | 21 let testDurationSec = 1; |
| 22 let testDurationSamples = testDurationSec * sampleRate; | |
| 23 let startTime = 0.9 * testDurationSec; | |
| 20 | 24 |
| 21 var testDurationSec = 1; | 25 audit.define("Test setting the source buffer after starting the grain", |
| 22 var testDurationSamples = testDurationSec * sampleRate; | 26 function (task, should) { |
| 23 var startTime = 0.9 * testDurationSec; | 27 context = new OfflineAudioContext(1, testDurationSamples, |
| 24 | 28 sampleRate); |
| 25 function runTest() { | |
| 26 window.jsTestIsAsync = true; | |
| 27 | |
| 28 context = new OfflineAudioContext(1, testDurationSamples, sampleRate); | |
| 29 context.oncomplete = checkResult; | |
| 30 | 29 |
| 31 buffer = createConstantBuffer(context, testDurationSamples, 1); | 30 buffer = createConstantBuffer(context, testDurationSamples, 1); |
| 32 source = context.createBufferSource(); | 31 source = context.createBufferSource(); |
| 33 source.connect(context.destination); | 32 source.connect(context.destination); |
| 34 | 33 |
| 35 // Start the source BEFORE we set the buffer. The grain offset and dur ation aren't | 34 // Start the source BEFORE we set the buffer. The grain offset and dur ation aren't |
| 36 // important, as long as we specify some offset. | 35 // important, as long as we specify some offset. |
| 37 source.start(startTime, .1); | 36 source.start(startTime, .1); |
| 38 source.buffer = buffer; | 37 source.buffer = buffer; |
| 39 | 38 |
| 40 // Render it! | 39 // Render it! |
| 41 context.startRendering(); | 40 context.startRendering() |
| 41 .then(function (buffer) { | |
| 42 checkResult(buffer, should); | |
| 43 }) | |
| 44 .then(task.done.bind(task));; | |
| 45 }); | |
| 46 | |
| 47 function checkResult(buffer, should) { | |
| 48 let success = false; | |
| 49 | |
| 50 renderedData = buffer.getChannelData(0); | |
| 51 | |
| 52 // Check that the rendered data is not all zeroes. Any non-zero data me ans the test | |
| 53 // passed. | |
|
hongchan
2017/01/04 21:40:55
Just a thought: perhaps we need should().beNonZero
Raymond Toy
2017/01/04 21:44:00
Only if we add should().beZero(). :-)
Both would
hongchan
2017/01/04 21:53:36
should().beZero() can be achieved by should().beCo
| |
| 54 let startFrame = Math.round(startTime * sampleRate); | |
| 55 for (k = 0; k < renderedData.length; ++k) { | |
| 56 if (renderedData[k]) { | |
| 57 success = true; | |
| 58 break; | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 should(success, "Buffer was played").beTrue(); | |
| 42 } | 63 } |
| 43 | 64 |
| 44 function checkResult(event) { | 65 audit.run(); |
| 45 var success = false; | |
| 46 | |
| 47 renderedData = event.renderedBuffer.getChannelData(0); | |
| 48 | |
| 49 // Check that the rendered data is not all zeroes. Any non-zero data means the test | |
| 50 // passed. | |
| 51 var startFrame = Math.round(startTime * sampleRate); | |
| 52 for (k = 0; k < renderedData.length; ++k) { | |
| 53 if (renderedData[k]) { | |
| 54 success = true; | |
| 55 break; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 if (success) | |
| 60 testPassed("Buffer was played."); | |
| 61 else | |
| 62 testFailed("Buffer was not played."); | |
| 63 | |
| 64 finishJSTest(); | |
| 65 } | |
| 66 | |
| 67 runTest(); | |
| 68 successfullyParsed = true; | |
| 69 </script> | 66 </script> |
| 70 </body> | 67 </body> |
| 71 </html> | 68 </html> |
| OLD | NEW |