| OLD | NEW |
| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 var startFrame = timeToSampleFrame(grainOffset, sampleRate); | 250 var startFrame = timeToSampleFrame(grainOffset, sampleRate); |
| 251 var endFrame = timeToSampleFrame(grainOffset + duration, sampleRate); | 251 var endFrame = timeToSampleFrame(grainOffset + duration, sampleRate); |
| 252 | 252 |
| 253 return endFrame - startFrame; | 253 return endFrame - startFrame; |
| 254 } | 254 } |
| 255 | 255 |
| 256 // True if the number is not an infinity or NaN | 256 // True if the number is not an infinity or NaN |
| 257 function isValidNumber(x) { | 257 function isValidNumber(x) { |
| 258 return !isNaN(x) && (x != Infinity) && (x != -Infinity); | 258 return !isNaN(x) && (x != Infinity) && (x != -Infinity); |
| 259 } | 259 } |
| 260 |
| 261 // Compute the (linear) signal-to-noise ratio between |actual| and |
| 262 // |expected|. The result is NOT in dB! If the |actual| and |
| 263 // |expected| have different lengths, the shorter length is used. |
| 264 function computeSNR(actual, expected) { |
| 265 var signalPower = 0; |
| 266 var noisePower = 0; |
| 267 |
| 268 var length = Math.min(actual.length, expected.length); |
| 269 |
| 270 for (var k = 0; k < length; ++k) { |
| 271 var diff = actual[k] - expected[k]; |
| 272 signalPower += expected[k] * expected[k]; |
| 273 noisePower += diff * diff; |
| 274 } |
| 275 |
| 276 return signalPower / noisePower; |
| 277 } |
| OLD | NEW |