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