| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 var startFrame = timeToSampleFrame(grainOffset, sampleRate); | 266 var startFrame = timeToSampleFrame(grainOffset, sampleRate); |
| 267 var endFrame = timeToSampleFrame(grainOffset + duration, sampleRate); | 267 var endFrame = timeToSampleFrame(grainOffset + duration, sampleRate); |
| 268 | 268 |
| 269 return endFrame - startFrame; | 269 return endFrame - startFrame; |
| 270 } | 270 } |
| 271 | 271 |
| 272 // True if the number is not an infinity or NaN | 272 // True if the number is not an infinity or NaN |
| 273 function isValidNumber(x) { | 273 function isValidNumber(x) { |
| 274 return !isNaN(x) && (x != Infinity) && (x != -Infinity); | 274 return !isNaN(x) && (x != Infinity) && (x != -Infinity); |
| 275 } | 275 } |
| 276 | |
| 277 // Compute the (linear) signal-to-noise ratio between |actual| and | |
| 278 // |expected|. The result is NOT in dB! If the |actual| and | |
| 279 // |expected| have different lengths, the shorter length is used. | |
| 280 function computeSNR(actual, expected) { | |
| 281 var signalPower = 0; | |
| 282 var noisePower = 0; | |
| 283 | |
| 284 var length = Math.min(actual.length, expected.length); | |
| 285 | |
| 286 for (var k = 0; k < length; ++k) { | |
| 287 var diff = actual[k] - expected[k]; | |
| 288 signalPower += expected[k] * expected[k]; | |
| 289 noisePower += diff * diff; | |
| 290 } | |
| 291 | |
| 292 return signalPower / noisePower; | |
| 293 } | |
| OLD | NEW |