OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Test AudioBufferSourceNode looping without explicit duration</title> |
| 5 <script src="resources/compatibility.js"></script> |
| 6 <script src="resources/audio-testing.js"></script> |
| 7 <script src="../resources/js-test.js"></script> |
| 8 </head> |
| 9 |
| 10 <body> |
| 11 <script> |
| 12 description("Test AudioBufferSourceNode looping without explicit duration"
); |
| 13 |
| 14 var context; |
| 15 var buffer; |
| 16 var output; |
| 17 var expected; |
| 18 var sampleRate = 44100; |
| 19 var sourceFrames = 8; |
| 20 // How many loops of the source we want to render. Any whole number great
er than 1 will work. |
| 21 var loopCount = 4; |
| 22 var renderFrames = sourceFrames * loopCount; |
| 23 |
| 24 |
| 25 function checkResult(renderedBuffer) { |
| 26 var badIndex = -1; |
| 27 var success = true; |
| 28 |
| 29 expected = buffer.getChannelData(0); |
| 30 output = renderedBuffer.getChannelData(0); |
| 31 |
| 32 // Verify the output has the expected data. The actual output should be
a loopCount copies |
| 33 // of the source buffer. |
| 34 for (var k = 0; k < loopCount; ++k) { |
| 35 // Check that this current subset is a linear ramp matching the origin
al source. |
| 36 for (var n = 0; n < sourceFrames; ++n) { |
| 37 if (expected[n] != output[n + k * sourceFrames]) { |
| 38 // Remember the first bad sample and exit all loops now. |
| 39 badIndex = n + k * sourceFrames; |
| 40 success = false; |
| 41 break; |
| 42 } |
| 43 } |
| 44 if (!success) |
| 45 break; |
| 46 } |
| 47 |
| 48 if (success) { |
| 49 testPassed("Source looped correctly"); |
| 50 } else { |
| 51 testFailed("First incorrect sample at index " + badIndex); |
| 52 } |
| 53 } |
| 54 |
| 55 function runTest() { |
| 56 window.jsTestIsAsync = true; |
| 57 |
| 58 // Create a short linear ramp and enable looping. The test will verify
that the ramp was |
| 59 // looped the appropriate number of times. |
| 60 context = new OfflineAudioContext(1, renderFrames, sampleRate); |
| 61 buffer = createLinearRampBuffer(context, sourceFrames); |
| 62 var source = context.createBufferSource(); |
| 63 source.buffer = buffer; |
| 64 source.connect(context.destination); |
| 65 |
| 66 // Loop the source, and start the source with an offset, but without a d
uration. In this |
| 67 // case, the source should loop "forever". See crbug.com/457009. The c
ase where the |
| 68 // duration is given is covered in other tests. |
| 69 source.loop = true; |
| 70 source.start(0, 0); |
| 71 context.startRendering() |
| 72 .then(checkResult) |
| 73 .then(finishJSTest); |
| 74 } |
| 75 |
| 76 runTest(); |
| 77 </script> |
| 78 </body> |
| 79 </html> |
OLD | NEW |