OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
| 3 <head> |
| 4 <title> |
| 5 audiochannelmerger-disconnect.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 </head> |
| 12 <body> |
| 13 <script id="layout-test-code"> |
| 14 let renderQuantum = 128; |
3 | 15 |
4 <head> | 16 let numberOfChannels = 2; |
5 <script src="../../resources/testharness.js"></script> | 17 let sampleRate = 44100; |
6 <script src="../../resources/testharnessreport.js"></script> | 18 let renderDuration = 0.5; |
7 <script src="../resources/audit-util.js"></script> | 19 let disconnectTime = 0.5 * renderDuration; |
8 <script src="../resources/audit.js"></script> | |
9 </head> | |
10 | 20 |
11 <body> | 21 let audit = Audit.createTaskRunner(); |
12 <script> | |
13 | 22 |
14 var renderQuantum = 128; | 23 // Task: Check if the merger outputs a silent channel when an input is |
| 24 // disconnected. |
| 25 audit.define('silent-disconnect', (task, should) => { |
| 26 let context = new OfflineAudioContext( |
| 27 numberOfChannels, renderDuration * sampleRate, sampleRate); |
| 28 let merger = context.createChannelMerger(); |
| 29 let source1 = context.createBufferSource(); |
| 30 let source2 = context.createBufferSource(); |
15 | 31 |
16 var numberOfChannels = 2; | 32 // Create and assign a constant buffer. |
17 var sampleRate = 44100; | 33 let bufferDCOffset = createConstantBuffer(context, 1, 1); |
18 var renderDuration = 0.5; | 34 source1.buffer = source2.buffer = bufferDCOffset; |
19 var disconnectTime = 0.5 * renderDuration; | 35 source1.loop = source2.loop = true; |
20 | 36 |
21 var audit = Audit.createTaskRunner(); | 37 // Connect the output of source into the 4th input of merger. The merger |
| 38 // should produce 6 channel output. |
| 39 source1.connect(merger, 0, 0); |
| 40 source2.connect(merger, 0, 1); |
| 41 merger.connect(context.destination); |
| 42 source1.start(); |
| 43 source2.start(); |
22 | 44 |
23 // Task: Check if the merger outputs a silent channel when an input is | 45 // Schedule the disconnection of |source2| at the half of render |
24 // disconnected. | 46 // duration. |
25 audit.define('silent-disconnect', (task, should) => { | 47 context.suspend(disconnectTime).then(function() { |
26 var context = new OfflineAudioContext(numberOfChannels, renderDuration * s
ampleRate, sampleRate); | 48 source2.disconnect(); |
27 var merger = context.createChannelMerger(); | 49 context.resume(); |
28 var source1 = context.createBufferSource(); | 50 }); |
29 var source2 = context.createBufferSource(); | |
30 | 51 |
31 // Create and assign a constant buffer. | 52 context.startRendering() |
32 var bufferDCOffset = createConstantBuffer(context, 1, 1); | 53 .then(function(buffer) { |
33 source1.buffer = source2.buffer = bufferDCOffset; | 54 // The entire first channel of the output should be 1. |
34 source1.loop = source2.loop = true; | 55 should(buffer.getChannelData(0), 'Channel #0') |
| 56 .beConstantValueOf(1); |
35 | 57 |
36 // Connect the output of source into the 4th input of merger. The merger | 58 // Calculate the first zero index in the second channel. |
37 // should produce 6 channel output. | 59 let channel1 = buffer.getChannelData(1); |
38 source1.connect(merger, 0, 0); | 60 let disconnectIndex = disconnectTime * sampleRate; |
39 source2.connect(merger, 0, 1); | 61 disconnectIndex -= (disconnectIndex) % renderQuantum; |
40 merger.connect(context.destination); | 62 let firstZeroIndex = channel1.findIndex(function(element, index) { |
41 source1.start(); | 63 if (element === 0) |
42 source2.start(); | 64 return index; |
| 65 }); |
43 | 66 |
44 // Schedule the disconnection of |source2| at the half of render duration. | 67 // The second channel should contain 1, and 0 after the |
45 context.suspend(disconnectTime).then(function () { | 68 // disconnection. |
46 source2.disconnect(); | 69 should(channel1, 'Channel #1').containValues([1, 0]); |
47 context.resume(); | 70 should( |
| 71 firstZeroIndex, 'The index of first zero in the channel #1') |
| 72 .beEqualTo(disconnectIndex); |
| 73 |
| 74 }) |
| 75 .then(() => task.done()); |
48 }); | 76 }); |
49 | 77 |
50 context.startRendering().then(function (buffer) { | 78 audit.run(); |
51 // The entire first channel of the output should be 1. | 79 </script> |
52 should(buffer.getChannelData(0), 'Channel #0').beConstantValueOf(1); | 80 </body> |
53 | |
54 // Calculate the first zero index in the second channel. | |
55 var channel1 = buffer.getChannelData(1); | |
56 var disconnectIndex = disconnectTime * sampleRate; | |
57 disconnectIndex -= (disconnectIndex) % renderQuantum; | |
58 var firstZeroIndex = channel1.findIndex(function (element, index) { | |
59 if (element === 0) | |
60 return index; | |
61 }); | |
62 | |
63 // The second channel should contain 1, and 0 after the disconnection. | |
64 should(channel1, 'Channel #1').containValues([1, 0]); | |
65 should(firstZeroIndex, 'The index of first zero in the channel #1') | |
66 .beEqualTo(disconnectIndex); | |
67 | |
68 }).then(() => task.done()); | |
69 }); | |
70 | |
71 audit.run(); | |
72 </script> | |
73 </body> | |
74 | |
75 </html> | 81 </html> |
OLD | NEW |