active-processing.https.html (3029B)
1 <!doctype html> 2 <html> 3 <head> 4 <title> 5 Test Active Processing for ConvolverNode 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 14 // whenever the number of channels on its input changes. 15 const filePath = 16 '../the-audioworklet-interface/processors/active-processing.js'; 17 18 let context; 19 20 promise_test(async () => { 21 // Create context and load the module 22 context = new AudioContext(); 23 await context.audioWorklet.addModule(filePath); 24 }, 'AudioWorklet module should load successfully'); 25 26 promise_test(async () => { 27 const src = new OscillatorNode(context); 28 29 const response = new AudioBuffer({ 30 numberOfChannels: 2, 31 length: 150, 32 sampleRate: context.sampleRate 33 }); 34 35 const conv = new ConvolverNode(context, {buffer: response}); 36 37 const testerNode = 38 new AudioWorkletNode(context, 'active-processing-tester', { 39 // Use as short a duration as possible to keep the test from 40 // taking too much time. 41 processorOptions: {testDuration: 0.5}, 42 }); 43 44 // Expected number of output channels from the convolver node. 45 // We should start with the number of inputs, because the 46 // source (oscillator) is actively processing. When the source 47 // stops, the number of channels should change to 0. 48 const expectedValues = [2, 0]; 49 let index = 0; 50 51 return new Promise(resolve => { 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, 61 'Number of distinct values'); 62 resolve(); 63 return; 64 } 65 66 if (index < expectedValues.length) { 67 // Verify that the number of channels matches the expected 68 // number of channels. 69 assert_equals( 70 count, expectedValues[index], 71 `Test ${index}: Number of convolver output channels`); 72 } 73 74 ++index; 75 }; 76 77 // Create the graph and go 78 src.connect(conv).connect(testerNode).connect(context.destination); 79 src.start(); 80 81 // Stop the source after a short time so we can test that the 82 // convolver changes to not actively processing and thus 83 // produces a single channel of silence. 84 src.stop(context.currentTime + 0.1); 85 }); 86 }, 'ConvolverNode should stop active processing after source stops'); 87 </script> 88 </body> 89 </html>