4 <script src=
"../resources/js-test.js"></script>
5 <script src=
"resources/audio-testing.js"></script>
6 <script src=
"resources/compatibility.js"></script>
10 description("Basic tests for AudioBuffer.");
12 var sampleRate
= 44100.0
13 var lengthInSeconds
= 2;
14 var numberOfChannels
= 4;
16 var context
= new AudioContext();
17 var buffer
= context
.createBuffer(numberOfChannels
, sampleRate
* lengthInSeconds
, sampleRate
);
19 if (buffer
.sampleRate
=== sampleRate
)
20 testPassed("sampleRate has been set correctly.");
22 testFailed("sampleRate should be set correctly.");
24 if (buffer
.length
=== sampleRate
* lengthInSeconds
)
25 testPassed("length has been set correctly.");
27 testFailed("length should be set correctly");
29 if (buffer
.duration
=== lengthInSeconds
)
30 testPassed("duration has been set correctly.");
32 testFailed("duration should be set correctly.");
34 if (buffer
.numberOfChannels
=== numberOfChannels
)
35 testPassed("numberOfChannels has been set correctly.");
37 testFailed("numberOfChannels should be set correctly.");
39 for (var index
= 0; index
< buffer
.numberOfChannels
; ++index
) {
40 if (buffer
.getChannelData(index
) instanceof window
.Float32Array
)
41 testPassed("getChannelData(" + index
+ ") returns a Float32Array object.");
43 testFailed("getChannelData(" + index
+ ") should return a Float32Array object.");
47 buffer
.getChannelData(buffer
.numberOfChannels
);
48 testFailed("Exception should be thrown when index is not less than numberOfChannels.");
50 testPassed("Exception has been thrown correctly when index is not less than numberOfChannels.");
53 var buffer2
= context
.createBuffer(1, 1000, 24576);
54 var expectedDuration
= 1000/24576;
56 if (buffer2
.duration
== expectedDuration
)
57 testPassed("duration has expected accuracy.");
59 testFailed("duration is " + buffer2
.duration
+ " sec instead of " + expectedDuration
+ " sec.");