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..74f213e1033924a34fa796f3a2323fb4c73e9353 |
--- /dev/null |
+++ b/LayoutTests/webaudio/audionode-disconnect-audioparam.html |
@@ -0,0 +1,154 @@ |
+<!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> |
+ <div id="description"></div> |
+ <div id="console"></div> |
+ <script> |
+ description('Test disconnect() method.'); |
+ window.jsTestIsAsync = true; |
+ |
+ var audit = Audit.createTaskRunner(); |
+ |
+ // Task 1: test disconnect(AudioParam) method. |
+ audit.defineTask('disconnect(AudioParam)', function (done) { |
+ var context = new OfflineAudioContext(1, 256, 44100); |
Raymond Toy
2015/02/11 21:31:17
Add description of how you're trying to test this.
hongchan
2015/02/12 18:37:59
Done.
|
+ var source = context.createBufferSource(); |
+ var buffer1ch = createTestingBuffer(context, 1, 128); |
+ var half = context.createGain(); |
+ var gain1 = context.createGain(); |
+ var gain2 = context.createGain(); |
+ var orphan = 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); |
+ half.connect(gain1.gain); // This amplifies by 1.5. (= 1.0 + 0.5) |
+ half.connect(gain2.gain); // This amplifies by 1.5. (= 1.0 + 0.5) |
+ |
+ source.start(); |
+ context.startRendering(); |
+ |
+ // This happens right after the rendering started. The closest moment when |
+ // this operation can happen is the beginning of the 2nd rendering quantum. |
+ // So the value change in the buffer will be observed at 128th sample. |
Raymond Toy
2015/02/11 21:31:17
Are you sure about this? The offline context is o
hongchan
2015/02/12 18:38:00
For the record, we discussed and are still not sur
|
+ half.disconnect(gain2.gain); |
+ |
+ Should.throwWithType(function () { |
+ half.disconnect(orphan.gain); |
+ }, 'InvalidAccessError'); |
+ |
+ context.oncomplete = function (event) { |
+ var channelData = event.renderedBuffer.getChannelData(0); |
+ var valueIndex = 0; |
+ var expectedValues = [2.25, 1.5]; // 1 * 1.5 * 1.5 -> 1 * 1.5 |
+ |
+ for (var i = 0; i < channelData.length; i++) { |
+ // console.log(i + ' : ' + channelData[i]); |
+ if (expectedValues[valueIndex] === channelData[i]) |
+ valueIndex++; |
+ } |
+ |
+ if (valueIndex === expectedValues.length) { |
+ testPassed('Expected values are verified.'); |
+ } else { |
+ testFailed('Expected values do not match.'); |
+ } |
+ |
+ done(); |
+ }; |
+ }); |
+ |
+ // Task 2: test disconnect(AudioParam, output) method. |
+ audit.defineTask('disconnect(AudioParam, output)', function (done) { |
+ var context = new OfflineAudioContext(2, 256, 44100); |
+ var source = context.createBufferSource(); |
+ var buffer2ch = createTestingBuffer(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| is [1, 2] but it becomes [0.5, 1]. Each splitter's output will |
+ // be applied to |gain1.gain| and |gain2.gain| respectively in an additive |
+ // fashion. |
+ source.connect(half); |
+ half.connect(splitter); |
+ splitter.connect(gain1.gain, 0); // This amplifies by 1.5. (= 1.0 + 0.5) |
+ splitter.connect(gain2.gain, 1); // This amplifies by 2. (= 1.0 + 1.0) |
+ |
+ source.start(); |
+ context.startRendering(); |
+ |
+ // So the value change in the buffer will be observed at 128th sample. |
+ // See the comment above. (line: 43) |
Raymond Toy
2015/02/11 21:31:17
Same comment on timing as above.
Also, I think it
hongchan
2015/02/12 18:37:59
Done.
|
+ splitter.disconnect(gain2.gain, 1); |
+ |
+ Should.throwWithType(function () { |
+ splitter.disconnect(gain1.gain, 1); |
+ }, 'InvalidAccessError'); |
+ |
+ Should.throwWithType(function () { |
+ splitter.disconnect(gain1.gain, 2); |
+ }, 'IndexSizeError'); |
+ |
+ context.oncomplete = function (event) { |
+ var channelData0 = event.renderedBuffer.getChannelData(0); |
+ var channelData1 = event.renderedBuffer.getChannelData(1); |
+ var valueIndex = 0; |
+ var expectedValuesCh0 = [3, 1.5]; // 1 * 1.5 * 2 -> 1 * 1.5 |
+ var expectedValuesCh1 = [6, 3]; // 2 * 1.5 * 2 -> 2 * 1.5 |
+ |
+ for (var i = 0; i < channelData0.length; i++) { |
+ // console.log(i + ' : ' + channelData0[i] + ' ' + channelData1[i]); |
+ if (expectedValuesCh0[valueIndex] === channelData0[i] && |
+ expectedValuesCh1[valueIndex] === channelData1[i]) { |
+ valueIndex++; |
+ } |
+ } |
+ |
+ if (valueIndex === expectedValuesCh0.length) { |
+ testPassed('Expected values are verified.'); |
+ } else { |
+ testFailed('Expected values do not match.'); |
+ } |
+ |
+ done(); |
+ }; |
+ }); |
+ |
+ audit.defineTask('finish', function (done) { |
+ finishJSTest(); |
+ done(); |
+ }); |
+ |
+ audit.runTasks( |
+ 'disconnect(AudioParam)', |
+ 'disconnect(AudioParam, output)', |
+ 'finish' |
+ ); |
+ |
+ successfullyParsed = true; |
+ </script> |
+</body> |
+ |
+</html> |