5 <script src=
"../resources/js-test.js"></script>
6 <script src=
"resources/compatibility.js"></script>
7 <script src=
"resources/audio-testing.js"></script>
12 description('AudioBufferSourceNode: test the "zero" playbackRate.');
13 window
.jsTestIsAsync
= true;
15 // Sample rate should be power of 128 to observe the change of AudioParam at
16 // the beginning of rendering quantum. (playbackRate is k-rate) This is the
17 // minimum sample rate in the valid sample rate range.
18 var sampleRate
= 4096;
20 // The render duration in seconds, and the length in samples.
21 var renderDuration
= 1.0;
22 var renderLength
= renderDuration
* sampleRate
;
24 var context
= new OfflineAudioContext(1, renderLength
, sampleRate
);
25 var audit
= Audit
.createTaskRunner();
28 // Task: Render the actual buffer and compare with the reference.
29 audit
.defineTask('synthesize-verify', function (done
) {
30 var ramp
= context
.createBufferSource();
31 var rampBuffer
= createLinearRampBuffer(context
, renderLength
);
32 ramp
.buffer
= rampBuffer
;
34 ramp
.connect(context
.destination
);
37 // Leave the playbackRate as 1 for the first half, then change it
38 // to zero at the exact half. The zero playback rate should hold the
39 // sample value of the buffer index at the moment. (sample-and-hold)
40 ramp
.playbackRate
.setValueAtTime(1.0, 0.0);
41 ramp
.playbackRate
.setValueAtTime(0.0, renderDuration
/ 2);
43 context
.startRendering().then(function (renderedBuffer
) {
44 var data
= renderedBuffer
.getChannelData(0);
45 var rampData
= rampBuffer
.getChannelData(0);
46 var half
= rampData
.length
/ 2;
49 for (var i
= 1; i
< rampData
.length
; i
++) {
51 // Before the half position, the actual should match with the
52 // original ramp data.
53 if (data
[i
] !== rampData
[i
]) {
58 // From the half position, the actual value should not change.
59 if (data
[i
] !== rampData
[half
]) {
67 testPassed('The zero playbackRate held the sample value correctly.');
69 testFailed('The zero playbackRate should hold the sample value. ' +
70 'Expected ' + rampData
[half
] + ' but got ' + data
[i
] + ' at the index ' +
76 audit
.defineTask('finish', function (done
) {
86 successfullyParsed
= true;