audioworkletprocessor-process-frozen-array.https.html (2073B)
1 <!doctype html> 2 <html> 3 <head> 4 <title> 5 Test given arrays within AudioWorkletProcessor.process() method 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 </head> 11 12 <body> 13 <script> 14 const audit = Audit.createTaskRunner(); 15 const filePath = 'processors/array-check-processor.js'; 16 const context = new AudioContext(); 17 18 // Test if the incoming arrays are frozen as expected. 19 audit.define('check-frozen-array', (task, should) => { 20 context.audioWorklet.addModule(filePath).then(() => { 21 const workletNode = 22 new AudioWorkletNode(context, 'array-frozen-processor'); 23 workletNode.port.onmessage = (message) => { 24 const actual = message.data; 25 should(actual.isInputFrozen, '|inputs| is frozen').beTrue(); 26 should(actual.isOutputFrozen, '|outputs| is frozen').beTrue(); 27 task.done(); 28 }; 29 }); 30 }); 31 32 // The incoming arrays should not be transferred, but the associated 33 // ArrayBuffers can be transferred. See the `array-transfer-processor` 34 // definition for the details. 35 audit.define('transfer-frozen-array', (task, should) => { 36 const sourceNode = new ConstantSourceNode(context); 37 const workletNode = 38 new AudioWorkletNode(context, 'array-transfer-processor'); 39 workletNode.port.onmessage = (message) => { 40 const actual = message.data; 41 if (actual.type === 'assertion') 42 should(actual.success, actual.message).beTrue(); 43 if (actual.done) 44 task.done(); 45 }; 46 // To have valid ArrayBuffers for both input and output, we need 47 // both connections. 48 // See: https://github.com/WebAudio/web-audio-api/issues/2566 49 sourceNode.connect(workletNode).connect(context.destination); 50 sourceNode.start(); 51 }); 52 53 audit.run(); 54 </script> 55 </body> 56 </html>