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