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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js

Issue 2783553002: Convert AudioBufferSource tests to new Audit (Closed)
Patch Set: Indent neatly. Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiosource-time-limits.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 /** 6 /**
7 * @fileOverview This file includes legacy utility functions for the layout 7 * @fileOverview This file includes legacy utility functions for the layout
8 * test. 8 * test.
9 */ 9 */
10 10
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // Compare two arrays (commonly extracted from buffer.getChannelData()) with 165 // Compare two arrays (commonly extracted from buffer.getChannelData()) with
166 // constraints: 166 // constraints:
167 // options.thresholdSNR: Minimum allowed SNR between the actual and expected 167 // options.thresholdSNR: Minimum allowed SNR between the actual and expected
168 // signal. The default value is 10000. 168 // signal. The default value is 10000.
169 // options.thresholdDiffULP: Maximum allowed difference between the actual 169 // options.thresholdDiffULP: Maximum allowed difference between the actual
170 // and expected signal in ULP(Unit in the last place). The default is 0. 170 // and expected signal in ULP(Unit in the last place). The default is 0.
171 // options.thresholdDiffCount: Maximum allowed number of sample differences 171 // options.thresholdDiffCount: Maximum allowed number of sample differences
172 // which exceeds the threshold. The default is 0. 172 // which exceeds the threshold. The default is 0.
173 // options.bitDepth: The expected result is assumed to come from an audio 173 // options.bitDepth: The expected result is assumed to come from an audio
174 // file with this number of bits of precision. The default is 16. 174 // file with this number of bits of precision. The default is 16.
175 function compareBuffersWithConstraints(actual, expected, options) { 175 function compareBuffersWithConstraints(should, actual, expected, options) {
176 if (!options) 176 if (!options)
177 options = {}; 177 options = {};
178 178
179 if (actual.length !== expected.length) 179 // Only print out the message if the lengths are different; the
180 testFailed('Buffer length mismatches.'); 180 // expectation is that they are the same, so don't clutter up the
181 // output.
182 if (actual.length !== expected.length) {
183 should(actual.length === expected.length,
184 "Length of actual and expected buffers should match")
185 .beTrue();
186 }
181 187
182 var maxError = -1; 188 var maxError = -1;
183 var diffCount = 0; 189 var diffCount = 0;
184 var errorPosition = -1; 190 var errorPosition = -1;
185 var thresholdSNR = (options.thresholdSNR || 10000); 191 var thresholdSNR = (options.thresholdSNR || 10000);
186 192
187 var thresholdDiffULP = (options.thresholdDiffULP || 0); 193 var thresholdDiffULP = (options.thresholdDiffULP || 0);
188 var thresholdDiffCount = (options.thresholdDiffCount || 0); 194 var thresholdDiffCount = (options.thresholdDiffCount || 0);
189 195
190 // By default, the bit depth is 16. 196 // By default, the bit depth is 16.
(...skipping 14 matching lines...) Expand all
205 211
206 // The reference file is a 16-bit WAV file, so we will almost never get 212 // The reference file is a 16-bit WAV file, so we will almost never get
207 // an exact match between it and the actual floating-point result. 213 // an exact match between it and the actual floating-point result.
208 if (Math.abs(diff) > scaleFactor) 214 if (Math.abs(diff) > scaleFactor)
209 diffCount++; 215 diffCount++;
210 } 216 }
211 217
212 var snr = 10 * Math.log10(signalPower / noisePower); 218 var snr = 10 * Math.log10(signalPower / noisePower);
213 var maxErrorULP = maxError * scaleFactor; 219 var maxErrorULP = maxError * scaleFactor;
214 220
215 Should("SNR", snr).beGreaterThanOrEqualTo(thresholdSNR); 221 should(snr, "SNR").beGreaterThanOrEqualTo(thresholdSNR);
216 222
217 Should(options.prefix + ': Maximum difference (in ulp units (' + bitDepth + '-bits))', 223 should(maxErrorULP,
218 maxErrorULP).beLessThanOrEqualTo(thresholdDiffULP); 224 options.prefix + ': Maximum difference (in ulp units (' + bitDepth +
225 '-bits))'
226 ).beLessThanOrEqualTo(thresholdDiffULP);
219 227
220 Should(options.prefix + ': Number of differences between results', diffCount ) 228 should(diffCount, options.prefix +
221 .beLessThanOrEqualTo(thresholdDiffCount); 229 ': Number of differences between results').beLessThanOrEqualTo(
230 thresholdDiffCount);
222 } 231 }
223 232
224 // Create an impulse in a buffer of length sampleFrameLength 233 // Create an impulse in a buffer of length sampleFrameLength
225 function createImpulseBuffer(context, sampleFrameLength) { 234 function createImpulseBuffer(context, sampleFrameLength) {
226 var audioBuffer = context.createBuffer(1, sampleFrameLength, context.sampleR ate); 235 var audioBuffer = context.createBuffer(1, sampleFrameLength, context.sampleR ate);
227 var n = audioBuffer.length; 236 var n = audioBuffer.length;
228 var dataL = audioBuffer.getChannelData(0); 237 var dataL = audioBuffer.getChannelData(0);
229 238
230 for (var k = 0; k < n; ++k) { 239 for (var k = 0; k < n; ++k) {
231 dataL[k] = 0; 240 dataL[k] = 0;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 var length = Math.min(actual.length, expected.length); 330 var length = Math.min(actual.length, expected.length);
322 331
323 for (var k = 0; k < length; ++k) { 332 for (var k = 0; k < length; ++k) {
324 var diff = actual[k] - expected[k]; 333 var diff = actual[k] - expected[k];
325 signalPower += expected[k] * expected[k]; 334 signalPower += expected[k] * expected[k];
326 noisePower += diff * diff; 335 noisePower += diff * diff;
327 } 336 }
328 337
329 return signalPower / noisePower; 338 return signalPower / noisePower;
330 } 339 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiosource-time-limits.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698