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 | 12 |
13 <div id="description"></div> | 13 <div id="description"></div> |
14 <div id="console"></div> | 14 <div id="console"></div> |
hongchan
2015/02/20 22:49:46
These two <div>s should be removed.
| |
15 | 15 |
16 <script> | 16 <script> |
17 description("Tests AudioBufferSourceNode looping with a variety of loop points." ); | 17 description("Tests AudioBufferSourceNode looping with a variety of loop points." ); |
18 | 18 |
19 // The following test cases assume an AudioBuffer of length 8 whose PCM data is a linear ramp, 0, 1, 2, 3,... | 19 // 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 | 20 // |description| is optional and will be computed from the other parameters. |of fsetFrame| is |
21 // optional and defaults to 0. | 21 // optional and defaults to 0. |
22 | 22 |
23 var tests = [ | 23 var tests = [ |
24 | 24 |
(...skipping 104 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] }, | 129 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
130 | 130 |
131 { description: "illegal loop: loopEndFrame > bufferLength", | 131 { description: "illegal loop: loopEndFrame > bufferLength", |
132 loopStartFrame: 0, | 132 loopStartFrame: 0, |
133 loopEndFrame: 30000, | 133 loopEndFrame: 30000, |
134 renderFrames: 16, | 134 renderFrames: 16, |
135 playbackRate: 1, | 135 playbackRate: 1, |
136 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, | 136 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
137 | 137 |
138 // Start a loop with a duration longer than the buffer. The output should be th e data from frame 1 | 138 // 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. | 139 // 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", | 140 { description: "loop from 3 -> 6 with offset 1 for 20 frames", |
141 loopStartFrame: 3, | 141 loopStartFrame: 3, |
142 loopEndFrame: 6, | 142 loopEndFrame: 6, |
143 playbackRate: 1, | 143 playbackRate: 1, |
144 offsetFrame: 1, | 144 offsetFrame: 1, |
145 durationFrames: 30, | 145 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] }, | 146 durationFrames: 20, |
147 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] }, | |
148 | |
149 // Start a loop with a duration less than the grain length. The output should b e the data from | |
hongchan
2015/02/20 22:49:45
By 'grain length', do you mean the playback durati
Raymond Toy
2015/02/20 23:06:18
No. It's the length of the looping region from loo
| |
150 // frame 1 to 3, and then stopping because duration = 3 | |
151 { description: "loop from 3 -> 8 with offset 1 for 3 frames", | |
152 loopStartFrame: 3, | |
153 loopEndFrame: 8, | |
154 playbackRate: 1, | |
155 offsetFrame: 1, | |
156 durationFrames: 3, | |
157 renderFrames: 30, | |
158 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] }, | |
159 | |
160 // Start a loop with a duration less than the grain length. The output should b e the data from | |
161 // frame 1 to 3, and then stopping because duration = 3 | |
162 { description: "loop from 3 -> 8 with offset 7 for 3 frames", | |
163 loopStartFrame: 3, | |
164 loopEndFrame: 8, | |
165 playbackRate: 1, | |
166 offsetFrame: 7, | |
167 durationFrames: 3, | |
168 renderFrames: 30, | |
169 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] }, | |
hongchan
2015/02/20 22:49:45
This is the last item in the array. The comma shou
| |
147 | 170 |
148 ]; | 171 ]; |
149 | 172 |
150 var sampleRate = 44100; | 173 var sampleRate = 44100; |
151 var buffer; | 174 var buffer; |
152 var bufferFrameLength = 8; | 175 var bufferFrameLength = 8; |
153 var testSpacingFrames = 32; | 176 var testSpacingFrames = 32; |
154 var testSpacingSeconds = testSpacingFrames / sampleRate; | 177 var testSpacingSeconds = testSpacingFrames / sampleRate; |
155 var totalRenderLengthFrames = tests.length * testSpacingFrames; | 178 var totalRenderLengthFrames = tests.length * testSpacingFrames; |
156 | 179 |
157 function runLoopTest(context, testNumber, test) { | 180 function runLoopTest(context, testNumber, test) { |
158 var source = context.createBufferSource(); | 181 var source = context.createBufferSource(); |
159 | 182 |
160 source.buffer = buffer; | 183 source.buffer = buffer; |
161 source.playbackRate.value = test.playbackRate; | 184 source.playbackRate.value = test.playbackRate; |
162 source.loop = true; | 185 source.loop = true; |
163 source.loopStart = test.loopStartFrame / context.sampleRate; | 186 source.loopStart = test.loopStartFrame / context.sampleRate; |
164 source.loopEnd = test.loopEndFrame / context.sampleRate; | 187 source.loopEnd = test.loopEndFrame / context.sampleRate; |
165 | 188 |
166 var offset = test.offsetFrame ? test.offsetFrame / context.sampleRate : 0; | 189 var offset = test.offsetFrame ? test.offsetFrame / context.sampleRate : 0; |
167 | 190 |
168 source.connect(context.destination); | 191 source.connect(context.destination); |
169 | 192 |
170 // Render each test one after the other, spaced apart by testSpacingSeconds. | 193 // Render each test one after the other, spaced apart by testSpacingSeconds. |
171 var startTime = testNumber * testSpacingSeconds; | 194 var startTime = testNumber * testSpacingSeconds; |
172 | 195 |
173 if (test.renderFrames) { | 196 // If durationFrames is given, run the test for the specified duration. |
197 if (test.durationFrames) { | |
198 if (!test.renderFrames) { | |
199 testFailed("renderFrames is required for test " + testNumber + ": " + test.description); | |
200 } else { | |
201 if (test.durationFrames > testSpacingFrames || test.durationFrames < 0) { | |
202 testFailed("Test " + testNumber | |
203 + ": durationFrames (" + test.durationFrames + ") outside th e range [0, " | |
204 + testSpacingFrames + "]"); | |
205 } | |
206 source.start(startTime, offset, test.durationFrames / context.sample Rate); | |
207 } | |
208 } else if (test.renderFrames) { | |
174 var duration = test.renderFrames / context.sampleRate; | 209 var duration = test.renderFrames / context.sampleRate; |
175 if (test.renderFrames > testSpacingFrames || test.renderFrames < 0) { | 210 if (test.renderFrames > testSpacingFrames || test.renderFrames < 0) { |
176 testFailed("Test " + testNumber | 211 testFailed("Test " + testNumber |
177 + ": renderFrames (" + test.renderFrames + ") outside the range [0, " | 212 + ": renderFrames (" + test.renderFrames + ") outside the range [0, " |
178 + testSpacingFrames + "]"); | 213 + testSpacingFrames + "]"); |
179 } | 214 } |
180 source.start(startTime, offset); | 215 source.start(startTime, offset); |
181 source.stop(startTime + duration); | 216 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 { | 217 } else { |
190 testFailed("Test " + testNumber + " must specify one of renderFrames or durationFrames"); | 218 testFailed("Test " + testNumber + " must specify renderFrames and possib ly durationFrames"); |
191 } | 219 } |
192 } | 220 } |
193 | 221 |
194 function runTest() { | 222 function runTest() { |
195 if (window.testRunner) { | |
196 testRunner.dumpAsText(); | |
197 testRunner.waitUntilDone(); | |
198 } | |
199 | |
200 window.jsTestIsAsync = true; | 223 window.jsTestIsAsync = true; |
201 | 224 |
202 // Create offline audio context. | 225 // Create offline audio context. |
203 var context = new OfflineAudioContext(1, totalRenderLengthFrames, sampleRate ); | 226 var context = new OfflineAudioContext(1, totalRenderLengthFrames, sampleRate ); |
204 buffer = createTestBuffer(context, bufferFrameLength); | 227 buffer = createTestBuffer(context, bufferFrameLength); |
205 | 228 |
206 for (var i = 0; i < tests.length; ++i) | 229 for (var i = 0; i < tests.length; ++i) |
207 runLoopTest(context, i, tests[i]); | 230 runLoopTest(context, i, tests[i]); |
208 | 231 |
209 context.oncomplete = checkAllTests; | 232 context.oncomplete = checkAllTests; |
210 context.startRendering(); | 233 context.startRendering(); |
hongchan
2015/02/20 22:49:45
Can we use |.then()| rather than |oncomplete|?
Raymond Toy
2015/02/20 23:06:18
That would require changing checkAllTests and all
| |
211 } | 234 } |
212 | 235 |
213 runTest(); | 236 runTest(); |
214 successfullyParsed = true; | 237 successfullyParsed = true; |
215 | 238 |
216 </script> | 239 </script> |
217 | 240 |
218 </body> | 241 </body> |
219 </html> | 242 </html> |
OLD | NEW |