Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Unified Diff: LayoutTests/webaudio/audionode-disconnect-audioparam.html

Issue 886173004: Fix AudioNode.disconnect() to support selective disconnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added comments and fixed exception messages Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e55b47e437e5479ef31408f5e66ecfbe260fef63
--- /dev/null
+++ b/LayoutTests/webaudio/audionode-disconnect-audioparam.html
@@ -0,0 +1,172 @@
+<!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. Then connect the half of buffer source to two gain
Raymond Toy 2015/02/12 19:45:52 What does "half of buffer source" mean?
hongchan 2015/02/13 01:16:56 It means the output of buffer source will be lower
+ // 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, 256, 44100);
+ 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;
Raymond Toy 2015/02/12 19:45:52 I think it's clearer to move this line just after
hongchan 2015/02/13 01:16:56 Hmm. I logically separated the configuration part
+
+ 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/12 19:45:52 As we discussed, this may not be true in general.
hongchan 2015/02/13 01:16:56 Done.
+ half.disconnect(gain2.gain);
+
+ Should.throwWithType('InvalidAccessError', function () {
+ half.disconnect(orphan.gain);
+ });
Raymond Toy 2015/02/12 19:45:52 Move this test somewhere else.
+
+ 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++;
+ }
Raymond Toy 2015/02/12 19:45:52 What happens if something is totally messed up and
hongchan 2015/02/13 01:16:56 That's a good point. Will fix to catch other wrong
+
+ 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) {
+
+ // Create a 2-channel buffer source with [1, 2] 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, 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.
+ splitter.disconnect(gain2.gain, 1);
+
+ Should.throwWithType('InvalidAccessError', function () {
+ splitter.disconnect(gain1.gain, 1);
+ });
+
+ Should.throwWithType('IndexSizeError', function () {
+ splitter.disconnect(gain1.gain, 2);
+ });
+
+ 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>

Powered by Google App Engine
This is Rietveld 408576698