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 type="text/javascript" src="resources/audio-testing.js"></script> | 5 <script type="text/javascript" src="resources/audio-testing.js"></script> |
6 </head> | 6 </head> |
7 | 7 |
8 <body> | 8 <body> |
9 | 9 |
10 <div id="description"></div> | 10 <div id="description"></div> |
11 <div id="console"></div> | 11 <div id="console"></div> |
12 | 12 |
13 <script> | 13 <script> |
14 description("Tests ScriptProcessorNode."); | 14 description("Tests ScriptProcessorNode."); |
15 | 15 |
16 var sampleRate = 44100.0; | 16 var sampleRate = 44100.0; |
17 var outputChannels = 6; | 17 var outputChannels = 6; |
18 var playbackTime = 0.0; | |
18 | 19 |
19 // For the current implementation of ScriptProcessorNode, when it works with Off lineAudioContext (which runs much faster | 20 // For the current implementation of ScriptProcessorNode, when it works with Off lineAudioContext (which runs much faster |
20 // than real-time) the event.inputBuffer might be overwrite again before onaudio process ever get chance to be called. | 21 // than real-time) the event.inputBuffer might be overwrite again before onaudio process ever get chance to be called. |
21 // We carefully arrange the renderLengthInFrames and bufferSize to have exactly the same value to avoid this issue. | 22 // We carefully arrange the renderLengthInFrames and bufferSize to have exactly the same value to avoid this issue. |
22 var renderLengthInFrames = 512; | 23 var renderLengthInFrames = 512; |
23 var bufferSize = 512; | 24 var bufferSize = 512; |
24 | 25 |
25 var context; | 26 var context; |
26 | 27 |
27 function createBuffer(context, length) { | 28 function createBuffer(context, length) { |
28 var audioBuffer = context.createBuffer(2, length, sampleRate); | 29 var audioBuffer = context.createBuffer(2, length, sampleRate); |
29 var n = audioBuffer.length; | 30 var n = audioBuffer.length; |
30 var dataL = audioBuffer.getChannelData(0); | 31 var dataL = audioBuffer.getChannelData(0); |
31 var dataR = audioBuffer.getChannelData(1); | 32 var dataR = audioBuffer.getChannelData(1); |
32 | 33 |
33 for (var i = 0; i < n; ++i) { | 34 for (var i = 0; i < n; ++i) { |
34 dataL[i] = -1; | 35 dataL[i] = -1; |
35 dataR[i] = 1; | 36 dataR[i] = 1; |
36 } | 37 } |
37 | 38 |
38 return audioBuffer; | 39 return audioBuffer; |
39 } | 40 } |
40 | 41 |
41 function processAudioData(event) { | 42 function processAudioData(event) { |
43 playbackTime = event.playbackTime; | |
44 var expectedTime = context.currentTime + (bufferSize / context.sampleRate); | |
45 var precision = 0.0000001; | |
46 shouldBeCloseTo("playbackTime", expectedTime, precision, true); | |
Raymond Toy
2014/03/27 18:52:20
Is there a reason playbackTime this is not EXACTLY
KhNo
2014/03/28 04:41:37
The reason that is not exactly same with expectedT
| |
47 | |
42 buffer = event.outputBuffer; | 48 buffer = event.outputBuffer; |
43 if (buffer.numberOfChannels != outputChannels) | 49 if (buffer.numberOfChannels != outputChannels) |
44 testFailed("numberOfOutputChannels doesn't match!"); | 50 testFailed("numberOfOutputChannels doesn't match!"); |
45 | 51 |
46 if (buffer.length != bufferSize) | 52 if (buffer.length != bufferSize) |
47 testFailed("numberOfOutputChannels doesn't match!"); | 53 testFailed("numberOfOutputChannels doesn't match!"); |
48 | 54 |
49 buffer = event.inputBuffer; | 55 buffer = event.inputBuffer; |
50 var bufferDataL = buffer.getChannelData(0); | 56 var bufferDataL = buffer.getChannelData(0); |
51 var bufferDataR = buffer.getChannelData(1); | 57 var bufferDataR = buffer.getChannelData(1); |
52 | 58 |
53 var success = true; | 59 var success = true; |
54 // Go through every sample and make sure it's all -1 for the left-channel, a nd all +1 for the right-channel. | 60 // Go through every sample and make sure it's all -1 for the left-channel, a nd all +1 for the right-channel. |
55 for (var i = 0; i < buffer.length; ++i) { | 61 for (var i = 0; i < buffer.length; ++i) { |
56 if (bufferDataL[i] != -1 || bufferDataR[i] != 1) { | 62 if (bufferDataL[i] != -1 || bufferDataR[i] != 1) { |
57 success = false; | 63 success = false; |
58 break; | 64 break; |
59 } | 65 } |
60 } | 66 } |
61 | 67 |
62 if (success) { | 68 if (success) { |
(...skipping 88 matching lines...) Loading... | |
151 context.oncomplete = finishJSTest; | 157 context.oncomplete = finishJSTest; |
152 context.startRendering(); | 158 context.startRendering(); |
153 } | 159 } |
154 | 160 |
155 runTest(); | 161 runTest(); |
156 | 162 |
157 </script> | 163 </script> |
158 | 164 |
159 </body> | 165 </body> |
160 </html> | 166 </html> |
OLD | NEW |