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

Side by Side Diff: LayoutTests/webaudio/stereopannernode-panning.html

Issue 691143007: Implement StereoPannerNode for robust stereo panning (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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
4 <head>
5 <script src="resources/compatibility.js"></script>
6 <script src="resources/audio-testing.js"></script>
7 <script src="../resources/js-test.js"></script>
8 </head>
9
10 <body>
11 <div id="description"></div>
12 <div id="console"></div>
13 <script>
14 description("Test panning model of StereoPannerNode.");
15
16 if (window.testRunner) {
17 testRunner.dumpAsText();
18 testRunner.waitUntilDone();
19 }
Raymond Toy 2014/11/11 19:41:46 Don't think the if is needed anymore.
hongchan 2014/11/12 00:06:53 Done.
20
21 window.jsTestIsAsync = true;
22
23 var sampleRate = 44100;
24
25 // Number of nodes to create for testing.
26 var nodesToCreate = 100;
27
28 // Interval between the onset of each impulse.
29 var timeStep = 0.001;
30
31 // Total render length. Should be long enough for all panner nodes.
32 var renderLength = timeStep * (nodesToCreate + 1);
33
34 var impulse,
35 impulseLength = Math.round(timeStep * sampleRate);
Raymond Toy 2014/11/11 19:41:46 This style is not generally allowed in blink or ch
hongchan 2014/11/12 00:06:53 I looked it up Google's JS style guide, but it doe
Raymond Toy 2014/11/12 00:16:44 Up to you. Chris always had me follow chromium (o
36
37 // Pan step unit for each test trial.
38 var panStep = 2 / (nodesToCreate - 1);
39
40 var sources = [],
41 panners = [],
42 panPositions = [],
43 onsets = [];
44
45 var ctx = new OfflineAudioContext(2, sampleRate * renderLength, sampleRate);
46
47 // Calculates channel gains based on equal power panning model.
48 function getChannelGains (pan) {
49 var normalized = 0.5 * Math.PI * (pan * 0.5 + 0.5);
50 return {
51 gainL: Math.cos(normalized),
52 gainR: Math.sin(normalized)
53 };
54 }
55
56 function prepareTest() {
57 impulse = createImpulseBuffer(ctx, impulseLength);
58
Raymond Toy 2014/11/11 19:41:46 Describe what you're connecting together here and
hongchan 2014/11/12 00:06:53 I will describe what I am doing here. But I think
Raymond Toy 2014/11/12 00:16:44 Acknowledged.
59 for (var i = 0; i < nodesToCreate; i++) {
60 sources[i] = ctx.createBufferSource();
61 panners[i] = ctx.createStereoPanner();
62 sources[i].connect(panners[i]);
63 panners[i].connect(ctx.destination);
64
65 sources[i].buffer = impulse;
66
67 // Moves the pan value for each panner by pan step unit.
68 panners[i].pan.value = panPositions[i] = panStep * i - 1;
69
70 onsets[i] = timeStep * i;
71 sources[i].start(onsets[i]);
72 }
73 }
74
75 function verifyResult(event) {
76
77 var success = true;
78
79 // The max error we allow between the rendered impulse and the
80 // expected value. This value is experimentally determined. Set
81 // to 0 to make the test fail to see what the actual error is.
82 var maxAllowedError = 1.3e-6;
83
84 var chanL = event.renderedBuffer.getChannelData(0),
85 chanR = event.renderedBuffer.getChannelData(1);
86
87 // Number of impulses found in the rendered result.
88 var impulseIndex = 0;
89
90 // Max (relative) error and the index of the maxima for the left
91 // and right channels.
92 var maxErrorL = 0,
93 maxErrorR = 0,
94 maxErrorIndexL = 0,
95 maxErrorIndexR = 0;
96
97 // Locations of where the impulses aren't at the expected locations.
98 var errors = [];
99
100 for (var i = 0; i < chanL.length; i++) {
101
102 // We assume that the left and right channels start at the same instant.
103 if (chanL[i] !== 0 || chanR[i] !== 0) {
104
105 // Get amount of error between actual and expected gain.
106 var expected = getChannelGains(panPositions[impulseIndex]),
107 errorL = Math.abs(chanL[i] - expected.gainL),
108 errorR = Math.abs(chanR[i] - expected.gainR);
109
110 if (errorL > maxErrorL) {
111 maxErrorL = errorL;
112 maxErrorIndexL = impulseIndex;
113 }
114
115 if (errorR > maxErrorR) {
116 maxErrorR = errorR;
117 maxErrorIndexR = impulseIndex;
118 }
119
120 // Keep track of the impulses that didn't show up where we expected
121 // them to be.
122 var expectedOffset = timeToSampleFrame(onsets[impulseIndex], sampleRat e);
123 if (i != expectedOffset) {
124 errors.push({
125 actual: i,
126 expected: expectedOffset
127 });
128 }
129
130 impulseIndex++;
131 }
132 }
133
134 if (impulseIndex === nodesToCreate) {
135 testPassed('Number of impulses matches the number of panner nodes.');
136 } else {
137 testFailed('Number of impulses is incorrect. (Found ' + impulseIndex + ' but expected ' + nodesToCreate + ')');
138 sucess = false;
139 }
140
141 if (errors.length === 0) {
142 testPassed("All impulses at expected offsets.");
143 } else {
144 testFailed(errors.length + " timing errors found in " + nodesToCreate + " panner nodes.");
145 for (var i = 0; i < errors.length; i++) {
146 testFailed("Impulse at sample " + errors[i].actual + " but expected " + errors[i].expected);
147 }
148 success = false;
149 }
150
151 if (maxErrorL <= maxAllowedError) {
152 testPassed("Left channel gain values are correct.");
153 } else {
154 testFailed("Left channel gain values are incorrect. Max error = " + max ErrorL + " at time " + onsets[maxErrorIndexL] + " (threshold = " + maxAllowedErr or + ")");
155 success = false;
156 }
157
158 if (maxErrorR <= maxAllowedError) {
159 testPassed("Right channel gain values are correct.");
160 } else {
161 testFailed("Right channel gain values are incorrect. Max error = " + ma xErrorR + " at time " + onsets[maxErrorIndexR] + " (threshold = " + maxAllowedEr ror + ")");
162 success = false;
163 }
164
165 if (success) {
166 testPassed("EqualPower panner test passed");
167 } else {
168 testFailed("EqualPower panner test failed");
169 }
Raymond Toy 2014/11/11 19:41:46 Chromium and blink style does not use braces for s
hongchan 2014/11/12 00:06:53 I just copied this part from the previous panner t
Raymond Toy 2014/11/12 00:16:44 Actually, the blink style guide says this is ok in
170
171 finishJSTest();
172 }
173
174 prepareTest();
175 ctx.oncomplete = verifyResult;
176 ctx.startRendering();
177
178 successfullyParsed = true;
179 </script>
180 </body>
181
182 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698