Index: third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js |
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js b/third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js |
index 112d75acb7f4902b3b8209b9b1ccbaaa156782d6..277756c985e0ba89afc31b5a00b6d669c0394ca2 100644 |
--- a/third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js |
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js |
@@ -273,3 +273,21 @@ function grainLengthInSampleFrames(grainOffset, duration, sampleRate) { |
function isValidNumber(x) { |
return !isNaN(x) && (x != Infinity) && (x != -Infinity); |
} |
+ |
+// Compute the (linear) signal-to-noise ratio between |actual| and |
+// |expected|. The result is NOT in dB! If the |actual| and |
+// |expected| have different lengths, the shorter length is used. |
+function computeSNR(actual, expected) { |
+ var signalPower = 0; |
+ var noisePower = 0; |
+ |
+ var length = Math.min(actual.length, expected.length); |
+ |
+ for (var k = 0; k < length; ++k) { |
+ var diff = actual[k] - expected[k]; |
+ signalPower += expected[k] * expected[k]; |
+ noisePower += diff * diff; |
+ } |
+ |
+ return signalPower / noisePower; |
+} |