| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 | 2 |
| 3 <html> | 3 <html> |
| 4 <head> | 4 <head> |
| 5 <script src="resources/audio-testing.js"></script> | 5 <script src="resources/audio-testing.js"></script> |
| 6 <script src="resources/compatibility.js"></script> | 6 <script src="resources/compatibility.js"></script> |
| 7 <script src="resources/audiobuffersource-testing.js"></script> | 7 <script src="resources/audiobuffersource-testing.js"></script> |
| 8 <script src="../resources/js-test.js"></script> | 8 <script src="../resources/js-test.js"></script> |
| 9 </head> | 9 </head> |
| 10 | 10 |
| 11 <body> | 11 <body> |
| 12 | |
| 13 <div id="description"></div> | |
| 14 <div id="console"></div> | |
| 15 | |
| 16 <script> | 12 <script> |
| 17 description("Tests AudioBufferSourceNode looping with a variety of loop points."
); | 13 description("Tests AudioBufferSourceNode looping with a variety of loop points."
); |
| 18 | 14 |
| 19 // The following test cases assume an AudioBuffer of length 8 whose PCM data is
a linear ramp, 0, 1, 2, 3,... | 15 // The following test cases assume an AudioBuffer of length 8 whose PCM data is
a linear ramp, 0, 1, 2, 3,... |
| 20 // |description| is optional and will be computed from the other parameters. |of
fsetFrame| is | 16 // |description| is optional and will be computed from the other parameters. |of
fsetFrame| is |
| 21 // optional and defaults to 0. | 17 // optional and defaults to 0. |
| 22 | 18 |
| 23 var tests = [ | 19 var tests = [ |
| 24 | 20 |
| 25 { description: "loop whole buffer by default with loopStart == loopEnd == 0", | 21 { description: "loop whole buffer by default with loopStart == loopEnd == 0", |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, | 125 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
| 130 | 126 |
| 131 { description: "illegal loop: loopEndFrame > bufferLength", | 127 { description: "illegal loop: loopEndFrame > bufferLength", |
| 132 loopStartFrame: 0, | 128 loopStartFrame: 0, |
| 133 loopEndFrame: 30000, | 129 loopEndFrame: 30000, |
| 134 renderFrames: 16, | 130 renderFrames: 16, |
| 135 playbackRate: 1, | 131 playbackRate: 1, |
| 136 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, | 132 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
| 137 | 133 |
| 138 // Start a loop with a duration longer than the buffer. The output should be th
e data from frame 1 | 134 // Start a loop with a duration longer than the buffer. The output should be th
e data from frame 1 |
| 139 // to 6, and then looping from 3 to 5 until 30 frames have been played. | 135 // to 6, and then looping from 3 to 5 until 20 frames have been played. |
| 140 { description: "loop from 3 -> 6 with offset 1 for 31 frames", | 136 { description: "loop from 3 -> 6 with offset 1 for 20 frames", |
| 141 loopStartFrame: 3, | 137 loopStartFrame: 3, |
| 142 loopEndFrame: 6, | 138 loopEndFrame: 6, |
| 143 playbackRate: 1, | 139 playbackRate: 1, |
| 144 offsetFrame: 1, | 140 offsetFrame: 1, |
| 145 durationFrames: 30, | 141 renderFrames: 30, |
| 146 expected: [1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5
, 3, 4, 5, 3, 4, 5, 3] }, | 142 durationFrames: 20, |
| 143 expected: [1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0] }, |
| 144 |
| 145 // Start a loop with a duration less than the length of the looping frames. The
output should be |
| 146 // the data from frame 1 to 3, and then stopping because duration = 3 |
| 147 { description: "loop from 3 -> 8 with offset 1 for 3 frames", |
| 148 loopStartFrame: 3, |
| 149 loopEndFrame: 8, |
| 150 playbackRate: 1, |
| 151 offsetFrame: 1, |
| 152 durationFrames: 3, |
| 153 renderFrames: 30, |
| 154 expected: [1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0] }, |
| 155 |
| 156 // Start a loop with a duration less than the length of the looping frames. The
output should be |
| 157 // the data from frame 1 to 3, and then stopping because duration = 3 |
| 158 { description: "loop from 3 -> 8 with offset 7 for 3 frames", |
| 159 loopStartFrame: 3, |
| 160 loopEndFrame: 8, |
| 161 playbackRate: 1, |
| 162 offsetFrame: 7, |
| 163 durationFrames: 3, |
| 164 renderFrames: 30, |
| 165 expected: [7, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0] } |
| 147 | 166 |
| 148 ]; | 167 ]; |
| 149 | 168 |
| 150 var sampleRate = 44100; | 169 var sampleRate = 44100; |
| 151 var buffer; | 170 var buffer; |
| 152 var bufferFrameLength = 8; | 171 var bufferFrameLength = 8; |
| 153 var testSpacingFrames = 32; | 172 var testSpacingFrames = 32; |
| 154 var testSpacingSeconds = testSpacingFrames / sampleRate; | 173 var testSpacingSeconds = testSpacingFrames / sampleRate; |
| 155 var totalRenderLengthFrames = tests.length * testSpacingFrames; | 174 var totalRenderLengthFrames = tests.length * testSpacingFrames; |
| 156 | 175 |
| 157 function runLoopTest(context, testNumber, test) { | 176 function runLoopTest(context, testNumber, test) { |
| 158 var source = context.createBufferSource(); | 177 var source = context.createBufferSource(); |
| 159 | 178 |
| 160 source.buffer = buffer; | 179 source.buffer = buffer; |
| 161 source.playbackRate.value = test.playbackRate; | 180 source.playbackRate.value = test.playbackRate; |
| 162 source.loop = true; | 181 source.loop = true; |
| 163 source.loopStart = test.loopStartFrame / context.sampleRate; | 182 source.loopStart = test.loopStartFrame / context.sampleRate; |
| 164 source.loopEnd = test.loopEndFrame / context.sampleRate; | 183 source.loopEnd = test.loopEndFrame / context.sampleRate; |
| 165 | 184 |
| 166 var offset = test.offsetFrame ? test.offsetFrame / context.sampleRate : 0; | 185 var offset = test.offsetFrame ? test.offsetFrame / context.sampleRate : 0; |
| 167 | 186 |
| 168 source.connect(context.destination); | 187 source.connect(context.destination); |
| 169 | 188 |
| 170 // Render each test one after the other, spaced apart by testSpacingSeconds. | 189 // Render each test one after the other, spaced apart by testSpacingSeconds. |
| 171 var startTime = testNumber * testSpacingSeconds; | 190 var startTime = testNumber * testSpacingSeconds; |
| 172 | 191 |
| 173 if (test.renderFrames) { | 192 // If durationFrames is given, run the test for the specified duration. |
| 193 if (test.durationFrames) { |
| 194 if (!test.renderFrames) { |
| 195 testFailed("renderFrames is required for test " + testNumber + ": "
+ test.description); |
| 196 } else { |
| 197 if (test.durationFrames > testSpacingFrames || test.durationFrames <
0) { |
| 198 testFailed("Test " + testNumber |
| 199 + ": durationFrames (" + test.durationFrames + ") outside th
e range [0, " |
| 200 + testSpacingFrames + "]"); |
| 201 } |
| 202 source.start(startTime, offset, test.durationFrames / context.sample
Rate); |
| 203 } |
| 204 } else if (test.renderFrames) { |
| 174 var duration = test.renderFrames / context.sampleRate; | 205 var duration = test.renderFrames / context.sampleRate; |
| 175 if (test.renderFrames > testSpacingFrames || test.renderFrames < 0) { | 206 if (test.renderFrames > testSpacingFrames || test.renderFrames < 0) { |
| 176 testFailed("Test " + testNumber | 207 testFailed("Test " + testNumber |
| 177 + ": renderFrames (" + test.renderFrames + ") outside the range
[0, " | 208 + ": renderFrames (" + test.renderFrames + ") outside the range
[0, " |
| 178 + testSpacingFrames + "]"); | 209 + testSpacingFrames + "]"); |
| 179 } | 210 } |
| 180 source.start(startTime, offset); | 211 source.start(startTime, offset); |
| 181 source.stop(startTime + duration); | 212 source.stop(startTime + duration); |
| 182 } else if (test.durationFrames) { | |
| 183 if (test.durationFrames > testSpacingFrames || test.durationFrames < 0)
{ | |
| 184 testFailed("Test " + testNumber | |
| 185 + ": durationFrames (" + test.durationFrames + ") outside the ra
nge [0, " | |
| 186 + testSpacingFrames + "]"); | |
| 187 } | |
| 188 source.start(startTime, offset, test.durationFrames / context.sampleRate
); | |
| 189 } else { | 213 } else { |
| 190 testFailed("Test " + testNumber + " must specify one of renderFrames or
durationFrames"); | 214 testFailed("Test " + testNumber + " must specify renderFrames and possib
ly durationFrames"); |
| 191 } | 215 } |
| 192 } | 216 } |
| 193 | 217 |
| 194 function runTest() { | 218 function runTest() { |
| 195 if (window.testRunner) { | |
| 196 testRunner.dumpAsText(); | |
| 197 testRunner.waitUntilDone(); | |
| 198 } | |
| 199 | |
| 200 window.jsTestIsAsync = true; | 219 window.jsTestIsAsync = true; |
| 201 | 220 |
| 202 // Create offline audio context. | 221 // Create offline audio context. |
| 203 var context = new OfflineAudioContext(1, totalRenderLengthFrames, sampleRate
); | 222 var context = new OfflineAudioContext(1, totalRenderLengthFrames, sampleRate
); |
| 204 buffer = createTestBuffer(context, bufferFrameLength); | 223 buffer = createTestBuffer(context, bufferFrameLength); |
| 205 | 224 |
| 206 for (var i = 0; i < tests.length; ++i) | 225 for (var i = 0; i < tests.length; ++i) |
| 207 runLoopTest(context, i, tests[i]); | 226 runLoopTest(context, i, tests[i]); |
| 208 | 227 |
| 209 context.oncomplete = checkAllTests; | 228 context.oncomplete = checkAllTests; |
| 210 context.startRendering(); | 229 context.startRendering(); |
| 211 } | 230 } |
| 212 | 231 |
| 213 runTest(); | 232 runTest(); |
| 214 successfullyParsed = true; | 233 successfullyParsed = true; |
| 215 | 234 |
| 216 </script> | 235 </script> |
| 217 | 236 |
| 218 </body> | 237 </body> |
| 219 </html> | 238 </html> |
| OLD | NEW |