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>
12 description("Test AudioBufferSourceNode looping without explicit duration");
18 var sampleRate
= 44100;
20 // How many loops of the source we want to render. Any whole number greater than 1 will work.
22 var renderFrames
= sourceFrames
* loopCount
;
25 function checkResult(renderedBuffer
) {
29 expected
= buffer
.getChannelData(0);
30 output
= renderedBuffer
.getChannelData(0);
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 original 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
;
49 testPassed("Source looped correctly");
51 testFailed("First incorrect sample at index " + badIndex
);
56 window
.jsTestIsAsync
= true;
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
);
66 // Loop the source, and start the source with an offset, but without a duration. In this
67 // case, the source should loop "forever". See crbug.com/457009. The case where the
68 // duration is given is covered in other tests.
71 context
.startRendering()