Chromium Code Reviews| Index: LayoutTests/webaudio/audionode-disconnect-audioparam.html |
| diff --git a/LayoutTests/webaudio/audionode-disconnect-audioparam.html b/LayoutTests/webaudio/audionode-disconnect-audioparam.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dc6190c5d7da992928503e5973c762317b4ce3b2 |
| --- /dev/null |
| +++ b/LayoutTests/webaudio/audionode-disconnect-audioparam.html |
| @@ -0,0 +1,209 @@ |
| +<!DOCTYPE html> |
| +<html> |
| + |
| +<head> |
| + <script src="../resources/js-test.js"></script> |
| + <script src="resources/compatibility.js"></script> |
| + <script src="resources/audio-testing.js"></script> |
| +</head> |
| + |
| +<body> |
| + <script> |
| + description('Test disconnect() method on AudioParam destination.'); |
| + window.jsTestIsAsync = true; |
| + |
| + var audit = Audit.createTaskRunner(); |
| + |
| + // Task 1: test disconnect(AudioParam) method. |
| + audit.defineTask('disconnect(AudioParam)', function (done) { |
| + |
| + // Creates a buffer source with value [1] and then connect it to two gain |
| + // nodes in series. The output of the buffer source is lowered by half |
| + // (* 0.5) and then connected to two |.gain| AudioParams in each gain node. |
| + // (1) bufferSource => gain1 => gain2 |
| + // (2) bufferSource => half => gain1.gain |
| + // (3) half => gain2.gain |
| + // This graph should produce the output of 2.25 (= 1 * 1.5 * 1.5). After |
| + // disconnecting (3), it should produce 1.5. |
| + var context = new OfflineAudioContext(1, 441000, 44100); |
| + var source = context.createBufferSource(); |
| + var buffer1ch = createTestingAudioBuffer(context, 1, 128); |
| + var half = context.createGain(); |
| + var gain1 = context.createGain(); |
| + var gain2 = context.createGain(); |
| + |
| + source.buffer = buffer1ch; |
| + source.loop = true; |
| + half.gain.value = 0.5; |
| + |
| + source.connect(gain1); |
| + gain1.connect(gain2); |
| + gain2.connect(context.destination); |
| + source.connect(half); |
| + |
| + // Connecting half to 2 AudioParams amplify the signal by 1.5 (= 1.0 + 0.5) |
|
Raymond Toy
2015/02/13 17:08:15
half -> |half|, maybe?
"AudioParams amplify" -> "
hongchan
2015/02/13 20:19:26
Rephrased.
|
| + // for each gain node, which is x2.25 (= 1.5 * 1.5) amplification in total. |
| + half.connect(gain1.gain); |
| + half.connect(gain2.gain); |
| + |
| + source.start(); |
| + |
| + context.startRendering().then(function (buffer) { |
| + var channelData = buffer.getChannelData(0); |
|
Raymond Toy
2015/02/13 17:08:15
I think you need a comment here that says you're d
|
| + var expectedValues = [2.25, 1.5]; // 1 * 1.5 * 1.5 -> 1 * 1.5 |
| + var passed = compareElements(expectedValues, channelData); |
| + |
| + if (passed) { |
| + testPassed('Expected values match.'); |
| + } else { |
| + testFailed('Expected values do not match.'); |
| + } |
| + }).then(done); |
| + |
| + // Disconnects after the rendering starts. |
| + // FIXME: This does not guarantee that the disconnection happens after the |
| + // rendering starts. Reconsider this when we implements a way to change the |
|
Raymond Toy
2015/02/13 17:08:15
We aren't actually considering implementing sample
hongchan
2015/02/13 20:19:26
Fixed.
|
| + // graph in a sample-accurately way in the middle of rendering. |
| + setTimeout(function () { |
| + half.disconnect(gain2.gain); |
| + }, 10); |
|
Raymond Toy
2015/02/13 17:08:15
I think there are some additional comments needed
hongchan
2015/02/13 20:19:26
Done.
|
| + }); |
| + |
| + // Task 2: test disconnect(AudioParam, output) method. |
| + audit.defineTask('disconnect(AudioParam, output)', function (done) { |
| + |
| + // Create a 2-channel buffer source with [1, 2] in each channel and |
| + // make a serial connection through gain1 and gain 2. The make the buffer |
| + // source half with a gain node and connect it to a 2-output splitter. |
| + // Connect each output to 2 gain AudioParams respectively. |
| + // (1) bufferSource => gain1 => gain2 |
| + // (2) bufferSource => half => splitter(2) |
| + // (3) splitter#0 => gain1.gain |
| + // (4) splitter#1 => gain2.gain |
| + // This graph should produce 3 (= 1 * 1.5 * 2) and 6 (= 2 * 1.5 * 2) for |
| + // each channel. After disconnecting (4), it should output 1.5 and 3. |
| + var context = new OfflineAudioContext(2, 441000, 44100); |
| + var source = context.createBufferSource(); |
| + var buffer2ch = createTestingAudioBuffer(context, 2, 128); |
| + var splitter = context.createChannelSplitter(2); |
| + var half = context.createGain(); |
| + var gain1 = context.createGain(); |
| + var gain2 = context.createGain(); |
| + |
| + source.buffer = buffer2ch; |
| + source.loop = true; |
| + half.gain.value = 0.5; |
| + |
| + source.connect(gain1); |
| + gain1.connect(gain2); |
| + gain2.connect(context.destination); |
| + |
| + // |source| originally is [1, 2] but it becomes [0.5, 1] after 0.5 gain. |
| + // Each splitter's output will be applied to |gain1.gain| and |gain2.gain| |
| + // respectively in an additive fashion. |
| + source.connect(half); |
| + half.connect(splitter); |
| + |
| + // This amplifies the signal by 1.5. (= 1.0 + 0.5) |
| + splitter.connect(gain1.gain, 0); |
| + |
| + // This amplifies the signal by 2. (= 1.0 + 1.0) |
| + splitter.connect(gain2.gain, 1); |
| + |
| + source.start(); |
| + context.startRendering().then(function (buffer) { |
| + var channelData0 = buffer.getChannelData(0); |
|
Raymond Toy
2015/02/13 17:08:15
Same comments here and for setTimeout as for the p
hongchan
2015/02/13 20:19:26
The comment is down there at setTimeout().
|
| + var channelData1 = buffer.getChannelData(1); |
| + var expectedValuesCh0 = [3, 1.5]; // 1 * 1.5 * 2 -> 1 * 1.5 |
| + var expectedValuesCh1 = [6, 3]; // 2 * 1.5 * 2 -> 2 * 1.5 |
| + var passedCh0 = compareElements(expectedValuesCh0, channelData0); |
| + var passedCh1 = compareElements(expectedValuesCh1, channelData1); |
| + |
| + if (passedCh0 && passedCh1) { |
| + testPassed('Expected values match.'); |
| + } else { |
| + testFailed('Expected values do not match.'); |
| + } |
| + }).then(done); |
| + |
| + // Disconnect after the rendering starts. See the comment above. |
| + setTimeout(function () { |
| + splitter.disconnect(gain2.gain, 1); |
| + }, 10); |
| + |
| + }); |
| + |
| + // Task 3: exception checks. |
| + audit.defineTask('exceptions', function (done) { |
| + var context = new AudioContext(); |
| + var gain1 = context.createGain(); |
| + var splitter = context.createChannelSplitter(2); |
| + var gain2 = context.createGain(); |
| + var gain3 = context.createGain(); |
| + |
| + gain1.connect(splitter); |
| + splitter.connect(gain2.gain, 0); |
| + splitter.connect(gain3.gain, 1); |
| + gain2.connect(gain3); |
| + gain3.connect(context.destination); |
| + |
| + // gain1 is not connected to gain3.gain. Exception should be thrown. |
| + Should.throwWithType('InvalidAccessError', function () { |
| + gain1.disconnect(gain3.gain); |
| + }); |
| + |
| + // When the output index is good but the destination is invalid. |
| + Should.throwWithType('InvalidAccessError', function () { |
| + splitter.disconnect(gain1.gain, 1); |
| + }); |
| + |
| + // When both arguments are wrong, throw IndexSizeError first. |
|
Raymond Toy
2015/02/13 17:08:15
This seems wrong. Since the splitter is not connec
hongchan
2015/02/13 20:19:26
I thought about it and decided to make it this way
|
| + Should.throwWithType('IndexSizeError', function () { |
| + splitter.disconnect(gain1.gain, 2); |
| + }); |
| + |
| + done(); |
| + }); |
| + |
| + audit.defineTask('finish', function (done) { |
| + finishJSTest(); |
| + done(); |
| + }); |
| + |
| + audit.runTasks( |
| + 'disconnect(AudioParam)', |
| + 'disconnect(AudioParam, output)', |
| + 'exceptions', |
| + 'finish' |
| + ); |
| + |
| + // The value-wise comparison of two arrays with different length. It |
| + // checks the value of element regardless of its occurrence. For example, |
| + // (1) [2.25, 2.25, 2.25, 1.5, 1.5, 1.5] === [2.25, 1.5] |
| + // (2) [2.25, 2.25, 1.5, 1.5, 0, 7, 7, 7, 9, 1] !== [2.25, 1.5] |
| + // (3) [-1, 2, 3, 2.25, 2.25, 1.5, 1.5] !== [2.25, 1.5] |
| + // (4) [3, 3, 3, 7, 7, 7] !== [2.25, 1.5] |
| + function compareElements(expected, actual) { |
| + var indexExpected = 0, indexActual = 0; |
| + while (indexExpected < expected.length && indexActual < actual.length) { |
| + if (expected[indexExpected] === actual[indexActual]) { |
| + indexActual++; |
| + } else { |
| + indexExpected++; |
| + } |
| + } |
| + |
| + if (indexExpected < expected.length - 1 || indexActual < actual.length - 1) { |
| + console.log('The value ' + actual[indexActual] + ' at index ' + |
|
Raymond Toy
2015/02/13 17:08:15
console.log or testFailed?
hongchan
2015/02/13 20:19:26
This method is called by the other test task. Decl
Raymond Toy
2015/02/13 20:47:25
compareElements could be modified to print out the
Raymond Toy
2015/02/13 20:52:33
I wasn't clear, but you don't need to make this mo
|
| + indexActual + ' was not found in expected values'); |
| + return false; |
| + } else { |
| + return true; |
| + } |
| + } |
| + |
| + successfullyParsed = true; |
| + </script> |
| +</body> |
| + |
| +</html> |