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