Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
| 5 <script src="resources/compatibility.js"></script> | 5 <script src="resources/compatibility.js"></script> |
| 6 <script type="text/javascript" src="resources/audio-testing.js"></script> | 6 <script type="text/javascript" src="resources/audio-testing.js"></script> |
| 7 </head> | 7 </head> |
| 8 | 8 |
| 9 <body> | 9 <body> |
| 10 | 10 |
| 11 <div id="description"></div> | 11 <div id="description"></div> |
| 12 <div id="console"></div> | 12 <div id="console"></div> |
| 13 | 13 |
| 14 <script> | 14 <script> |
| 15 description("Tests ScriptProcessorNode."); | 15 description("Tests ScriptProcessorNode."); |
| 16 | 16 |
| 17 var sampleRate = 44100.0; | 17 var sampleRate = 44100.0; |
| 18 var outputChannels = 6; | 18 var outputChannels = 6; |
| 19 var playbackTime = 0.0; | |
| 19 | 20 |
| 20 // For the current implementation of ScriptProcessorNode, when it works with Off lineAudioContext (which runs much faster | 21 // For the current implementation of ScriptProcessorNode, when it works with Off lineAudioContext (which runs much faster |
| 21 // than real-time) the event.inputBuffer might be overwrite again before onaudio process ever get chance to be called. | 22 // than real-time) the event.inputBuffer might be overwrite again before onaudio process ever get chance to be called. |
| 22 // We carefully arrange the renderLengthInFrames and bufferSize to have exactly the same value to avoid this issue. | 23 // We carefully arrange the renderLengthInFrames and bufferSize to have exactly the same value to avoid this issue. |
| 23 var renderLengthInFrames = 512; | 24 var renderLengthInFrames = 512; |
| 24 var bufferSize = 512; | 25 var bufferSize = 512; |
| 25 | 26 |
| 26 var context; | 27 var context; |
| 27 | 28 |
| 28 function createBuffer(context, length) { | 29 function createBuffer(context, length) { |
| 29 var audioBuffer = context.createBuffer(2, length, sampleRate); | 30 var audioBuffer = context.createBuffer(2, length, sampleRate); |
| 30 var n = audioBuffer.length; | 31 var n = audioBuffer.length; |
| 31 var dataL = audioBuffer.getChannelData(0); | 32 var dataL = audioBuffer.getChannelData(0); |
| 32 var dataR = audioBuffer.getChannelData(1); | 33 var dataR = audioBuffer.getChannelData(1); |
| 33 | 34 |
| 34 for (var i = 0; i < n; ++i) { | 35 for (var i = 0; i < n; ++i) { |
| 35 dataL[i] = -1; | 36 dataL[i] = -1; |
| 36 dataR[i] = 1; | 37 dataR[i] = 1; |
| 37 } | 38 } |
| 38 | 39 |
| 39 return audioBuffer; | 40 return audioBuffer; |
| 40 } | 41 } |
| 41 | 42 |
| 42 function processAudioData(event) { | 43 function processAudioData(event) { |
| 44 playbackTime = event.playbackTime; | |
| 45 var expectedTime = context.currentTime + (bufferSize / context.sampleRate); | |
| 46 var allowedTimeGap = 0.0000001; | |
| 47 | |
| 48 // There may be a little time gap which is from different thread operation | |
| 49 // between currentTime when main thread fires onaudioprocess() and currenTim e when read in JS | |
| 50 // since currentTime is continuously increasing on audio thread. | |
| 51 shouldBeCloseTo("playbackTime", expectedTime, allowedTimeGap, true); | |
|
mickelsen.eric
2014/10/07 02:05:41
I'm not sure how to track this down, but I have a
| |
| 52 | |
| 43 buffer = event.outputBuffer; | 53 buffer = event.outputBuffer; |
| 44 if (buffer.numberOfChannels != outputChannels) | 54 if (buffer.numberOfChannels != outputChannels) |
| 45 testFailed("numberOfOutputChannels doesn't match!"); | 55 testFailed("numberOfOutputChannels doesn't match!"); |
| 46 | 56 |
| 47 if (buffer.length != bufferSize) | 57 if (buffer.length != bufferSize) |
| 48 testFailed("numberOfOutputChannels doesn't match!"); | 58 testFailed("numberOfOutputChannels doesn't match!"); |
| 49 | 59 |
| 50 buffer = event.inputBuffer; | 60 buffer = event.inputBuffer; |
| 51 var bufferDataL = buffer.getChannelData(0); | 61 var bufferDataL = buffer.getChannelData(0); |
| 52 var bufferDataR = buffer.getChannelData(1); | 62 var bufferDataR = buffer.getChannelData(1); |
| 53 | 63 |
| 54 var success = true; | 64 var success = true; |
| 55 // Go through every sample and make sure it's all -1 for the left-channel, a nd all +1 for the right-channel. | 65 // Go through every sample and make sure it's all -1 for the left-channel, a nd all +1 for the right-channel. |
| 56 for (var i = 0; i < buffer.length; ++i) { | 66 for (var i = 0; i < buffer.length; ++i) { |
| 57 if (bufferDataL[i] != -1 || bufferDataR[i] != 1) { | 67 if (bufferDataL[i] != -1 || bufferDataR[i] != 1) { |
| 58 success = false; | 68 success = false; |
| 59 break; | 69 break; |
| 60 } | 70 } |
| 61 } | 71 } |
| 62 | 72 |
| 63 if (success) { | 73 if (success) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 context.oncomplete = finishJSTest; | 162 context.oncomplete = finishJSTest; |
| 153 context.startRendering(); | 163 context.startRendering(); |
| 154 } | 164 } |
| 155 | 165 |
| 156 runTest(); | 166 runTest(); |
| 157 | 167 |
| 158 </script> | 168 </script> |
| 159 | 169 |
| 160 </body> | 170 </body> |
| 161 </html> | 171 </html> |
| OLD | NEW |