Index: third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js |
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js b/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js |
index 41c7edc8574878019c26a4d3871c33de8c1b330c..7f1b0ac4af61df3e1376a74607b733b8220fed04 100644 |
--- a/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js |
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js |
@@ -169,6 +169,24 @@ |
})(); |
+ |
+// 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; |
+} |
// |Should| JS layout test utility. |
// Dependency: ../resources/js-test.js |