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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/panner-automation-basic.html

Issue 1820403002: Implement Automations for PannerNode and AutioListener (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <script src="../resources/js-test.js"></script>
5 <script src="resources/compatibility.js"></script>
6 <script src="resources/audio-testing.js"></script>
7 <script src="resources/panner-formulas.js"></script>
8 <title>Test Basic Panner Position Properties</title>
9 </head>
10
11 <body>
12 <script>
13 description("Test Basic SpatialPannerNode Properties.");
14 window.jsTestIsAsync = true;
15
16 var sampleRate = 48000;
17
18 // These tests are quite slow, so don't run for many frames. 256 frames s hould be enough to
19 // demonstrate that automations are working.
20 var renderFrames = 256;
21 var renderDuration = renderFrames / sampleRate;
22
23 var audit = Audit.createTaskRunner();
24
25 audit.defineTask("panner position x-setter", function (done) {
26 var nodes = createGraph();
27 var {context, source, panner} = nodes;
28
29 testPositionSetter({
30 nodes: nodes,
31 pannerSetter: panner.positionX,
32 message: "panner.positionX"
33 }).then(done);
34 });
35
36 audit.defineTask("panner position y-setter", function (done) {
37 var nodes = createGraph();
38 var {context, source, panner} = nodes;
39
40 testPositionSetter({
41 nodes: nodes,
42 pannerSetter: panner.positionY,
43 message: "panner.positionY"
44 }).then(done);
45 });
46
47 audit.defineTask("panner position z-setter", function (done) {
48 var nodes = createGraph();
49 var {context, source, panner} = nodes;
50
51 testPositionSetter({
52 nodes: nodes,
53 pannerSetter: panner.positionZ,
54 message: "panner.positionZ"
55 }).then(done);
56 });
57
58 // This test currently fails because of the dezippering of the distance an d cone gain that
59 // happens when setPosition is used.
60 audit.defineTask("setPosition", function (done) {
61 var {context, panner, source} = createGraph();
62
63 // Initialize source position (values don't really matter).
64 panner.setPosition(1,1,1);
65
66 // After some (unimportant) time, move the panner to a (any) new locatio n.
67 var suspendFrame = 128;
68 context.suspend(suspendFrame / sampleRate).then(function () {
69 panner.setPosition(-100, 2000, 8000);
70 }).then(context.resume.bind(context));
71
72 context.startRendering().then(function (resultBuffer) {
73 verifyPannerOutputChanged(resultBuffer, {message: "setPosition", suspe ndFrame: suspendFrame});
74 }).then(done);
75 });
76
77 audit.defineTask("orientation setter", function (done) {
78 var {context, panner, source} = createGraph();
79
80 // For orientation to matter, we need to make the source directional, an d also move away
81 // from the listener (because the default location is 0,0,0).
82 panner.setPosition(0,0,1);
83 panner.coneInnerAngle = 0;
84 panner.coneOuterAngle = 360;
85 panner.coneOuterGain = .001;
86
87 // After some (unimportant) time, change the panner orientation to a new orientation. The
88 // only constraint is that the orientation changes from before.
89 var suspendFrame = 128;
90 context.suspend(suspendFrame / sampleRate).then(function () {
91 panner.orientationX.value = -100;
92 panner.orientationY.value = 2000;
93 panner.orientationZ.value = 8000;
94 }).then(context.resume.bind(context));
95
96 context.startRendering().then(function (resultBuffer) {
97 verifyPannerOutputChanged(resultBuffer, {message: "panner.orientation{ XYZ}", suspendFrame: suspendFrame});
98 }).then(done);
99 });
100
101
102 audit.defineTask("listener x-setter", function (done) {
103 var nodes = createGraph();
104 var {context, source, panner} = nodes;
105
106 panner.setPosition(1,0,1);
107 testPositionSetter({
108 nodes: nodes,
109 pannerSetter: context.listener.positionX,
110 message: "listener.positionX"
111 }).then(done);
112 });
113
114 audit.defineTask("listener y-setter", function (done) {
115 var nodes = createGraph();
116 var {context, source, panner} = nodes;
117
118 panner.setPosition(1,0,1);
119 //panner.setOrientation(0, 0, -1);
120 testPositionSetter({
121 nodes: nodes,
122 pannerSetter: context.listener.positionY,
123 message: "listener.positionY"
124 }).then(done);
125 });
126
127 audit.defineTask("listener z-setter", function (done) {
128 var nodes = createGraph();
129 var {context, source, panner} = nodes;
130
131 panner.setPosition(1,0,1);
132 //panner.setOrientation(0, 0, -1);
133 testPositionSetter({
134 nodes: nodes,
135 pannerSetter: context.listener.positionZ,
136 message: "listener.positionZ"
137 }).then(done);
138 });
139
140 audit.defineTask("forward setter", function (done) {
141 var {context, panner, source} = createGraph();
142
143 // For orientation to matter, we need to make the source directional, an d also move away
144 // from the listener (because the default location is 0,0,0).
145 panner.setPosition(0,0,1);
146 panner.coneInnerAngle = 0;
147 panner.coneOuterAngle = 360;
148 panner.coneOuterGain = .001;
149
150 // After some (unimportant) time, change the panner orientation to a new orientation. The
151 // only constraint is that the orientation changes from before.
152 var suspendFrame = 128;
153 context.suspend(suspendFrame / sampleRate).then(function () {
154 context.listener.forwardX.value = -100;
155 context.listener.forwardY.value = 2000;
156 context.listener.forwardZ.value = 8000;
157 }).then(context.resume.bind(context));
158
159 context.startRendering().then(function (resultBuffer) {
160 verifyPannerOutputChanged(resultBuffer, {message: "listener.forward{XY Z}", suspendFrame: suspendFrame});
161 }).then(done);
162 });
163
164 audit.defineTask("up setter", function (done) {
165 var {context, panner, source} = createGraph();
166
167 // For orientation to matter, we need to make the source directional, an d also move away
168 // from the listener (because the default location is 0,0,0).
169 panner.setPosition(0,0,1);
170 panner.coneInnerAngle = 0;
171 panner.coneOuterAngle = 360;
172 panner.coneOuterGain = .001;
173 panner.setPosition(1,0,1);
174
175 // After some (unimportant) time, change the panner orientation to a new orientation. The
176 // only constraint is that the orientation changes from before.
177 var suspendFrame = 128;
178 context.suspend(suspendFrame / sampleRate).then(function () {
179 context.listener.upX.value = 100;
180 context.listener.upY.value = 100;
181 context.listener.upZ.value = 100;;
182 }).then(context.resume.bind(context));
183
184 context.startRendering().then(function (resultBuffer) {
185 verifyPannerOutputChanged(resultBuffer, {message: "listener.up{XYZ}", suspendFrame: suspendFrame});
186 }).then(done);
187 });
188
189 audit.defineTask("finish", function (done) {
190 finishJSTest();
191 done();
192 });
193
194 audit.runTasks();
195
196 function createGraph() {
197 var context = new OfflineAudioContext(2, renderFrames, sampleRate);
198 var panner = context.createPanner();
199 var source = context.createBufferSource();
200 source.buffer = createConstantBuffer(context, 1, 1);
201 source.loop = true;
202
203 source.connect(panner);
204 panner.connect(context.destination);
205
206 source.start();
207 return { context: context,
208 source: source,
209 panner: panner
210 };
211 }
212
213 function testPositionSetter(options) {
214 var {nodes, pannerSetter, message} = options;
215
216 var {context, source, panner} = nodes;
217
218 // Set panner x position. (Value doesn't matter);
219 pannerSetter.value = 1;
220
221 // Wait a bit and set a new position. (Actual time and position doesn't matter).
222 var suspendFrame = 128;
223 context.suspend(suspendFrame / sampleRate).then(function () {
224 pannerSetter.value = 10000;
225 }).then(context.resume.bind(context));
226
227 return context.startRendering().then(function (resultBuffer) {
228 verifyPannerOutputChanged(resultBuffer, {message: message, suspendFram e: suspendFrame});
229 });
230 }
231
232 function verifyPannerOutputChanged(resultBuffer, options) {
233 var {message, suspendFrame} = options;
234 // Verify that the first part of output is constant. (Doesn't matter w hat.)
235 var success = true;
236 var data0 = resultBuffer.getChannelData(0);
237 var data1 = resultBuffer.getChannelData(1);
238
239 success = Should(message + ".value at frame 0 channel 0", data0.slice( 0, suspendFrame))
240 .beConstantValueOf(data0[0]) && success;
241 success = Should(message + ".value at frame 0 channel 1", data1.slice( 0, suspendFrame))
242 .beConstantValueOf(data1[0]) && success;
243
244 // The rest after suspendTime should be constant and different from th e first part.
245 success = Should(message + ".value at frame " + suspendFrame + " chann el 0",
246 data0.slice(suspendFrame))
247 .beConstantValueOf(data0[suspendFrame]) && success;
248 success = Should(message + ".value at frame " + suspendFrame + " chann el 0",
249 data1.slice(suspendFrame))
250 .beConstantValueOf(data1[suspendFrame]) && success;
251 success = Should("Output at frame " + suspendFrame + " channel 0", dat a0[0])
252 .notBeEqualTo(data0[suspendFrame]) && success;
253 success = Should("Output at frame " + suspendFrame + " channel 1", dat a1[0])
254 .notBeEqualTo(data1[suspendFrame]) && success;
255
256 var prefix = "Directly setting " + message + ".value";
257 if (success)
258 testPassed(prefix + " worked.\n");
259 else
260 testFailed(prefix + " failed.\n");
261 }
262 </script>
263 </body>
264 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698