process-parameters.https.html (3332B)
1 <!doctype html> 2 <title>Test parameters of process() AudioWorkletProcessor callback</title> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <script> 6 var context; 7 promise_setup(async (t) => { 8 context = new AudioContext(); 9 const filePath = 'processors/process-parameter-test-processor.js'; 10 await context.audioWorklet.addModule(filePath); 11 }); 12 13 const get_parameters = async (node, options) => { 14 const event = await new Promise((resolve) => { 15 node.port.onmessage = resolve; 16 }); 17 const inputs = event.data.inputs; 18 assert_equals(inputs.length, options.numberOfInputs, 'inputs length'); 19 const outputs = event.data.outputs; 20 assert_equals(outputs.length, options.numberOfOutputs, 'outputs length'); 21 for (let port = 0; port < inputs.length; ++port) { 22 for (let channel = 0; channel < inputs[port].length; ++channel) { 23 assert_equals(inputs[port][channel].length, 128, 24 `inputs[${port}][${channel}].length`); 25 } 26 } 27 for (let port = 0; port < outputs.length; ++port) { 28 for (let channel = 0; channel < outputs[port].length; ++channel) { 29 assert_equals(outputs[port][channel].length, 128, 30 `outputs[${port}][${channel}].length`); 31 } 32 } 33 return event.data; 34 }; 35 36 promise_test(async (t) => { 37 const options = { 38 numberOfInputs: 3, 39 numberOfOutputs: 0 40 }; 41 // Connect a source so that one channel of one input is active. 42 context.suspend(); 43 const source = new ConstantSourceNode(context); 44 source.start(); 45 const merger = new ChannelMergerNode(context, {numberOfInputs: 2}); 46 const active_channel_index = merger.numberOfInputs - 1; 47 source.connect(merger, 0, active_channel_index); 48 const node = new AudioWorkletNode(context, 'process-parameter-test', options); 49 const active_port_index = options.numberOfInputs - 1; 50 merger.connect(node, 0, active_port_index); 51 context.resume(); 52 const {inputs} = await get_parameters(node, options); 53 for (let port = 0; port < inputs.length - 1; ++port) { 54 if (port != active_port_index) { 55 assert_equals(inputs[port].length, 0, `inputs[${port}].length`); 56 } 57 } 58 const active_input = inputs[active_port_index]; 59 assert_equals(active_input.length, merger.numberOfInputs, 60 'active_input.length'); 61 for (let channel = 0; channel < active_input.length; ++channel) { 62 let expected = channel == active_channel_index ? 1.0 : 0.0; 63 for (let sample = 0; sample < inputs.length; ++sample) { 64 assert_equals(active_input[channel][sample], expected, 65 `active_input[${channel}][${sample}]`); 66 } 67 } 68 }, '3 inputs; 0 outputs'); 69 70 promise_test(async (t) => { 71 const options = { 72 numberOfInputs: 0, 73 numberOfOutputs: 3 74 }; 75 const node = new AudioWorkletNode(context, 'process-parameter-test', options); 76 const {outputs} = await get_parameters(node, options); 77 for (let port = 0; port < outputs.length; ++port) { 78 assert_equals(outputs[port].length, 1, `outputs[${port}].length`); 79 for (let channel = 0; channel < outputs[port].length; ++channel) { 80 for (let sample = 0; sample < outputs.length; ++sample) { 81 assert_equals(outputs[port][channel][sample], 0.0, 82 `outputs[${port}][${channel}][${sample}]`); 83 } 84 } 85 } 86 }, '0 inputs; 3 outputs'); 87 </script>