| OLD | NEW |
| 1 // For the current implementation of JavaScriptAudioNode, when it works with Off
lineAudioContext (which runs much faster | 1 // For the current implementation of JavaScriptAudioNode, when it works with Off
lineAudioContext (which runs much faster |
| 2 // than real-time) the event.inputBuffer might be overwrite again before onaudio
process ever get chance to be called. | 2 // than real-time) the event.inputBuffer might be overwrite again before onaudio
process ever get chance to be called. |
| 3 // We carefully arrange the renderLengthInFrames and bufferSize to have exactly
the same value to avoid this issue. | 3 // We carefully arrange the renderLengthInFrames and bufferSize to have exactly
the same value to avoid this issue. |
| 4 var renderLengthInFrames = 512; | 4 var renderLengthInFrames = 512; |
| 5 var bufferSize = 512; | 5 var bufferSize = 512; |
| 6 | 6 |
| 7 var context; | 7 var context; |
| 8 | 8 |
| 9 function createBuffer(context, numberOfChannels, length) { | 9 function createBuffer(context, numberOfChannels, length) { |
| 10 var audioBuffer = context.createBuffer(numberOfChannels, length, sampleRate)
; | 10 var audioBuffer = context.createBuffer(numberOfChannels, length, sampleRate)
; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return false; | 58 return false; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 function runJSNodeTest() | 65 function runJSNodeTest() |
| 66 { | 66 { |
| 67 // Create offline audio context. | 67 // Create offline audio context. |
| 68 context = new webkitOfflineAudioContext(2, renderLengthInFrames, sampleRate)
; | 68 context = new OfflineAudioContext(2, renderLengthInFrames, sampleRate); |
| 69 | 69 |
| 70 var sourceBuffer = createBuffer(context, sourceChannels, renderLengthInFrame
s); | 70 var sourceBuffer = createBuffer(context, sourceChannels, renderLengthInFrame
s); |
| 71 | 71 |
| 72 var bufferSource = context.createBufferSource(); | 72 var bufferSource = context.createBufferSource(); |
| 73 bufferSource.buffer = sourceBuffer; | 73 bufferSource.buffer = sourceBuffer; |
| 74 | 74 |
| 75 var scriptNode = context.createScriptProcessor(bufferSize, inputChannels, ou
tputChannels); | 75 var scriptNode = context.createScriptProcessor(bufferSize, inputChannels, ou
tputChannels); |
| 76 | 76 |
| 77 bufferSource.connect(scriptNode); | 77 bufferSource.connect(scriptNode); |
| 78 scriptNode.connect(context.destination); | 78 scriptNode.connect(context.destination); |
| 79 scriptNode.onaudioprocess = processAudioData; | 79 scriptNode.onaudioprocess = processAudioData; |
| 80 | 80 |
| 81 bufferSource.start(0); | 81 bufferSource.start(0); |
| 82 context.oncomplete = finishJSTest; | 82 context.oncomplete = finishJSTest; |
| 83 context.startRendering(); | 83 context.startRendering(); |
| 84 } | 84 } |
| OLD | NEW |