Chromium Code Reviews| 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/audio-testing.js"></script> | |
| 8 </head> | |
| 9 | |
| 10 <body> | |
| 11 <script> | |
| 12 description('Test disconnect() method on AudioNode destination.'); | |
| 13 window.jsTestIsAsync = true; | |
| 14 | |
| 15 var audit = Audit.createTaskRunner(); | |
| 16 | |
| 17 // Task 1: test disconnect() method. | |
| 18 audit.defineTask('disconnect()', function (done) { | |
| 19 | |
| 20 // Connect a source to multiple gain nodes, each connected to the | |
| 21 // destination. Then disconnect the source. The expected output should be | |
| 22 // all zeros since the source was disconnected. | |
| 23 var context = new OfflineAudioContext(1, 128, 44100); | |
| 24 var source = context.createBufferSource(); | |
| 25 var buffer1ch = createTestingAudioBuffer(context, 1, 128); | |
| 26 var gain1 = context.createGain(); | |
| 27 var gain2 = context.createGain(); | |
| 28 var gain3 = context.createGain(); | |
| 29 | |
| 30 source.buffer = buffer1ch; | |
| 31 | |
| 32 source.connect(gain1); | |
| 33 source.connect(gain2); | |
| 34 source.connect(gain3); | |
| 35 gain1.connect(context.destination); | |
| 36 gain2.connect(context.destination); | |
| 37 gain3.connect(context.destination); | |
| 38 source.start(); | |
| 39 | |
| 40 // This disconnects everything. | |
| 41 source.disconnect(); | |
| 42 | |
| 43 context.startRendering().then(function (buffer) { | |
| 44 var channelData = buffer.getChannelData(0); | |
| 45 | |
| 46 // With everything disconnected, the result should be zero. | |
| 47 Should.haveValueInChannel(0, channelData); | |
| 48 | |
| 49 }).then(done); | |
| 50 }); | |
| 51 | |
| 52 // Task 2: test disconnect(output) method. | |
| 53 audit.defineTask('disconnect(output)', function (done) { | |
| 54 | |
| 55 // Create multiple connections from each output of a ChannelSplitter | |
| 56 // to a gain node. Then test if disconnecting a single output of splitter | |
| 57 // is actually disconnected. | |
| 58 var context = new OfflineAudioContext(1, 128, 44100); | |
| 59 var source = context.createBufferSource(); | |
| 60 var buffer3ch = createTestingAudioBuffer(context, 3, 128); | |
| 61 var splitter = context.createChannelSplitter(3); | |
| 62 var sum = context.createGain(); | |
| 63 | |
| 64 source.buffer = buffer3ch; | |
| 65 | |
| 66 source.connect(splitter); | |
| 67 splitter.connect(sum, 0); | |
| 68 splitter.connect(sum, 1); | |
| 69 splitter.connect(sum, 2); | |
| 70 sum.connect(context.destination); | |
| 71 source.start(); | |
| 72 | |
| 73 // This disconnects the second output. | |
| 74 splitter.disconnect(1); | |
| 75 | |
| 76 context.startRendering().then(function (buffer) { | |
| 77 var channelData = buffer.getChannelData(0); | |
| 78 | |
| 79 // The rendered channel should contain 4. (= 1 + 0 + 3) | |
| 80 Should.haveValueInChannel(4, channelData); | |
| 81 | |
| 82 }).then(done); | |
| 83 }); | |
| 84 | |
| 85 // Task 3: test disconnect(AudioNode) method. | |
| 86 audit.defineTask('disconnect(AudioNode)', function (done) { | |
| 87 | |
| 88 // Connect a source to multiple gain nodes. Then test if disconnecting a | |
| 89 // single destination selectively works correctly. | |
| 90 var context = new OfflineAudioContext(1, 128, 44100); | |
| 91 var source = context.createBufferSource(); | |
| 92 var buffer1ch = createTestingAudioBuffer(context, 1, 128); | |
| 93 var gain1 = context.createGain(); | |
| 94 var gain2 = context.createGain(); | |
| 95 var gain3 = context.createGain(); | |
| 96 var orphan = context.createGain(); | |
| 97 | |
| 98 source.buffer = buffer1ch; | |
| 99 | |
| 100 source.connect(gain1); | |
| 101 source.connect(gain2); | |
| 102 source.connect(gain3); | |
| 103 gain1.connect(context.destination); | |
| 104 gain2.connect(context.destination); | |
| 105 gain3.connect(context.destination); | |
| 106 source.start(); | |
| 107 | |
| 108 source.disconnect(gain2); | |
| 109 | |
| 110 context.startRendering().then(function (buffer) { | |
| 111 var channelData = buffer.getChannelData(0); | |
| 112 | |
| 113 // The |sum| gain node should produce value 2. (1 + 0 + 1 = 2) | |
| 114 Should.haveValueInChannel(2, channelData); | |
| 115 | |
| 116 }).then(done); | |
| 117 }); | |
| 118 | |
| 119 // Task 4: test disconnect(AudioNode, output) method. | |
| 120 audit.defineTask('disconnect(AudioNode, output)', function (done) { | |
| 121 | |
| 122 // Connect a 2-channel buffer with [1, 2] in each channel to a | |
|
Raymond Toy
2015/02/13 17:08:16
"[1, 2] in each channel" is a bit confusing. This
hongchan
2015/02/13 20:19:26
Yes, that's what I meant. I will rephrase it.
| |
| 123 // ChannelSplitter, then connect the splitter to 2 gain nodes as shown | |
| 124 // below: | |
| 125 // (1) splitter#0 => gain1 | |
| 126 // (2) splitter#0 => gain2 | |
| 127 // (3) splitter#1 => gain2 | |
| 128 // Then disconnect (2) and verify if the selective disconnection on a | |
| 129 // specified output of the destination node works correctly. | |
| 130 var context = new OfflineAudioContext(1, 128, 44100); | |
| 131 var source = context.createBufferSource(); | |
| 132 var buffer2ch = createTestingAudioBuffer(context, 2, 128); | |
| 133 var splitter = context.createChannelSplitter(2); | |
| 134 var gain1 = context.createGain(); | |
| 135 var gain2 = context.createGain(); | |
| 136 | |
| 137 source.buffer = buffer2ch; | |
| 138 | |
| 139 source.connect(splitter); | |
| 140 splitter.connect(gain1, 0); // gain1 gets [1] | |
| 141 splitter.connect(gain2, 0); // gain2 gets [1 + 2] | |
|
Raymond Toy
2015/02/13 17:08:16
I think both of these would be clearer if you just
hongchan
2015/02/13 20:19:26
Done.
| |
| 142 splitter.connect(gain2, 1); | |
| 143 gain1.connect(context.destination); | |
| 144 gain2.connect(context.destination); | |
| 145 source.start(); | |
| 146 | |
| 147 splitter.disconnect(gain2, 0); // Now gain2 gets [2] | |
| 148 | |
| 149 context.startRendering().then(function (buffer) { | |
| 150 var channelData0 = buffer.getChannelData(0); | |
| 151 | |
| 152 // The sum of gain1 and gain2 should produce value 3. (= 1 + 2) | |
| 153 Should.haveValueInChannel(3, channelData0); | |
| 154 | |
| 155 }).then(done); | |
| 156 }); | |
| 157 | |
| 158 // Task 5: test disconnect(AudioNode, output, input) method. | |
| 159 audit.defineTask('disconnect(AudioNode, output, input)', function (done) { | |
| 160 | |
| 161 // Create a 3-channel buffer with [1, 2, 3] in each channel and then pass | |
| 162 // it through a splitter and a merger. Each input/output of the splitter | |
| 163 // and the merger is connected in a sequential order as shown below. | |
| 164 // (1) splitter#0 => merger#0 | |
| 165 // (2) splitter#1 => merger#1 | |
| 166 // (3) splitter#2 => merger#2 | |
| 167 // Then disconnect (3) and verify if each channel contains [1] and [2] | |
| 168 // respectively. | |
| 169 var context = new OfflineAudioContext(3, 128, 44100); | |
| 170 var source = context.createBufferSource(); | |
| 171 var buffer3ch = createTestingAudioBuffer(context, 3, 128); | |
| 172 var splitter = context.createChannelSplitter(3); | |
| 173 var merger = context.createChannelMerger(3); | |
| 174 | |
| 175 source.buffer = buffer3ch; | |
| 176 | |
| 177 source.connect(splitter); | |
| 178 splitter.connect(merger, 0, 0); | |
| 179 splitter.connect(merger, 1, 1); | |
| 180 splitter.connect(merger, 2, 2); | |
| 181 merger.connect(context.destination); | |
| 182 source.start(); | |
| 183 | |
| 184 splitter.disconnect(merger, 2, 2); | |
| 185 | |
| 186 context.startRendering().then(function (buffer) { | |
| 187 var channelData0 = buffer.getChannelData(0); | |
| 188 var channelData1 = buffer.getChannelData(1); | |
| 189 var channelData2 = buffer.getChannelData(2); | |
| 190 | |
| 191 // Each channel should have 1, 2, and 0 respectively. | |
| 192 Should.haveValueInChannel(1, channelData0); | |
| 193 Should.haveValueInChannel(2, channelData1); | |
| 194 Should.haveValueInChannel(0, channelData2); | |
| 195 | |
| 196 }).then(done); | |
| 197 }); | |
| 198 | |
| 199 // Task 6: exception checks. | |
| 200 audit.defineTask('exceptions', function (done) { | |
| 201 var context = new AudioContext(); | |
|
Raymond Toy
2015/02/13 17:08:16
Is AudioContext required or can OfflineAudioContex
hongchan
2015/02/13 20:19:26
Fixed.
| |
| 202 var gain1 = context.createGain(); | |
| 203 var splitter = context.createChannelSplitter(2); | |
| 204 var merger = context.createChannelMerger(2); | |
| 205 var gain2 = context.createGain(); | |
| 206 var gain3 = context.createGain(); | |
| 207 | |
| 208 gain1.connect(splitter); | |
| 209 splitter.connect(gain2, 0); | |
| 210 splitter.connect(gain3, 1); | |
| 211 splitter.connect(merger, 0, 0); | |
| 212 splitter.connect(merger, 1, 1); | |
| 213 gain2.connect(gain3); | |
| 214 gain3.connect(context.destination); | |
| 215 merger.connect(context.destination); | |
|
Raymond Toy
2015/02/13 17:08:16
Add a brief description of why you're connecting t
| |
| 216 | |
| 217 // There is no output #2. An exception should be thrown. | |
| 218 Should.throwWithType('IndexSizeError', function () { | |
| 219 splitter.disconnect(2); | |
| 220 }); | |
| 221 | |
| 222 // Disconnecting the output already disconnected should not throw. | |
| 223 Should.notThrow(function () { | |
| 224 splitter.disconnect(1); | |
| 225 splitter.disconnect(1); | |
| 226 }); | |
| 227 | |
| 228 // gain2 is already disconnected. An exception should be thrown. | |
| 229 Should.throwWithType('InvalidAccessError', function () { | |
| 230 gain1.disconnect(gain2); | |
|
Raymond Toy
2015/02/13 17:08:16
How is gain1 connected to gain2? I think you're tr
hongchan
2015/02/13 20:19:26
Oops. This is a mistake.
| |
| 231 gain1.disconnect(gain2); | |
| 232 }); | |
| 233 | |
| 234 // gain1 and gain3 are not connected. An exception should be thrown. | |
| 235 Should.throwWithType('InvalidAccessError', function () { | |
| 236 gain1.disconnect(gain3); | |
| 237 }); | |
| 238 | |
| 239 // There is no output #2 in the splitter. An exception should be thrown. | |
| 240 Should.throwWithType('IndexSizeError', function () { | |
| 241 splitter.disconnect(gain2, 2); | |
| 242 }); | |
| 243 | |
| 244 // splitter and gain1 are not connected. An exception should be thrown. | |
| 245 Should.throwWithType('InvalidAccessError', function () { | |
| 246 splitter.disconnect(gain1, 0); | |
| 247 }); | |
| 248 | |
| 249 // splitter and gain3 are not connection. An exception should be thrown. | |
|
Raymond Toy
2015/02/13 17:08:16
"connection" -> "connected". Plus this comment do
hongchan
2015/02/13 20:19:26
Fixed.
| |
| 250 Should.throwWithType('InvalidAccessError', function () { | |
| 251 splitter.disconnect(gain3, 0, 0); | |
| 252 }); | |
| 253 | |
| 254 // The output index is out of bound. An exception should be thrown. | |
| 255 Should.throwWithType('IndexSizeError', function () { | |
| 256 splitter.disconnect(merger, 3, 0); | |
| 257 }); | |
| 258 | |
| 259 done(); | |
| 260 }); | |
| 261 | |
| 262 audit.defineTask('finish', function (done) { | |
| 263 finishJSTest(); | |
| 264 done(); | |
| 265 }); | |
| 266 | |
| 267 audit.runTasks( | |
| 268 'disconnect()', | |
| 269 'disconnect(output)', | |
| 270 'disconnect(AudioNode)', | |
| 271 'disconnect(AudioNode, output)', | |
| 272 'disconnect(AudioNode, output, input)', | |
| 273 'exceptions', | |
| 274 'finish' | |
| 275 ); | |
| 276 | |
| 277 successfullyParsed = true; | |
| 278 </script> | |
| 279 </body> | |
| 280 | |
| 281 </html> | |
| OLD | NEW |