audiochannelmerger-input.html (3954B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>audiochannelmerger-input.html</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/webaudio/resources/audit-util.js"></script> 8 <script src="/webaudio/resources/merger-testing.js"></script> 9 </head> 10 <body> 11 <script> 12 promise_test((t) => { 13 // Task: Check if an inactive input renders a silent mono channel in the 14 // output. 15 return testMergerInput_W3CTH({ 16 numberOfChannels: 6, 17 18 // Create a mono source buffer filled with '1'. 19 testBufferContent: [1], 20 21 // Connect the output of source into the 4th input of merger. 22 mergerInputIndex: 3, 23 24 // All channels should contain 0, except channel 4 which should be 1. 25 expected: [0, 0, 0, 1, 0, 0], 26 }); 27 }, 'Silent inactive inputs produce 0 in unused merger channels'); 28 29 promise_test((t) => { 30 // Task: Check if a stereo input is being down-mixed to mono channel 31 // correctly based on the mixing rule. 32 return testMergerInput_W3CTH({ 33 numberOfChannels: 6, 34 35 // Create a stereo buffer filled with '1' and '2' for left and right 36 // channels respectively. 37 testBufferContent: [1, 2], 38 39 // Connect the output of source into the 1st input of merger. 40 mergerInputIndex: undefined, 41 42 // The result of summed and down-mixed stereo audio should be 1.5. 43 // (= 1 * 0.5 + 2 * 0.5) 44 expected: [1.5, 0, 0, 0, 0, 0], 45 }); 46 }, 'Stereo input should down-mix properly to mono merger input'); 47 48 promise_test((t) => { 49 // Task: Check if 3-channel input gets processed by the 'discrete' 50 // mixing rule. 51 return testMergerInput_W3CTH({ 52 numberOfChannels: 6, 53 54 // Create a 3-channel buffer filled with '1', '2', and '3' 55 // respectively. 56 testBufferContent: [1, 2, 3], 57 58 // Connect the output of source into the 1st input of merger. 59 mergerInputIndex: undefined, 60 61 // The result of summed stereo audio should be 1 because 3-channel is 62 // not a canonical layout, so the input channel 2 and 3 should be 63 // dropped by 'discrete' mixing rule. 64 expected: [1, 0, 0, 0, 0, 0], 65 }); 66 }, '3-channel input uses discrete rule, dropping 2nd and 3rd channels'); 67 68 promise_test((t) => { 69 // Task: Merging two inputs into a single stereo stream. 70 71 // For this test, the number of channel should be 2. 72 const context = new OfflineAudioContext(2, 128, 44100); 73 const merger = context.createChannelMerger(); 74 const source1 = context.createBufferSource(); 75 const source2 = context.createBufferSource(); 76 77 // Create a DC offset buffer (mono) filled with 1 and assign it to BS 78 // nodes. 79 const positiveDCOffset = createConstantBuffer(context, 128, 1); 80 const negativeDCOffset = createConstantBuffer(context, 128, -1); 81 source1.buffer = positiveDCOffset; 82 source2.buffer = negativeDCOffset; 83 84 // Connect: BS#1 => merger_input#0, BS#2 => Inverter => merger_input#1 85 source1.connect(merger, 0, 0); 86 source2.connect(merger, 0, 1); 87 merger.connect(context.destination); 88 source1.start(); 89 source2.start(); 90 91 return context.startRendering().then((buffer) => { 92 assert_array_equals( 93 buffer.getChannelData(0), 94 new Float32Array(128).fill(1), 95 'Channel #0 should be constant value of 1'); 96 assert_array_equals( 97 buffer.getChannelData(1), 98 new Float32Array(128).fill(-1), 99 'Channel #1 should be constant value of -1'); 100 }); 101 }, 'Merging two mono sources into stereo using ChannelMerger'); 102 </script> 103 </body> 104 </html>