OLD | NEW |
1 <!doctype html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Test Processing Of AudioParams of Disconnected AudioNodes</title> | 4 <title> |
| 5 Test Processing Of AudioParams of Disconnected AudioNodes |
| 6 </title> |
5 <script src="../../resources/testharness.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
6 <script src="../../resources/testharnessreport.js"></script> | 8 <script src="../../resources/testharnessreport.js"></script> |
7 <script src="../resources/audit.js"></script> | 9 <script src="../resources/audit.js"></script> |
8 </head> | 10 </head> |
9 | |
10 <body> | 11 <body> |
11 <script> | 12 <script id="layout-test-code"> |
12 // Arbitrary sample rate. | 13 // Arbitrary sample rate. |
13 var sampleRate = 8000; | 14 let sampleRate = 8000; |
14 | 15 |
15 // Arbitrary number of frames for the test, except it must be greater than | 16 // Arbitrary number of frames for the test, except it must be greater than |
16 // |automationEndFrame|. | 17 // |automationEndFrame|. |
17 var renderFrames = 1024; | 18 let renderFrames = 1024; |
18 | 19 |
19 // The linear ramp automation ends at this frame. Arbitrary, except it | 20 // The linear ramp automation ends at this frame. Arbitrary, except it |
20 // must be strictly less than the render length. | 21 // must be strictly less than the render length. |
21 var automationEndFrame = 128; | 22 let automationEndFrame = 128; |
22 | 23 |
23 var audit = Audit.createTaskRunner(); | 24 let audit = Audit.createTaskRunner(); |
24 | 25 |
25 // There should be a test for every single node which has an AudioParam. | 26 // There should be a test for every single node which has an AudioParam. |
26 // Source nodes are not included in this because the AudioParams for the | 27 // Source nodes are not included in this because the AudioParams for the |
27 // source nodes only process when the node has been started. | 28 // source nodes only process when the node has been started. |
28 | 29 |
29 audit.define("BiquadFilterNode", (task, should) => { | 30 audit.define('BiquadFilterNode', (task, should) => { |
30 var nodeName = "BiquadFilterNode" | 31 let nodeName = 'BiquadFilterNode' |
31 Promise.all([ | 32 Promise |
32 testParamAutomation(should, { | 33 .all([ |
33 nodeName: nodeName, | 34 testParamAutomation(should, { |
34 paramName: "Q", | 35 nodeName: nodeName, |
35 initialValue: 2, | 36 paramName: 'Q', |
36 rampFinalValue: 5 | 37 initialValue: 2, |
37 }), | 38 rampFinalValue: 5 |
38 testParamAutomation(should, { | 39 }), |
39 nodeName: nodeName, | 40 testParamAutomation(should, { |
40 paramName: "detune", | 41 nodeName: nodeName, |
41 initialValue: 1, | 42 paramName: 'detune', |
42 rampFinalValue: 0.5 | 43 initialValue: 1, |
43 }), | 44 rampFinalValue: 0.5 |
44 testParamAutomation(should, { | 45 }), |
45 nodeName: nodeName, | 46 testParamAutomation(should, { |
46 paramName: "frequency", | 47 nodeName: nodeName, |
47 initialValue: 1000, | 48 paramName: 'frequency', |
48 rampFinalValue: 100 | 49 initialValue: 1000, |
49 }), | 50 rampFinalValue: 100 |
50 testParamAutomation(should, { | 51 }), |
51 nodeName: nodeName, | 52 testParamAutomation(should, { |
52 paramName: "gain", | 53 nodeName: nodeName, |
53 initialValue: -3, | 54 paramName: 'gain', |
54 rampFinalValue: 3 | 55 initialValue: -3, |
55 }), | 56 rampFinalValue: 3 |
56 ]).then(() => task.done()); | 57 }), |
57 }); | 58 ]) |
58 | 59 .then(() => task.done()); |
59 audit.define("DelayNode", (task, should) => { | 60 }); |
| 61 |
| 62 audit.define('DelayNode', (task, should) => { |
60 testParamAutomation(should, { | 63 testParamAutomation(should, { |
61 nodeName: "DelayNode", | 64 nodeName: 'DelayNode', |
62 paramName: "delayTime", | 65 paramName: 'delayTime', |
63 initialValue: 0.25, | 66 initialValue: 0.25, |
64 rampFinalValue: 0.5 | 67 rampFinalValue: 0.5 |
65 }).then(() => task.done()); | 68 }).then(() => task.done()); |
66 }); | 69 }); |
67 | 70 |
68 audit.define("DynamicsCompressorNode", (task, should) => { | 71 audit.define('DynamicsCompressorNode', (task, should) => { |
69 var nodeName = "DynamicsCompressorNode"; | 72 let nodeName = 'DynamicsCompressorNode'; |
70 Promise.all([ | 73 Promise |
71 testParamAutomation(should, { | 74 .all([ |
72 nodeName: nodeName, | 75 testParamAutomation(should, { |
73 paramName: "attack", | 76 nodeName: nodeName, |
74 initialValue: 0.1, | 77 paramName: 'attack', |
75 rampFinalValue: 0.5 | 78 initialValue: 0.1, |
76 }), | 79 rampFinalValue: 0.5 |
77 testParamAutomation(should, { | 80 }), |
78 nodeName: nodeName, | 81 testParamAutomation(should, { |
79 paramName: "knee", | 82 nodeName: nodeName, |
80 initialValue: 0, | 83 paramName: 'knee', |
81 rampFinalValue: 25 | 84 initialValue: 0, |
82 }), | 85 rampFinalValue: 25 |
83 testParamAutomation(should, { | 86 }), |
84 nodeName: nodeName, | 87 testParamAutomation(should, { |
85 paramName: "ratio", | 88 nodeName: nodeName, |
86 initialValue: 1, | 89 paramName: 'ratio', |
87 rampFinalValue: 15 | 90 initialValue: 1, |
88 }), | 91 rampFinalValue: 15 |
89 testParamAutomation(should, { | 92 }), |
90 nodeName: nodeName, | 93 testParamAutomation(should, { |
91 paramName: "release", | 94 nodeName: nodeName, |
92 initialValue: 0, | 95 paramName: 'release', |
93 rampFinalValue: 0.75 | 96 initialValue: 0, |
94 }), | 97 rampFinalValue: 0.75 |
95 testParamAutomation(should, { | 98 }), |
96 nodeName: nodeName, | 99 testParamAutomation(should, { |
97 paramName: "threshold", | 100 nodeName: nodeName, |
98 initialValue: -50, | 101 paramName: 'threshold', |
99 rampFinalValue: -10 | 102 initialValue: -50, |
100 }) | 103 rampFinalValue: -10 |
101 ]).then(() => task.done()); | 104 }) |
102 }); | 105 ]) |
103 | 106 .then(() => task.done()); |
104 audit.define("GainNode", (task, should) => { | 107 }); |
| 108 |
| 109 audit.define('GainNode', (task, should) => { |
105 testParamAutomation(should, { | 110 testParamAutomation(should, { |
106 nodeName: "GainNode", | 111 nodeName: 'GainNode', |
107 paramName: "gain", | 112 paramName: 'gain', |
108 initialValue: 1, | 113 initialValue: 1, |
109 rampFinalValue: 0.5 | 114 rampFinalValue: 0.5 |
110 }).then(() => task.done()); | 115 }).then(() => task.done()); |
111 }); | 116 }); |
112 | 117 |
113 audit.define("PannerNode", (task, should) => { | 118 audit.define('PannerNode', (task, should) => { |
114 var nodeName = "PannerNode"; | 119 let nodeName = 'PannerNode'; |
115 Promise.all([ | 120 Promise |
116 testParamAutomation(should, { | 121 .all([ |
117 nodeName: nodeName, | 122 testParamAutomation(should, { |
118 paramName: "positionX", | 123 nodeName: nodeName, |
119 initialValue: 0.1, | 124 paramName: 'positionX', |
120 rampFinalValue: 0.5 | 125 initialValue: 0.1, |
121 }), | 126 rampFinalValue: 0.5 |
122 testParamAutomation(should, { | 127 }), |
123 nodeName: nodeName, | 128 testParamAutomation(should, { |
124 paramName: "positionY", | 129 nodeName: nodeName, |
125 initialValue: 2, | 130 paramName: 'positionY', |
126 rampFinalValue: 30 | 131 initialValue: 2, |
127 }), | 132 rampFinalValue: 30 |
128 testParamAutomation(should, { | 133 }), |
129 nodeName: nodeName, | 134 testParamAutomation(should, { |
130 paramName: "positionZ", | 135 nodeName: nodeName, |
131 initialValue: 1, | 136 paramName: 'positionZ', |
132 rampFinalValue: 15 | 137 initialValue: 1, |
133 }), | 138 rampFinalValue: 15 |
134 testParamAutomation(should, { | 139 }), |
135 nodeName: nodeName, | 140 testParamAutomation(should, { |
136 paramName: "orientationX", | 141 nodeName: nodeName, |
137 initialValue: 0.1, | 142 paramName: 'orientationX', |
138 rampFinalValue: 0.5 | 143 initialValue: 0.1, |
139 }), | 144 rampFinalValue: 0.5 |
140 testParamAutomation(should, { | 145 }), |
141 nodeName: nodeName, | 146 testParamAutomation(should, { |
142 paramName: "orientationY", | 147 nodeName: nodeName, |
143 initialValue: 2, | 148 paramName: 'orientationY', |
144 rampFinalValue: 30 | 149 initialValue: 2, |
145 }), | 150 rampFinalValue: 30 |
146 testParamAutomation(should, { | 151 }), |
147 nodeName: nodeName, | 152 testParamAutomation(should, { |
148 paramName: "orientationZ", | 153 nodeName: nodeName, |
149 initialValue: 1, | 154 paramName: 'orientationZ', |
150 rampFinalValue: 15 | 155 initialValue: 1, |
151 }), | 156 rampFinalValue: 15 |
152 ]).then(() => task.done()); | 157 }), |
153 }); | 158 ]) |
154 | 159 .then(() => task.done()); |
155 audit.define("StereoPannerNode", (task, should) => { | 160 }); |
| 161 |
| 162 audit.define('StereoPannerNode', (task, should) => { |
156 testParamAutomation(should, { | 163 testParamAutomation(should, { |
157 nodeName: "StereoPannerNode", | 164 nodeName: 'StereoPannerNode', |
158 paramName: "pan", | 165 paramName: 'pan', |
159 initialValue: 1, | 166 initialValue: 1, |
160 rampFinalValue: 0.5 | 167 rampFinalValue: 0.5 |
161 }).then(() => task.done()); | 168 }).then(() => task.done()); |
162 }); | 169 }); |
163 | 170 |
164 audit.define("AudioListener", (task, should) => { | 171 audit.define('AudioListener', (task, should) => { |
165 Promise.all([ | 172 Promise |
166 testAudioListener(should, { | 173 .all([ |
167 paramName: "positionX", | 174 testAudioListener(should, { |
168 initialValue: 1, | 175 paramName: 'positionX', |
169 rampFinalValue: 100 | 176 initialValue: 1, |
170 }), | 177 rampFinalValue: 100 |
171 testAudioListener(should, { | 178 }), |
172 paramName: "positionY", | 179 testAudioListener(should, { |
173 initialValue: 1, | 180 paramName: 'positionY', |
174 rampFinalValue: 200 | 181 initialValue: 1, |
175 }), | 182 rampFinalValue: 200 |
176 testAudioListener(should, { | 183 }), |
177 paramName: "positionZ", | 184 testAudioListener(should, { |
178 initialValue: 1, | 185 paramName: 'positionZ', |
179 rampFinalValue: 300 | 186 initialValue: 1, |
180 }), | 187 rampFinalValue: 300 |
181 testAudioListener(should, { | 188 }), |
182 paramName: "forwardX", | 189 testAudioListener(should, { |
183 initialValue: 1, | 190 paramName: 'forwardX', |
184 rampFinalValue: -100 | 191 initialValue: 1, |
185 }), | 192 rampFinalValue: -100 |
186 testAudioListener(should, { | 193 }), |
187 paramName: "forwardY", | 194 testAudioListener(should, { |
188 initialValue: 1, | 195 paramName: 'forwardY', |
189 rampFinalValue: -200 | 196 initialValue: 1, |
190 }), | 197 rampFinalValue: -200 |
191 testAudioListener(should, { | 198 }), |
192 paramName: "forwardZ", | 199 testAudioListener(should, { |
193 initialValue: 1, | 200 paramName: 'forwardZ', |
194 rampFinalValue: -300 | 201 initialValue: 1, |
195 }), | 202 rampFinalValue: -300 |
196 testAudioListener(should, { | 203 }), |
197 paramName: "upX", | 204 testAudioListener( |
198 initialValue: 1, | 205 should, |
199 rampFinalValue: 99 | 206 {paramName: 'upX', initialValue: 1, rampFinalValue: 99}), |
200 }), | 207 testAudioListener( |
201 testAudioListener(should, { | 208 should, |
202 paramName: "upY", | 209 {paramName: 'upY', initialValue: 1, rampFinalValue: 42}), |
203 initialValue: 1, | 210 testAudioListener( |
204 rampFinalValue: 42 | 211 should, |
205 }), | 212 {paramName: 'upZ', initialValue: 1, rampFinalValue: 137}), |
206 testAudioListener(should, { | 213 ]) |
207 paramName: "upZ", | 214 .then(() => task.done()); |
208 initialValue: 1, | |
209 rampFinalValue: 137 | |
210 }), | |
211 ]).then(() => task.done()); | |
212 }); | 215 }); |
213 | 216 |
214 // Run test of automation processing. |options| is a dictionary that | 217 // Run test of automation processing. |options| is a dictionary that |
215 // describes the node to test, the AudioParams to be tested and the values | 218 // describes the node to test, the AudioParams to be tested and the values |
216 // for the AudioParam. The members of the dictionary are: | 219 // for the AudioParam. The members of the dictionary are: |
217 // | 220 // |
218 // nodeName - name of the node (constructor name) | 221 // nodeName - name of the node (constructor name) |
219 // paramName - name of the AudioParam to be tested | 222 // paramName - name of the AudioParam to be tested |
220 // initialValue - starting value for linear ramp | 223 // initialValue - starting value for linear ramp |
221 // rampFinalValue - finale value for linear ramp | 224 // rampFinalValue - finale value for linear ramp |
222 // | 225 // |
223 // The test is considered to have succeeded if the |.value| of the AudioPa
ram | 226 // The test is considered to have succeeded if the |.value| of the |
224 // is the final value. | 227 // AudioParam is the final value. |
225 // | 228 // |
226 // A simple graph is created containing the node to be tested, connected | 229 // A simple graph is created containing the node to be tested, connected |
227 // to the destination. A linear ramp automation is scheduled for the | 230 // to the destination. A linear ramp automation is scheduled for the |
228 // specified AudioParam, starting and ending at the values given. | 231 // specified AudioParam, starting and ending at the values given. |
229 // | 232 // |
230 // Processing is started and after some number of frames, the |.value| of | 233 // Processing is started and after some number of frames, the |.value| of |
231 // the AudioParam is obtained and compared against the final value. These | 234 // the AudioParam is obtained and compared against the final value. These |
232 // should match exactly. | 235 // should match exactly. |
233 function testParamAutomation(should, options) { | 236 function testParamAutomation(should, options) { |
234 var context = new OfflineAudioContext(1, renderFrames, sampleRate); | 237 let context = new OfflineAudioContext(1, renderFrames, sampleRate); |
235 | 238 |
236 // Create the node to be tested | 239 // Create the node to be tested |
237 var node = new window[options.nodeName](context); | 240 let node = new window[options.nodeName](context); |
238 node.connect(context.destination); | 241 node.connect(context.destination); |
239 | 242 |
240 // A linear ramp starting at frame 0 to frame |automationEndFrame| is | 243 // A linear ramp starting at frame 0 to frame |automationEndFrame| is |
241 // used for the test. This value is fairly arbitrary, but it should be | 244 // used for the test. This value is fairly arbitrary, but it should be |
242 // less than the total render frames. | 245 // less than the total render frames. |
243 | 246 |
244 node[options.paramName].setValueAtTime(options.initialValue, 0); | 247 node[options.paramName].setValueAtTime(options.initialValue, 0); |
245 node[options.paramName].linearRampToValueAtTime(options.rampFinalValue, | 248 node[options.paramName].linearRampToValueAtTime( |
246 automationEndFrame / context.sampleRate); | 249 options.rampFinalValue, automationEndFrame / context.sampleRate); |
247 | 250 |
248 return context.startRendering() | 251 return context.startRendering().then(function(resultBuffer) { |
249 .then(function (resultBuffer) { | 252 // Sanity check: the given ramp final value must not be the default |
250 // Sanity check: the given ramp final value must not be the default | 253 // value, otherwise we can't easily tell if the automation was |
251 // value, otherwise we can't easily tell if the automation was | 254 // actually run. |
252 // actually run. | 255 should( |
253 should(options.rampFinalValue, | 256 options.rampFinalValue, |
254 options.nodeName + "." + options.paramName + " ramp final value") | 257 options.nodeName + '.' + options.paramName + ' ramp final value') |
255 .notBeEqualTo(node[options.paramName].defaultValue); | 258 .notBeEqualTo(node[options.paramName].defaultValue); |
256 | 259 |
257 // The actual AudioParam value should be the rampe final value. | 260 // The actual AudioParam value should be the rampe final value. |
258 should(node[options.paramName].value, | 261 should( |
259 options.nodeName + "." + options.paramName + ".value") | 262 node[options.paramName].value, |
| 263 options.nodeName + '.' + options.paramName + '.value') |
260 .beEqualTo(options.rampFinalValue); | 264 .beEqualTo(options.rampFinalValue); |
261 }); | 265 }); |
262 } | 266 } |
263 | 267 |
264 function testAudioListener(should, options) { | 268 function testAudioListener(should, options) { |
265 var context = new OfflineAudioContext(1, renderFrames, sampleRate); | 269 let context = new OfflineAudioContext(1, renderFrames, sampleRate); |
266 | 270 |
267 // Create the node to be tested | 271 // Create the node to be tested |
268 var node = new PannerNode(context); | 272 let node = new PannerNode(context); |
269 node.connect(context.destination); | 273 node.connect(context.destination); |
270 | 274 |
271 // A linear ramp starting at frame 0 to frame |automationEndFrame| is | 275 // A linear ramp starting at frame 0 to frame |automationEndFrame| is |
272 // used for the test. This value is fairly arbitrary, but it should be | 276 // used for the test. This value is fairly arbitrary, but it should be |
273 // less than the total render frames. | 277 // less than the total render frames. |
274 | 278 |
275 context.listener[options.paramName].setValueAtTime(options.initialValue,
0); | 279 context.listener[options.paramName].setValueAtTime( |
276 context.listener[options.paramName].linearRampToValueAtTime(options.ramp
FinalValue, | 280 options.initialValue, 0); |
277 automationEndFrame / context.sampleRate); | 281 context.listener[options.paramName].linearRampToValueAtTime( |
| 282 options.rampFinalValue, automationEndFrame / context.sampleRate); |
278 | 283 |
279 return context.startRendering() | 284 return context.startRendering().then(function(resultBuffer) { |
280 .then(function (resultBuffer) { | 285 // Sanity check: the given ramp final value must not be the default |
281 // Sanity check: the given ramp final value must not be the default | 286 // value, otherwise we can't easily tell if the automation was |
282 // value, otherwise we can't easily tell if the automation was | 287 // actually run. |
283 // actually run. | 288 should( |
284 should(options.rampFinalValue, | 289 options.rampFinalValue, |
285 "AudioListener." + options.paramName + " ramp final value") | 290 'AudioListener.' + options.paramName + ' ramp final value') |
286 .notBeEqualTo(context.listener[options.paramName].defaultValue); | 291 .notBeEqualTo(context.listener[options.paramName].defaultValue); |
287 | 292 |
288 // The actual AudioParam value should be the rampe final value. | 293 // The actual AudioParam value should be the rampe final value. |
289 should(context.listener[options.paramName].value, | 294 should( |
290 "AudioListener." + options.paramName + ".value") | 295 context.listener[options.paramName].value, |
| 296 'AudioListener.' + options.paramName + '.value') |
291 .beEqualTo(options.rampFinalValue); | 297 .beEqualTo(options.rampFinalValue); |
292 }); | 298 }); |
293 } | 299 } |
294 | 300 |
295 audit.run(); | 301 audit.run(); |
296 </script> | 302 </script> |
297 </body> | 303 </body> |
298 </html> | 304 </html> |
OLD | NEW |