| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <script src="../resources/js-test.js"></script> | |
| 5 <script src="resources/audit-util.js"></script> | |
| 6 <script src="resources/audio-testing.js"></script> | |
| 7 <script src="resources/compatibility.js"></script> | |
| 8 </head> | |
| 9 <body> | |
| 10 <script> | |
| 11 description("Basic tests for AudioBuffer."); | |
| 12 | |
| 13 var sampleRate = 44100.0 | |
| 14 var lengthInSeconds = 2; | |
| 15 var numberOfChannels = 4; | |
| 16 | |
| 17 var context = new AudioContext(); | |
| 18 var buffer = context.createBuffer(numberOfChannels, sampleRate * lengthInSeconds
, sampleRate); | |
| 19 | |
| 20 if (buffer.sampleRate === sampleRate) | |
| 21 testPassed("sampleRate has been set correctly."); | |
| 22 else | |
| 23 testFailed("sampleRate should be set correctly."); | |
| 24 | |
| 25 if (buffer.length === sampleRate * lengthInSeconds) | |
| 26 testPassed("length has been set correctly."); | |
| 27 else | |
| 28 testFailed("length should be set correctly"); | |
| 29 | |
| 30 if (buffer.duration === lengthInSeconds) | |
| 31 testPassed("duration has been set correctly."); | |
| 32 else | |
| 33 testFailed("duration should be set correctly."); | |
| 34 | |
| 35 if (buffer.numberOfChannels === numberOfChannels) | |
| 36 testPassed("numberOfChannels has been set correctly."); | |
| 37 else | |
| 38 testFailed("numberOfChannels should be set correctly."); | |
| 39 | |
| 40 for (var index = 0; index < buffer.numberOfChannels; ++index) { | |
| 41 if (buffer.getChannelData(index) instanceof window.Float32Array) | |
| 42 testPassed("getChannelData(" + index + ") returns a Float32Array object.
"); | |
| 43 else | |
| 44 testFailed("getChannelData(" + index + ") should return a Float32Array o
bject."); | |
| 45 } | |
| 46 | |
| 47 try { | |
| 48 buffer.getChannelData(buffer.numberOfChannels); | |
| 49 testFailed("Exception should be thrown when index is not less than numberOfC
hannels."); | |
| 50 } catch(e) { | |
| 51 testPassed("Exception has been thrown correctly when index is not less than
numberOfChannels."); | |
| 52 } | |
| 53 | |
| 54 var buffer2 = context.createBuffer(1, 1000, 24576); | |
| 55 var expectedDuration = 1000/24576; | |
| 56 | |
| 57 if (buffer2.duration == expectedDuration) | |
| 58 testPassed("duration has expected accuracy."); | |
| 59 else | |
| 60 testFailed("duration is " + buffer2.duration + " sec instead of " + expected
Duration + " sec."); | |
| 61 </script> | |
| 62 | |
| 63 </body> | |
| 64 </html> | |
| OLD | NEW |