OLD | NEW |
---|---|
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../../resources/testharness.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
5 <script src="../../resources/testharnessreport.js"></script> | 5 <script src="../../resources/testharnessreport.js"></script> |
6 <script src="../resources/audit-util.js"></script> | 6 <script src="../resources/audit-util.js"></script> |
7 <script src="../resources/audio-testing.js"></script> | 7 <script src="../resources/audit.js"></script> |
8 <script src="../resources/panner-formulas.js"></script> | 8 <script src="../resources/panner-formulas.js"></script> |
9 <title>Test Basic PannerNode with Automation Position Properties</title> | 9 <title>Test Basic PannerNode with Automation Position Properties</title> |
10 </head> | 10 </head> |
11 | 11 |
12 <body> | 12 <body> |
13 <script> | 13 <script> |
14 var sampleRate = 48000; | 14 var sampleRate = 48000; |
15 | 15 |
16 // These tests are quite slow, so don't run for many frames. 256 frames s hould be enough to | 16 // These tests are quite slow, so don't run for many frames. 256 frames s hould be enough to |
17 // demonstrate that automations are working. | 17 // demonstrate that automations are working. |
(...skipping 10 matching lines...) Expand all Loading... | |
28 setter: "positionY", | 28 setter: "positionY", |
29 }, { | 29 }, { |
30 setter: "positionZ", | 30 setter: "positionZ", |
31 }]; | 31 }]; |
32 | 32 |
33 // Create tests for the panner position setters. Both mono and steroe sou rces are tested. | 33 // Create tests for the panner position setters. Both mono and steroe sou rces are tested. |
34 for (var k = 0; k < testConfig.length; ++k) { | 34 for (var k = 0; k < testConfig.length; ++k) { |
35 var config = testConfig[k]; | 35 var config = testConfig[k]; |
36 // Function to create the test to define the test. | 36 // Function to create the test to define the test. |
37 var tester = function (config, channelCount) { | 37 var tester = function (config, channelCount) { |
38 return function (done) { | 38 return (task, should) => { |
39 var nodes = createGraph(channelCount); | 39 var nodes = createGraph(channelCount); |
40 var {context, source, panner} = nodes; | 40 var {context, source, panner} = nodes; |
41 | 41 |
42 var message = channelCount == 1 ? "Mono" : "Stereo"; | 42 var message = channelCount == 1 ? "Mono" : "Stereo"; |
43 message += " panner." + config.setter; | 43 message += " panner." + config.setter; |
44 | 44 |
45 testPositionSetter({ | 45 testPositionSetter(should, { |
46 nodes: nodes, | 46 nodes: nodes, |
47 pannerSetter: panner[config.setter], | 47 pannerSetter: panner[config.setter], |
48 message: message | 48 message: message |
49 }).then(done); | 49 }).then(() => task.done()); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 audit.defineTask("Stereo panner." + config.setter, tester(config, 2)); | 53 audit.define("Stereo panner." + config.setter, tester(config, 2)); |
54 audit.defineTask("Mono panner." + config.setter, tester(config, 1)); | 54 audit.define("Mono panner." + config.setter, tester(config, 1)); |
55 } | 55 } |
56 | 56 |
57 // Create tests for the listener position setters. Both mono and steroe s ources are tested. | 57 // Create tests for the listener position setters. Both mono and steroe s ources are tested. |
58 for (var k = 0; k < testConfig.length; ++k) { | 58 for (var k = 0; k < testConfig.length; ++k) { |
59 var config = testConfig[k]; | 59 var config = testConfig[k]; |
60 // Function to create the test to define the test. | 60 // Function to create the test to define the test. |
61 var tester = function (config, channelCount) { | 61 var tester = function (config, channelCount) { |
62 return function (done) { | 62 return (task, should) => { |
63 var nodes = createGraph(channelCount); | 63 var nodes = createGraph(channelCount); |
64 var {context, source, panner} = nodes; | 64 var {context, source, panner} = nodes; |
65 | 65 |
66 var message = channelCount == 1 ? "Mono" : "Stereo"; | 66 var message = channelCount == 1 ? "Mono" : "Stereo"; |
67 message += " listener." + config.setter; | 67 message += " listener." + config.setter; |
68 | 68 |
69 // Some relatively arbitrary (non-default) position for the source l ocation. | 69 // Some relatively arbitrary (non-default) position for the source l ocation. |
70 panner.setPosition(1,0,1); | 70 panner.setPosition(1,0,1); |
71 | 71 |
72 testPositionSetter({ | 72 testPositionSetter(should, { |
73 nodes: nodes, | 73 nodes: nodes, |
74 pannerSetter: context.listener[config.setter], | 74 pannerSetter: context.listener[config.setter], |
75 message: message | 75 message: message |
76 }).then(done); | 76 }).then(() => task.done()); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 audit.defineTask("Stereo listener." + config.setter, tester(config, 2)); | 80 audit.define("Stereo listener." + config.setter, tester(config, 2)); |
81 audit.defineTask("Mono listener." + config.setter, tester(config, 1)); | 81 audit.define("Mono listener." + config.setter, tester(config, 1)); |
82 } | 82 } |
83 | 83 |
84 // Test setPosition method. | 84 // Test setPosition method. |
85 audit.defineTask("setPosition", function (done) { | 85 audit.define("setPosition", (task, should) => { |
86 var {context, panner, source} = createGraph(2); | 86 var {context, panner, source} = createGraph(2); |
87 | 87 |
88 // Initialize source position (values don't really matter). | 88 // Initialize source position (values don't really matter). |
89 panner.setPosition(1,1,1); | 89 panner.setPosition(1,1,1); |
90 | 90 |
91 // After some (unimportant) time, move the panner to a (any) new locatio n. | 91 // After some (unimportant) time, move the panner to a (any) new locatio n. |
92 var suspendFrame = 128; | 92 var suspendFrame = 128; |
93 context.suspend(suspendFrame / sampleRate).then(function () { | 93 context.suspend(suspendFrame / sampleRate).then(function () { |
94 panner.setPosition(-100, 2000, 8000); | 94 panner.setPosition(-100, 2000, 8000); |
95 }).then(context.resume.bind(context)); | 95 }).then(context.resume.bind(context)); |
96 | 96 |
97 context.startRendering().then(function (resultBuffer) { | 97 context.startRendering().then(function (resultBuffer) { |
98 verifyPannerOutputChanged(resultBuffer, {message: "setPosition", suspe ndFrame: suspendFrame}); | 98 verifyPannerOutputChanged(should, resultBuffer, { |
99 }).then(done); | 99 message: "setPosition", |
100 suspendFrame: suspendFrame | |
101 }); | |
102 }) | |
103 .then(() => task.done()); | |
100 }); | 104 }); |
101 | 105 |
102 audit.defineTask("orientation setter", function (done) { | 106 audit.define("orientation setter", (task, should) => { |
103 var {context, panner, source} = createGraph(2); | 107 var {context, panner, source} = createGraph(2); |
104 | 108 |
105 // For orientation to matter, we need to make the source directional, an d also move away | 109 // For orientation to matter, we need to make the source directional, an d also move away |
106 // from the listener (because the default location is 0,0,0). | 110 // from the listener (because the default location is 0,0,0). |
107 panner.setPosition(0,0,1); | 111 panner.setPosition(0,0,1); |
108 panner.coneInnerAngle = 0; | 112 panner.coneInnerAngle = 0; |
109 panner.coneOuterAngle = 360; | 113 panner.coneOuterAngle = 360; |
110 panner.coneOuterGain = .001; | 114 panner.coneOuterGain = .001; |
111 | 115 |
112 // After some (unimportant) time, change the panner orientation to a new orientation. The | 116 // After some (unimportant) time, change the panner orientation to a new orientation. The |
113 // only constraint is that the orientation changes from before. | 117 // only constraint is that the orientation changes from before. |
114 var suspendFrame = 128; | 118 var suspendFrame = 128; |
115 context.suspend(suspendFrame / sampleRate).then(function () { | 119 context.suspend(suspendFrame / sampleRate).then(function () { |
116 panner.orientationX.value = -100; | 120 panner.orientationX.value = -100; |
117 panner.orientationY.value = 2000; | 121 panner.orientationY.value = 2000; |
118 panner.orientationZ.value = 8000; | 122 panner.orientationZ.value = 8000; |
119 }).then(context.resume.bind(context)); | 123 }).then(context.resume.bind(context)); |
120 | 124 |
121 context.startRendering().then(function (resultBuffer) { | 125 context.startRendering().then(function (resultBuffer) { |
122 verifyPannerOutputChanged(resultBuffer, {message: "panner.orientation{ XYZ}", suspendFrame: suspendFrame}); | 126 verifyPannerOutputChanged(should, resultBuffer, { |
hongchan
2017/05/02 16:46:31
Is this done by clang-format? Why is the indentati
Raymond Toy
2017/05/02 19:04:29
Reindented everything with clang-format.
| |
123 }).then(done); | 127 message: "panner.orientation{XYZ}", |
128 suspendFrame: suspendFrame | |
129 }); | |
130 }) | |
131 .then(() => task.done()); | |
124 }); | 132 }); |
125 | 133 |
126 audit.defineTask("forward setter", function (done) { | 134 audit.define("forward setter", (task, should) => { |
127 var {context, panner, source} = createGraph(2); | 135 var {context, panner, source} = createGraph(2); |
128 | 136 |
129 // For orientation to matter, we need to make the source directional, an d also move away | 137 // For orientation to matter, we need to make the source directional, an d also move away |
130 // from the listener (because the default location is 0,0,0). | 138 // from the listener (because the default location is 0,0,0). |
131 panner.setPosition(0,0,1); | 139 panner.setPosition(0,0,1); |
132 panner.coneInnerAngle = 0; | 140 panner.coneInnerAngle = 0; |
133 panner.coneOuterAngle = 360; | 141 panner.coneOuterAngle = 360; |
134 panner.coneOuterGain = .001; | 142 panner.coneOuterGain = .001; |
135 | 143 |
136 // After some (unimportant) time, change the panner orientation to a new orientation. The | 144 // After some (unimportant) time, change the panner orientation to a new orientation. The |
137 // only constraint is that the orientation changes from before. | 145 // only constraint is that the orientation changes from before. |
138 var suspendFrame = 128; | 146 var suspendFrame = 128; |
139 context.suspend(suspendFrame / sampleRate).then(function () { | 147 context.suspend(suspendFrame / sampleRate).then(function () { |
140 context.listener.forwardX.value = -100; | 148 context.listener.forwardX.value = -100; |
141 context.listener.forwardY.value = 2000; | 149 context.listener.forwardY.value = 2000; |
142 context.listener.forwardZ.value = 8000; | 150 context.listener.forwardZ.value = 8000; |
143 }).then(context.resume.bind(context)); | 151 }).then(context.resume.bind(context)); |
144 | 152 |
145 context.startRendering().then(function (resultBuffer) { | 153 context.startRendering().then(function (resultBuffer) { |
146 verifyPannerOutputChanged(resultBuffer, {message: "listener.forward{XY Z}", suspendFrame: suspendFrame}); | 154 verifyPannerOutputChanged(should, resultBuffer, { |
147 }).then(done); | 155 message: "listener.forward{XYZ}", |
156 suspendFrame: suspendFrame | |
157 }); | |
158 }) | |
159 .then(() => task.done()); | |
148 }); | 160 }); |
149 | 161 |
150 audit.defineTask("up setter", function (done) { | 162 audit.define("up setter", (task, should) => { |
151 var {context, panner, source} = createGraph(2); | 163 var {context, panner, source} = createGraph(2); |
152 | 164 |
153 // For orientation to matter, we need to make the source directional, an d also move away | 165 // For orientation to matter, we need to make the source directional, an d also move away |
154 // from the listener (because the default location is 0,0,0). | 166 // from the listener (because the default location is 0,0,0). |
155 panner.setPosition(0,0,1); | 167 panner.setPosition(0,0,1); |
156 panner.coneInnerAngle = 0; | 168 panner.coneInnerAngle = 0; |
157 panner.coneOuterAngle = 360; | 169 panner.coneOuterAngle = 360; |
158 panner.coneOuterGain = .001; | 170 panner.coneOuterGain = .001; |
159 panner.setPosition(1,0,1); | 171 panner.setPosition(1,0,1); |
160 | 172 |
161 // After some (unimportant) time, change the panner orientation to a new orientation. The | 173 // After some (unimportant) time, change the panner orientation to a new orientation. The |
162 // only constraint is that the orientation changes from before. | 174 // only constraint is that the orientation changes from before. |
163 var suspendFrame = 128; | 175 var suspendFrame = 128; |
164 context.suspend(suspendFrame / sampleRate).then(function () { | 176 context.suspend(suspendFrame / sampleRate).then(function () { |
165 context.listener.upX.value = 100; | 177 context.listener.upX.value = 100; |
166 context.listener.upY.value = 100; | 178 context.listener.upY.value = 100; |
167 context.listener.upZ.value = 100;; | 179 context.listener.upZ.value = 100;; |
168 }).then(context.resume.bind(context)); | 180 }).then(context.resume.bind(context)); |
169 | 181 |
170 context.startRendering().then(function (resultBuffer) { | 182 context.startRendering().then(function (resultBuffer) { |
171 verifyPannerOutputChanged(resultBuffer, {message: "listener.up{XYZ}", suspendFrame: suspendFrame}); | 183 verifyPannerOutputChanged(should, resultBuffer, { |
172 }).then(done); | 184 message: "listener.up{XYZ}", |
185 suspendFrame: suspendFrame | |
186 }); | |
187 }) | |
188 .then(() => task.done()); | |
173 }); | 189 }); |
174 | 190 |
175 audit.runTasks(); | 191 audit.run(); |
176 | 192 |
177 function createGraph(channelCount) { | 193 function createGraph(channelCount) { |
178 var context = new OfflineAudioContext(2, renderFrames, sampleRate); | 194 var context = new OfflineAudioContext(2, renderFrames, sampleRate); |
179 var panner = context.createPanner(); | 195 var panner = context.createPanner(); |
180 var source = context.createBufferSource(); | 196 var source = context.createBufferSource(); |
181 source.buffer = createConstantBuffer(context, 1, channelCount == 1 ? 1 : [1, 2]); | 197 source.buffer = createConstantBuffer(context, 1, channelCount == 1 ? 1 : [1, 2]); |
182 source.loop = true; | 198 source.loop = true; |
183 | 199 |
184 source.connect(panner); | 200 source.connect(panner); |
185 panner.connect(context.destination); | 201 panner.connect(context.destination); |
186 | 202 |
187 source.start(); | 203 source.start(); |
188 return { | 204 return { |
189 context: context, | 205 context: context, |
190 source: source, | 206 source: source, |
191 panner: panner | 207 panner: panner |
192 }; | 208 }; |
193 } | 209 } |
194 | 210 |
195 function testPositionSetter(options) { | 211 function testPositionSetter(should, options) { |
196 var {nodes, pannerSetter, message} = options; | 212 var {nodes, pannerSetter, message} = options; |
197 | 213 |
198 var {context, source, panner} = nodes; | 214 var {context, source, panner} = nodes; |
199 | 215 |
200 // Set panner x position. (Value doesn't matter); | 216 // Set panner x position. (Value doesn't matter); |
201 pannerSetter.value = 1; | 217 pannerSetter.value = 1; |
202 | 218 |
203 // Wait a bit and set a new position. (Actual time and position doesn't matter). | 219 // Wait a bit and set a new position. (Actual time and position doesn't matter). |
204 var suspendFrame = 128; | 220 var suspendFrame = 128; |
205 context.suspend(suspendFrame / sampleRate).then(function () { | 221 context.suspend(suspendFrame / sampleRate).then(function () { |
206 pannerSetter.value = 10000; | 222 pannerSetter.value = 10000; |
207 }).then(context.resume.bind(context)); | 223 }).then(context.resume.bind(context)); |
208 | 224 |
209 return context.startRendering().then(function (resultBuffer) { | 225 return context.startRendering().then(function (resultBuffer) { |
210 verifyPannerOutputChanged(resultBuffer, {message: message, suspendFram e: suspendFrame}); | 226 verifyPannerOutputChanged(should, resultBuffer, { |
227 message: message, | |
228 suspendFrame: suspendFrame | |
229 }); | |
211 }); | 230 }); |
212 } | 231 } |
213 | 232 |
214 function verifyPannerOutputChanged(resultBuffer, options) { | 233 function verifyPannerOutputChanged(should, resultBuffer, options) { |
215 var {message, suspendFrame} = options; | 234 var {message, suspendFrame} = options; |
216 // Verify that the first part of output is constant. (Doesn't matter w hat.) | 235 // Verify that the first part of output is constant. (Doesn't matter w hat.) |
217 var success = true; | 236 var success = true; |
218 var data0 = resultBuffer.getChannelData(0); | 237 var data0 = resultBuffer.getChannelData(0); |
219 var data1 = resultBuffer.getChannelData(1); | 238 var data1 = resultBuffer.getChannelData(1); |
220 | 239 |
221 var middle = "[0, " + suspendFrame + ") "; | 240 var middle = "[0, " + suspendFrame + ") "; |
222 success = Should(message + ".value frame " + middle + "channel 0", dat a0.slice(0, suspendFrame)) | 241 should(data0.slice(0, suspendFrame), |
hongchan
2017/05/02 16:46:30
Please revise the indentation of this area.
| |
223 .beConstantValueOf(data0[0]) && success; | 242 message + ".value frame " + middle + "channel 0") |
224 success = Should(message + ".value frame " + middle + "channel 1", dat a1.slice(0, suspendFrame)) | 243 .beConstantValueOf(data0[0]); |
225 .beConstantValueOf(data1[0]) && success; | 244 should(data1.slice(0, suspendFrame), |
245 message + ".value frame " + middle + "channel 1") | |
246 .beConstantValueOf(data1[0]); | |
226 | 247 |
227 // The rest after suspendTime should be constant and different from th e first part. | 248 // The rest after suspendTime should be constant and different from th e first part. |
228 middle = "[" + suspendFrame + ", " + renderFrames + ") "; | 249 middle = "[" + suspendFrame + ", " + renderFrames + ") "; |
229 success = Should(message + ".value frame " + middle + "channel 0", | 250 should(data0.slice(suspendFrame), |
hongchan
2017/05/02 16:46:31
Ditto.
| |
230 data0.slice(suspendFrame)) | 251 message + ".value frame " + middle + "channel 0") |
231 .beConstantValueOf(data0[suspendFrame]) && success; | 252 .beConstantValueOf(data0[suspendFrame]); |
232 success = Should(message + ".value frame " + middle + "channel 1", | 253 should(data1.slice(suspendFrame), |
233 data1.slice(suspendFrame)) | 254 message + ".value frame " + middle + "channel 1") |
234 .beConstantValueOf(data1[suspendFrame]) && success; | 255 .beConstantValueOf(data1[suspendFrame]); |
235 success = Should(message + ": Output at frame " + suspendFrame + " cha nnel 0", data0[suspendFrame]) | 256 should(data0[suspendFrame], |
236 .notBeEqualTo(data0[0]) && success; | 257 message + ": Output at frame " + suspendFrame + " channel 0") |
237 success = Should(message + ": Output at frame " + suspendFrame + " cha nnel 1", data1[suspendFrame]) | 258 .notBeEqualTo(data0[0]); |
238 .notBeEqualTo(data1[0]) && success; | 259 should(data1[suspendFrame], |
260 message + ": Output at frame " + suspendFrame + " channel 1") | |
261 .notBeEqualTo(data1[0]); | |
239 | 262 |
240 var prefix = "Directly setting " + message + ".value"; | |
241 Should(prefix, success) | |
242 .summarize("worked", "failed"); | |
243 } | 263 } |
244 </script> | 264 </script> |
245 </body> | 265 </body> |
246 </html> | 266 </html> |
OLD | NEW |