OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 | 3 |
4 <head> | 4 <head> |
5 <script src="../resources/js-test.js"></script> | 5 <script src="../resources/js-test.js"></script> |
6 <script src="resources/compatibility.js"></script> | 6 <script src="resources/compatibility.js"></script> |
7 <script src="resources/audio-testing.js"></script> | 7 <script src="resources/audio-testing.js"></script> |
8 </head> | 8 </head> |
9 | 9 |
10 <body> | 10 <body> |
11 <script> | 11 <script> |
12 description('Test ChannelMergerNode behavior on dynamic input change.'); | 12 description('Test ChannelMergerNode behavior on dynamic input change.'); |
13 window.jsTestIsAsync = true; | 13 window.jsTestIsAsync = true; |
14 | 14 |
15 var numberOfChannels = 2; | |
15 var sampleRate = 44100; | 16 var sampleRate = 44100; |
16 var numberOfChannels = 2; | 17 var renderLength = 2 * sampleRate; |
17 | |
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; | |
21 | 18 |
22 var audit = Audit.createTaskRunner(); | 19 var audit = Audit.createTaskRunner(); |
23 | 20 |
24 // Task: Check if the merger outputs a silent channel when an input is | 21 // Task: Check if the merger outputs a silent channel when an input is |
25 // disconnected. | 22 // disconnected. |
26 audit.defineTask('silent-disconnect', function (done) { | 23 audit.defineTask('silent-disconnect', function (done) { |
27 var context = new OfflineAudioContext( | 24 var context = new OfflineAudioContext(numberOfChannels, renderLength, samp leRate); |
28 numberOfChannels, renderLength, sampleRate | |
29 ); | |
30 var merger = context.createChannelMerger(); | 25 var merger = context.createChannelMerger(); |
31 var source1 = context.createBufferSource(); | 26 var source1 = context.createBufferSource(); |
32 var source2 = context.createBufferSource(); | 27 var source2 = context.createBufferSource(); |
33 | 28 |
34 // Create and assign a mono testing buffer. | 29 // Create and assign a constant buffer. |
35 var bufferDCOffset = createTestingAudioBuffer(context, 1, renderLength); | 30 var bufferDCOffset = createConstantBuffer(context, 1, 1); |
36 source1.buffer = bufferDCOffset; | 31 source1.buffer = source2.buffer = bufferDCOffset; |
37 source2.buffer = bufferDCOffset; | 32 source1.loop = source2.loop = true; |
38 | 33 |
39 // Connect the output of source into the 4th input of merger. The merger | 34 // Connect the output of source into the 4th input of merger. The merger |
40 // should produce 6 channel output. | 35 // should produce 6 channel output. |
41 source1.connect(merger, 0, 0); | 36 source1.connect(merger, 0, 0); |
42 source2.connect(merger, 0, 1); | 37 source2.connect(merger, 0, 1); |
43 merger.connect(context.destination); | 38 merger.connect(context.destination); |
44 source1.start(); | 39 source1.start(); |
45 source2.start(); | 40 source2.start(); |
46 | 41 |
47 // When the rendering begins, disconnect |source2| as soon as possible. | 42 // Schedule the disconnection of |source2| at 1 second. |
Raymond Toy
2015/12/01 22:14:37
We could make this test much faster if we didn't r
hongchan
2015/12/02 18:58:31
I thought you'd ask! I will reduce the render leng
Raymond Toy
2015/12/02 19:37:50
Seems to me that you did 1/2 sec for the tests. T
| |
48 context.onstatechange = function () { | 43 context.suspend(1.0).then(function () { |
49 if (context.state === 'running') | 44 source2.disconnect(); |
50 source2.disconnect(); | 45 context.resume(); |
51 }; | 46 }); |
52 | 47 |
53 context.startRendering().then(function (buffer) { | 48 context.startRendering().then(function (buffer) { |
54 | |
55 // The entire first channel of the output should be 1. | 49 // The entire first channel of the output should be 1. |
56 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(1); | 50 Should('Channel #0', buffer.getChannelData(0)).beConstantValueOf(1); |
57 | 51 |
58 // The second channel should contain 1, and 0 after the disconnection. | 52 // The second channel should contain 1, and 0 after the disconnection. |
Raymond Toy
2015/12/01 22:14:37
Now that we know exactly when the disconnect happe
hongchan
2015/12/02 18:58:31
Done.
| |
59 Should('Channel #1', buffer.getChannelData(1)).containValues([1, 0]); | 53 Should('Channel #1', buffer.getChannelData(1)).containValues([1, 0]); |
60 | 54 }).then(done); |
61 done(); | |
62 }); | |
63 }); | 55 }); |
64 | 56 |
65 audit.defineTask('finish', function (done) { | 57 audit.defineTask('finish', function (done) { |
66 finishJSTest(); | 58 finishJSTest(); |
67 done(); | 59 done(); |
68 }); | 60 }); |
69 | 61 |
70 audit.runTasks( | 62 audit.runTasks(); |
71 'silent-disconnect', | |
72 'finish' | |
73 ); | |
74 | 63 |
75 successfullyParsed = true; | 64 successfullyParsed = true; |
76 </script> | 65 </script> |
77 </body> | 66 </body> |
78 | 67 |
79 </html> | 68 </html> |
OLD | NEW |