audioworkletnode-automatic-pull.https.html (2685B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 Test AudioWorkletNode's automatic pull feature 6 </title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/webaudio/resources/audit.js"></script> 10 <script src="/webaudio/resources/audit-util.js"></script> 11 </head> 12 <body> 13 <script id="layout-test-code"> 14 const audit = Audit.createTaskRunner(); 15 16 // Arbitrary sample rate. Anything should work. 17 const sampleRate = 48000; 18 const renderLength = RENDER_QUANTUM_FRAMES * 2; 19 const channelCount = 1; 20 const filePath = 'processors/zero-output-processor.js'; 21 22 const sourceOffset = 0.5; 23 24 // Connect a constant source node to the zero-output AudioWorkletNode. 25 // Then verify if it captures the data correctly. 26 audit.define('setup-worklet', (task, should) => { 27 const context = 28 new OfflineAudioContext(channelCount, renderLength, sampleRate); 29 30 context.audioWorklet.addModule(filePath).then(() => { 31 let testSource = 32 new ConstantSourceNode(context, { offset: sourceOffset }); 33 let zeroOutputWorkletNode = 34 new AudioWorkletNode(context, 'zero-output-processor', { 35 numberOfInputs: 1, 36 numberOfOutputs: 0, 37 processorOptions: { 38 bufferLength: renderLength, 39 channeCount: channelCount 40 } 41 }); 42 43 // Start the source and stop at the first render quantum. 44 testSource.connect(zeroOutputWorkletNode); 45 testSource.start(); 46 testSource.stop(RENDER_QUANTUM_FRAMES/sampleRate); 47 48 zeroOutputWorkletNode.port.onmessage = (event) => { 49 // The |capturedBuffer| can be multichannel. Iterate through it. 50 for (let i = 0; i < event.data.capturedBuffer.length; ++i) { 51 let buffer = event.data.capturedBuffer[i]; 52 // Split the captured buffer in half for the easier test. 53 should(buffer.subarray(0, RENDER_QUANTUM_FRAMES), 54 'The first half of the captured buffer') 55 .beConstantValueOf(sourceOffset); 56 should(buffer.subarray(RENDER_QUANTUM_FRAMES, renderLength), 57 'The second half of the captured buffer') 58 .beConstantValueOf(0); 59 } 60 task.done(); 61 }; 62 63 // Starts the rendering, but we don't need the rendered buffer from 64 // the context. 65 context.startRendering(); 66 }); 67 }); 68 69 audit.run(); 70 </script> 71 </body> 72 </html>