Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 | 2 |
| 3 <html> | 3 <html> |
| 4 <head> | 4 <head> |
| 5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | |
| 6 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 8 <script src="../resources/audiobuffersource-testing.js"></script> | 9 <script src="../resources/audiobuffersource-testing.js"></script> |
| 9 </head> | 10 </head> |
| 10 | 11 |
| 11 <body> | 12 <body> |
| 12 <script> | 13 <script> |
| 13 description("Tests AudioBufferSourceNode looping with a variety of loop points." ); | 14 let audit = Audit.createTaskRunner(); |
| 14 | 15 |
| 15 // The following test cases assume an AudioBuffer of length 8 whose PCM data is a linear ramp, 0, 1, 2, 3,... | 16 // The following test cases assume an AudioBuffer of length 8 whose PCM data is a linear ramp, 0, 1, 2, 3,... |
| 16 // |description| is optional and will be computed from the other parameters. |of fsetFrame| is | 17 // |description| is optional and will be computed from the other parameters. |of fsetFrame| is |
| 17 // optional and defaults to 0. | 18 // optional and defaults to 0. |
| 18 | 19 |
| 19 var tests = [ | 20 let tests = [ |
| 20 | 21 |
| 21 { description: "loop whole buffer by default with loopStart == loopEnd == 0", | 22 { description: "loop whole buffer by default with loopStart == loopEnd == 0", |
| 22 loopStartFrame: 0, | 23 loopStartFrame: 0, |
| 23 loopEndFrame: 0, | 24 loopEndFrame: 0, |
| 24 renderFrames: 16, | 25 renderFrames: 16, |
| 25 playbackRate: 1, | 26 playbackRate: 1, |
| 26 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, | 27 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
| 27 | 28 |
| 28 { description: "loop whole buffer explicitly", | 29 { description: "loop whole buffer explicitly", |
| 29 loopStartFrame: 0, | 30 loopStartFrame: 0, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 loopStartFrame: 3, | 160 loopStartFrame: 3, |
| 160 loopEndFrame: 8, | 161 loopEndFrame: 8, |
| 161 playbackRate: 1, | 162 playbackRate: 1, |
| 162 offsetFrame: 7, | 163 offsetFrame: 7, |
| 163 durationFrames: 3, | 164 durationFrames: 3, |
| 164 renderFrames: 30, | 165 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] } | 166 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] } |
| 166 | 167 |
| 167 ]; | 168 ]; |
| 168 | 169 |
| 169 var sampleRate = 44100; | 170 let sampleRate = 44100; |
| 170 var buffer; | 171 let buffer; |
| 171 var bufferFrameLength = 8; | 172 let bufferFrameLength = 8; |
| 172 var testSpacingFrames = 32; | 173 let testSpacingFrames = 32; |
| 173 var testSpacingSeconds = testSpacingFrames / sampleRate; | 174 let testSpacingSeconds = testSpacingFrames / sampleRate; |
| 174 var totalRenderLengthFrames = tests.length * testSpacingFrames; | 175 let totalRenderLengthFrames = tests.length * testSpacingFrames; |
| 175 | 176 |
| 176 function runLoopTest(context, testNumber, test) { | 177 function runLoopTest(context, testNumber, test, should) { |
| 177 var source = context.createBufferSource(); | 178 let source = context.createBufferSource(); |
| 178 | 179 |
| 179 source.buffer = buffer; | 180 source.buffer = buffer; |
| 180 source.playbackRate.value = test.playbackRate; | 181 source.playbackRate.value = test.playbackRate; |
| 181 source.loop = true; | 182 source.loop = true; |
| 182 source.loopStart = test.loopStartFrame / context.sampleRate; | 183 source.loopStart = test.loopStartFrame / context.sampleRate; |
| 183 source.loopEnd = test.loopEndFrame / context.sampleRate; | 184 source.loopEnd = test.loopEndFrame / context.sampleRate; |
| 184 | 185 |
| 185 var offset = test.offsetFrame ? test.offsetFrame / context.sampleRate : 0; | 186 let offset = test.offsetFrame ? test.offsetFrame / context.sampleRate : 0; |
| 186 | 187 |
| 187 source.connect(context.destination); | 188 source.connect(context.destination); |
| 188 | 189 |
| 189 // Render each test one after the other, spaced apart by testSpacingSeconds. | 190 // Render each test one after the other, spaced apart by testSpacingSeconds. |
| 190 var startTime = testNumber * testSpacingSeconds; | 191 let startTime = testNumber * testSpacingSeconds; |
| 191 | 192 |
| 192 // If durationFrames is given, run the test for the specified duration. | 193 // If durationFrames is given, run the test for the specified duration. |
| 193 if (test.durationFrames) { | 194 if (test.durationFrames) { |
| 194 if (!test.renderFrames) { | 195 if (!test.renderFrames) { |
| 195 testFailed("renderFrames is required for test " + testNumber + ": " + test.description); | 196 throw("renderFrames is required for test " + testNumber + ": " + tes t.description); |
|
hongchan
2017/01/18 18:13:03
Just throw? I have to think about this - do we hav
| |
| 196 } else { | 197 } else { |
| 197 if (test.durationFrames > testSpacingFrames || test.durationFrames < 0) { | 198 if (test.durationFrames > testSpacingFrames || test.durationFrames < 0) { |
| 198 testFailed("Test " + testNumber | 199 throw("Test " + testNumber |
| 199 + ": durationFrames (" + test.durationFrames + ") outside th e range [0, " | 200 + ": durationFrames (" + test.durationFrames + ") outside th e range [0, " |
| 200 + testSpacingFrames + "]"); | 201 + testSpacingFrames + "]"); |
| 201 } | 202 } |
| 202 source.start(startTime, offset, test.durationFrames / context.sample Rate); | 203 source.start(startTime, offset, test.durationFrames / context.sample Rate); |
| 203 } | 204 } |
| 204 } else if (test.renderFrames) { | 205 } else if (test.renderFrames) { |
| 205 var duration = test.renderFrames / context.sampleRate; | 206 let duration = test.renderFrames / context.sampleRate; |
| 206 if (test.renderFrames > testSpacingFrames || test.renderFrames < 0) { | 207 if (test.renderFrames > testSpacingFrames || test.renderFrames < 0) { |
| 207 testFailed("Test " + testNumber | 208 throw("Test " + testNumber |
| 208 + ": renderFrames (" + test.renderFrames + ") outside the range [0, " | 209 + ": renderFrames (" + test.renderFrames + ") outside the range [0, " |
| 209 + testSpacingFrames + "]"); | 210 + testSpacingFrames + "]"); |
| 210 } | 211 } |
| 211 source.start(startTime, offset); | 212 source.start(startTime, offset); |
| 212 source.stop(startTime + duration); | 213 source.stop(startTime + duration); |
| 213 } else { | 214 } else { |
| 214 testFailed("Test " + testNumber + " must specify renderFrames and possib ly durationFrames"); | 215 throw("Test " + testNumber + " must specify renderFrames and possibly du rationFrames"); |
| 215 } | 216 } |
| 216 } | 217 } |
| 217 | 218 |
| 218 function runTest() { | 219 audit.define("AudioBufferSource looping test", function (task, should) { |
| 219 window.jsTestIsAsync = true; | |
| 220 | |
| 221 // Create offline audio context. | 220 // Create offline audio context. |
| 222 var context = new OfflineAudioContext(1, totalRenderLengthFrames, sampleRate ); | 221 let context = new OfflineAudioContext(1, totalRenderLengthFrames, sampleRate ); |
| 223 buffer = createTestBuffer(context, bufferFrameLength); | 222 buffer = createTestBuffer(context, bufferFrameLength); |
| 224 | 223 |
| 225 for (var i = 0; i < tests.length; ++i) | 224 should(function () { |
| 226 runLoopTest(context, i, tests[i]); | 225 for (let i = 0; i < tests.length; ++i) |
| 226 runLoopTest(context, i, tests[i], should); | |
| 227 }, "Generate " + tests.length + " test cases").notThrow(); | |
| 227 | 228 |
| 228 context.oncomplete = checkAllTests; | 229 context.startRendering() |
| 229 context.startRendering(); | 230 .then(function (audioBuffer) { |
| 230 } | 231 checkAllTests(audioBuffer, should); |
| 232 }) | |
| 233 .then(task.done.bind(task));; | |
| 234 }); | |
| 231 | 235 |
| 232 runTest(); | 236 audit.run(); |
| 233 successfullyParsed = true; | |
| 234 | |
| 235 </script> | 237 </script> |
| 236 | 238 |
| 237 </body> | 239 </body> |
| 238 </html> | 240 </html> |
| OLD | NEW |