4 <title>Test Start Grain with Delayed Buffer Setting
</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 setting the source buffer after starting the grain");
19 var sampleRate
= 44100;
21 var testDurationSec
= 1;
22 var testDurationSamples
= testDurationSec
* sampleRate
;
23 var startTime
= 0.9 * testDurationSec
;
26 window
.jsTestIsAsync
= true;
28 context
= new OfflineAudioContext(1, testDurationSamples
, sampleRate
);
29 context
.oncomplete
= checkResult
;
31 buffer
= createConstantBuffer(context
, testDurationSamples
, 1);
32 source
= context
.createBufferSource();
33 source
.connect(context
.destination
);
35 // Start the source BEFORE we set the buffer. The grain offset and duration aren't
36 // important, as long as we specify some offset.
37 source
.start(startTime
, .1);
38 source
.buffer
= buffer
;
41 context
.startRendering();
44 function checkResult(event
) {
47 renderedData
= event
.renderedBuffer
.getChannelData(0);
49 // Check that the rendered data is not all zeroes. Any non-zero data means the test
51 var startFrame
= Math
.round(startTime
* sampleRate
);
52 for (k
= 0; k
< renderedData
.length
; ++k
) {
53 if (renderedData
[k
]) {
60 testPassed("Buffer was played.");
62 testFailed("Buffer was not played.");
68 successfullyParsed
= true;