5 <script src=
"../resources/js-test.js"></script>
6 <script src=
"resources/compatibility.js"></script>
7 <script src=
"resources/audio-testing.js"></script>
12 description('Test ChannelMergerNode behavior on dynamic input change.');
13 window
.jsTestIsAsync
= true;
15 var sampleRate
= 44100;
16 var numberOfChannels
= 2;
18 // The test needs the long render length (20 seconds) to capture the
19 // disconnection which happens after starting the rendering.
20 var renderLength
= sampleRate
* 20;
22 var audit
= Audit
.createTaskRunner();
24 // Task: Check if the merger outputs a silent channel when an input is
26 audit
.defineTask('silent-disconnect', function (done
) {
27 var context
= new OfflineAudioContext(
28 numberOfChannels
, renderLength
, sampleRate
30 var merger
= context
.createChannelMerger();
31 var source1
= context
.createBufferSource();
32 var source2
= context
.createBufferSource();
34 // Create and assign a mono testing buffer.
35 var bufferDCOffset
= createTestingAudioBuffer(context
, 1, renderLength
);
36 source1
.buffer
= bufferDCOffset
;
37 source2
.buffer
= bufferDCOffset
;
39 // Connect the output of source into the 4th input of merger. The merger
40 // should produce 6 channel output.
41 source1
.connect(merger
, 0, 0);
42 source2
.connect(merger
, 0, 1);
43 merger
.connect(context
.destination
);
47 // When the rendering begins, disconnect |source2| as soon as possible.
48 context
.onstatechange = function () {
49 if (context
.state
=== 'running')
53 context
.startRendering().then(function (buffer
) {
55 // The entire first channel of the output should be 1.
56 Should('Channel #0', buffer
.getChannelData(0)).beConstantValueOf(1);
58 // The second channel should contain 1, and 0 after the disconnection.
59 Should('Channel #1', buffer
.getChannelData(1)).containValues([1, 0]);
65 audit
.defineTask('finish', function (done
) {
75 successfullyParsed
= true;