Bug 1265405 - Add test case for PeriodicWave normalization; r=padenot
authorDan Minor <dminor@mozilla.com>
Fri, 22 Apr 2016 09:47:07 -0400
changeset 334177 632811bf4b6e96b54709d125c298493d30576eb8
parent 334176 94189d37e581d108bf89064ded062831669a7be6
child 334178 a6e3503205e87001cfb0b53b457bdaa595fd9521
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1265405
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1265405 - Add test case for PeriodicWave normalization; r=padenot MozReview-Commit-ID: B85kaip1xQT
dom/media/webaudio/test/mochitest.ini
dom/media/webaudio/test/test_periodicWaveDisableNormalization.html
--- a/dom/media/webaudio/test/mochitest.ini
+++ b/dom/media/webaudio/test/mochitest.ini
@@ -166,16 +166,17 @@ skip-if = (toolkit == 'gonk' && !debug) 
 [test_pannerNodeAbove.html]
 [test_pannerNodeChannelCount.html]
 [test_pannerNodeHRTFSymmetry.html]
 [test_pannerNodeTail.html]
 [test_pannerNode_maxDistance.html]
 [test_stereoPannerNode.html]
 [test_stereoPannerNodePassThrough.html]
 [test_periodicWave.html]
+[test_periodicWaveDisableNormalization.html]
 [test_periodicWaveBandLimiting.html]
 [test_ScriptProcessorCollected1.html]
 [test_scriptProcessorNode.html]
 [test_scriptProcessorNodeChannelCount.html]
 [test_scriptProcessorNodePassThrough.html]
 [test_scriptProcessorNode_playbackTime1.html]
 [test_scriptProcessorNodeZeroInputOutput.html]
 [test_scriptProcessorNodeNotConnected.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_periodicWaveDisableNormalization.html
@@ -0,0 +1,100 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test PeriodicWave disableNormalization Parameter</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="webaudio.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+// We create PerodicWave instances containing two tones and compare it to
+// buffers created directly in JavaScript by adding the two waves together.
+// Two of the PeriodicWaves are normalized, the other is not. This test is
+// a modification of test_periodicWave.html.
+//
+// These constants are borrowed from test_periodicWave.html and modified
+// so that the realPeak (which is the normalization factor) will be small
+// enough that the errors are within the bounds for the test.
+const realMax = 99;
+var real = new Float32Array(realMax + 1);
+real[1] = 2.0; // fundamental
+real[realMax] = 0.25;
+
+const realPeak = real[1] + real[realMax];
+const realFundamental = 19.0;
+
+const testLength = 4096;
+
+addLoadEvent(function() {
+  runTest();
+});
+
+var gTest = {
+  createGraph: function(context) {
+    var merger = context.createChannelMerger();
+
+    var osc0 = context.createOscillator();
+    var osc1 = context.createOscillator();
+    var osc2 = context.createOscillator();
+
+    osc0.setPeriodicWave(context.
+                         createPeriodicWave(real,
+                                            new Float32Array(real.length),
+                                            {disableNormalization: false}));
+    osc1.setPeriodicWave(context.
+                         createPeriodicWave(real,
+                                            new Float32Array(real.length)));
+    osc2.setPeriodicWave(context.
+                         createPeriodicWave(real,
+                                            new Float32Array(real.length),
+                                            {disableNormalization: true}));
+
+    osc0.frequency.value = realFundamental;
+    osc1.frequency.value = realFundamental;
+    osc2.frequency.value = realFundamental;
+
+    osc0.start();
+    osc1.start();
+    osc2.start();
+
+    osc0.connect(merger, 0, 0);
+    osc1.connect(merger, 0, 1);
+    osc2.connect(merger, 0, 2);
+
+    return merger;
+  },
+  createExpectedBuffers: function(context) {
+    var buffer = context.createBuffer(3, testLength, context.sampleRate);
+
+    for (var i = 0; i < buffer.length; ++i) {
+
+      buffer.getChannelData(0)[i] = 1.0 / realPeak *
+        (real[1] * Math.cos(2 * Math.PI * realFundamental * i /
+                            context.sampleRate) +
+         real[realMax] * Math.cos(2 * Math.PI * realMax * realFundamental * i /
+                            context.sampleRate));
+
+      buffer.getChannelData(1)[i] = buffer.getChannelData(0)[i];
+
+      // TODO: We need to scale by a factor of two to make the results work
+      //       out here. This seems suspicious, see Bug 1266737.
+      buffer.getChannelData(2)[i] = 2.0 *
+        (real[1] * Math.cos(2 * Math.PI * realFundamental * i /
+                            context.sampleRate) +
+         real[realMax] * Math.cos(2 * Math.PI * realMax * realFundamental * i /
+                            context.sampleRate));
+    }
+    return buffer;
+  },
+  'numberOfChannels': 3,
+};
+
+</script>
+</pre>
+</body>
+</html>