audioworkletnode-output-channel-count.https.html (2088B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 Test the construction of AudioWorkletNode with real-time context 6 </title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 </head> 10 <body> 11 <script> 12 const processorUrl = 'processors/channel-count-processor.js'; 13 14 const waitForMessageFromPort = (port) => { 15 return new Promise(resolve => { 16 port.onmessage = e => resolve(e.data); 17 }); 18 }; 19 20 promise_test(async t => { 21 const context = new AudioContext(); 22 23 await context.audioWorklet.addModule(processorUrl); 24 25 { 26 const buffer = new AudioBuffer({ 27 numberOfChannels: 17, 28 length: 1, 29 sampleRate: context.sampleRate, 30 }); 31 32 const source = new AudioBufferSourceNode(context, { buffer }); 33 34 const node = new AudioWorkletNode(context, 'channel-count', { 35 numberOfInputs: 1, 36 numberOfOutputs: 1, 37 }); 38 39 const promiseMessage = waitForMessageFromPort(node.port); 40 41 source.connect(node).connect(context.destination); 42 source.start(); 43 44 const { outputChannel } = await promiseMessage; 45 assert_equals( 46 outputChannel, 47 17, 48 'Output channel count should follow upstream (17).'); 49 50 } 51 52 { 53 const node = new AudioWorkletNode(context, 'channel-count', { 54 numberOfInputs: 1, 55 numberOfOutputs: 1, 56 outputChannelCount: [2], 57 }); 58 59 const promiseMessage = waitForMessageFromPort(node.port); 60 61 node.connect(context.destination); 62 63 const { outputChannel } = await promiseMessage; 64 assert_equals( 65 outputChannel, 66 2, 67 'Explicit outputChannelCount [2] must be honored.'); 68 } 69 }, `AudioWorkletNode channel count: dynamic propagation and `+ 70 `honoring outputChannelCount (single serialized test).`); 71 </script> 72 </body> 73 </html>