active-processing.https.html (3171B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 Test Active Processing for ChannelMergerNode 6 </title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 </head> 10 11 <body> 12 <script> 13 // AudioProcessor that sends a message to its AudioWorkletNode whenver the 14 // number of channels on its input changes. 15 const filePath = 16 '../the-audioworklet-interface/processors/active-processing.js'; 17 18 let context; 19 20 // Keep one promise_test to load module 21 // and set up context (so ordering is explicit). 22 promise_test(() => { 23 // Create context and load the module 24 context = new AudioContext(); 25 return context.audioWorklet.addModule(filePath); 26 }, 'initialize: AudioWorklet module loading'); 27 28 promise_test(() => { 29 return new Promise(resolve => { 30 const src = new OscillatorNode(context); 31 32 // Number of inputs for the ChannelMergerNode. Pretty arbitrary, but 33 // should not be 1. 34 const numberOfInputs = 7; 35 const merger = 36 new ChannelMergerNode(context, {numberOfInputs: numberOfInputs}); 37 38 const testerNode = 39 new AudioWorkletNode(context, 'active-processing-tester', { 40 // Use as short a duration as possible to keep the test from 41 // taking too much time. 42 processorOptions: {testDuration: .5}, 43 }); 44 45 // Expected number of output channels from the merger node. We should 46 // start with the number of inputs, because the source (oscillator) is 47 // actively processing. When the source stops, the number of channels 48 // should change to 0. 49 const expectedValues = [numberOfInputs, 0]; 50 let index = 0; 51 52 testerNode.port.onmessage = event => { 53 const count = event.data.channelCount; 54 const finished = event.data.finished; 55 56 // If we're finished, end testing. 57 if (finished) { 58 // Verify that we got the expected number of changes. 59 assert_equals( 60 index, expectedValues.length, 'Number of distinct values'); 61 resolve(); 62 return; 63 } 64 65 if (index < expectedValues.length) { 66 // Verify that the number of channels matches the expected number 67 // of channels. 68 assert_equals( 69 count, expectedValues[index], 70 `Test ${index}: Number of convolver output channels`); 71 } 72 73 ++index; 74 }; 75 76 // Create the graph and go 77 src.connect(merger).connect(testerNode).connect(context.destination); 78 src.start(); 79 80 // Stop the source after a short time so we can test that the channel 81 // merger changes to not actively processing and thus produces a 82 // single channel of silence. 83 src.stop(context.currentTime + .1); 84 }); 85 }, 'test: Active processing emits expected channel-count changes'); 86 </script> 87 </body> 88 </html>