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 <div id="description"></div> | |
12 <div id="console"></div> | |
13 <script> | |
14 description('Test disconnect() method.'); | |
15 window.jsTestIsAsync = true; | |
16 | |
17 var audit = Audit.createTaskRunner(); | |
18 | |
19 // Task 1: test disconnect(AudioParam) method. | |
20 audit.defineTask('disconnect(AudioParam)', function (done) { | |
21 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.
| |
22 var source = context.createBufferSource(); | |
23 var buffer1ch = createTestingBuffer(context, 1, 128); | |
24 var half = context.createGain(); | |
25 var gain1 = context.createGain(); | |
26 var gain2 = context.createGain(); | |
27 var orphan = context.createGain(); | |
28 | |
29 source.buffer = buffer1ch; | |
30 source.loop = true; | |
31 half.gain.value = 0.5; | |
32 | |
33 source.connect(gain1); | |
34 gain1.connect(gain2); | |
35 gain2.connect(context.destination); | |
36 source.connect(half); | |
37 half.connect(gain1.gain); // This amplifies by 1.5. (= 1.0 + 0.5) | |
38 half.connect(gain2.gain); // This amplifies by 1.5. (= 1.0 + 0.5) | |
39 | |
40 source.start(); | |
41 context.startRendering(); | |
42 | |
43 // This happens right after the rendering started. The closest moment when | |
44 // this operation can happen is the beginning of the 2nd rendering quantum . | |
45 // 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
| |
46 half.disconnect(gain2.gain); | |
47 | |
48 Should.throwWithType(function () { | |
49 half.disconnect(orphan.gain); | |
50 }, 'InvalidAccessError'); | |
51 | |
52 context.oncomplete = function (event) { | |
53 var channelData = event.renderedBuffer.getChannelData(0); | |
54 var valueIndex = 0; | |
55 var expectedValues = [2.25, 1.5]; // 1 * 1.5 * 1.5 -> 1 * 1.5 | |
56 | |
57 for (var i = 0; i < channelData.length; i++) { | |
58 // console.log(i + ' : ' + channelData[i]); | |
59 if (expectedValues[valueIndex] === channelData[i]) | |
60 valueIndex++; | |
61 } | |
62 | |
63 if (valueIndex === expectedValues.length) { | |
64 testPassed('Expected values are verified.'); | |
65 } else { | |
66 testFailed('Expected values do not match.'); | |
67 } | |
68 | |
69 done(); | |
70 }; | |
71 }); | |
72 | |
73 // Task 2: test disconnect(AudioParam, output) method. | |
74 audit.defineTask('disconnect(AudioParam, output)', function (done) { | |
75 var context = new OfflineAudioContext(2, 256, 44100); | |
76 var source = context.createBufferSource(); | |
77 var buffer2ch = createTestingBuffer(context, 2, 128); | |
78 var splitter = context.createChannelSplitter(2); | |
79 var half = context.createGain(); | |
80 var gain1 = context.createGain(); | |
81 var gain2 = context.createGain(); | |
82 | |
83 source.buffer = buffer2ch; | |
84 source.loop = true; | |
85 half.gain.value = 0.5; | |
86 | |
87 source.connect(gain1); | |
88 gain1.connect(gain2); | |
89 gain2.connect(context.destination); | |
90 | |
91 // |source| is [1, 2] but it becomes [0.5, 1]. Each splitter's output will | |
92 // be applied to |gain1.gain| and |gain2.gain| respectively in an additive | |
93 // fashion. | |
94 source.connect(half); | |
95 half.connect(splitter); | |
96 splitter.connect(gain1.gain, 0); // This amplifies by 1.5. (= 1.0 + 0.5) | |
97 splitter.connect(gain2.gain, 1); // This amplifies by 2. (= 1.0 + 1.0) | |
98 | |
99 source.start(); | |
100 context.startRendering(); | |
101 | |
102 // So the value change in the buffer will be observed at 128th sample. | |
103 // 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.
| |
104 splitter.disconnect(gain2.gain, 1); | |
105 | |
106 Should.throwWithType(function () { | |
107 splitter.disconnect(gain1.gain, 1); | |
108 }, 'InvalidAccessError'); | |
109 | |
110 Should.throwWithType(function () { | |
111 splitter.disconnect(gain1.gain, 2); | |
112 }, 'IndexSizeError'); | |
113 | |
114 context.oncomplete = function (event) { | |
115 var channelData0 = event.renderedBuffer.getChannelData(0); | |
116 var channelData1 = event.renderedBuffer.getChannelData(1); | |
117 var valueIndex = 0; | |
118 var expectedValuesCh0 = [3, 1.5]; // 1 * 1.5 * 2 -> 1 * 1.5 | |
119 var expectedValuesCh1 = [6, 3]; // 2 * 1.5 * 2 -> 2 * 1.5 | |
120 | |
121 for (var i = 0; i < channelData0.length; i++) { | |
122 // console.log(i + ' : ' + channelData0[i] + ' ' + channelData1[i]); | |
123 if (expectedValuesCh0[valueIndex] === channelData0[i] && | |
124 expectedValuesCh1[valueIndex] === channelData1[i]) { | |
125 valueIndex++; | |
126 } | |
127 } | |
128 | |
129 if (valueIndex === expectedValuesCh0.length) { | |
130 testPassed('Expected values are verified.'); | |
131 } else { | |
132 testFailed('Expected values do not match.'); | |
133 } | |
134 | |
135 done(); | |
136 }; | |
137 }); | |
138 | |
139 audit.defineTask('finish', function (done) { | |
140 finishJSTest(); | |
141 done(); | |
142 }); | |
143 | |
144 audit.runTasks( | |
145 'disconnect(AudioParam)', | |
146 'disconnect(AudioParam, output)', | |
147 'finish' | |
148 ); | |
149 | |
150 successfullyParsed = true; | |
151 </script> | |
152 </body> | |
153 | |
154 </html> | |
OLD | NEW |