Bug 867876 - Add some tests for the AudioParam automation events; r=roc
☠☠ backed out by b9d7489b20fb ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 02 May 2013 01:13:27 -0400
changeset 141572 85ec6c94314741e467881241cc777c2205fbf83b
parent 141571 9351bfd9d8c5729f8dbc678c9babe8582d924de9
child 141573 57b73db8e65b2281c42f11b900c1fc1d21e4fe14
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs867876
milestone23.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 867876 - Add some tests for the AudioParam automation events; r=roc
content/media/webaudio/test/Makefile.in
content/media/webaudio/test/test_audioParamExponentialRamp.html
content/media/webaudio/test/test_audioParamLinearRamp.html
content/media/webaudio/test/webaudio.js
--- a/content/media/webaudio/test/Makefile.in
+++ b/content/media/webaudio/test/Makefile.in
@@ -21,16 +21,18 @@ MOCHITEST_FILES := \
   test_bug866737.html \
   test_bug867089.html \
   test_bug867174.html \
   test_analyserNode.html \
   test_AudioBuffer.html \
   test_AudioContext.html \
   test_AudioListener.html \
   test_AudioParam.html \
+  test_audioParamExponentialRamp.html \
+  test_audioParamLinearRamp.html \
   test_audioBufferSourceNode.html \
   test_audioBufferSourceNodeLazyLoopParam.html \
   test_audioBufferSourceNodeLoop.html \
   test_audioBufferSourceNodeLoopStartEnd.html \
   test_audioBufferSourceNodeLoopStartEndSame.html \
   test_audioBufferSourceNodeNullBuffer.html \
   test_badConnect.html \
   test_biquadFilterNode.html \
new file mode 100644
--- /dev/null
+++ b/content/media/webaudio/test/test_audioParamExponentialRamp.html
@@ -0,0 +1,63 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test AudioParam.exponentialRampToValue</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();
+addLoadEvent(function() {
+  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
+
+  var context = new AudioContext();
+
+  var V0 = 0.1;
+  var V1 = 0.9;
+  var T0 = 0;
+  var T1 = 2048 / context.sampleRate;
+
+  var sourceBuffer = context.createBuffer(1, 2048, context.sampleRate);
+  for (var i = 0; i < 2048; ++i) {
+    sourceBuffer.getChannelData(0)[i] = 1;
+  }
+  var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
+  for (var i = 0; i < 2048; ++i) {
+    var t = i / context.sampleRate;
+    expectedBuffer.getChannelData(0)[i] = V0 * Math.pow(V1 / V0, (t - T0) / (T1 - T0));
+  }
+
+  var destination = context.destination;
+
+  var source = context.createBufferSource();
+  source.buffer = sourceBuffer;
+
+  var gain = context.createGain();
+  gain.gain.setValueAtTime(V0, 0);
+  gain.gain.exponentialRampToValueAtTime(V1, 2048/context.sampleRate);
+
+  var sp = context.createScriptProcessor(2048, 1);
+  source.connect(gain);
+  gain.connect(sp);
+  sp.connect(destination);
+
+  source.start(0);
+  sp.onaudioprocess = function(e) {
+    is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
+    compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));
+
+    sp.onaudioprocess = null;
+
+    SpecialPowers.clearUserPref("media.webaudio.enabled");
+    SimpleTest.finish();
+  };
+});
+
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/content/media/webaudio/test/test_audioParamLinearRamp.html
@@ -0,0 +1,63 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test AudioParam.linearRampToValue</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();
+addLoadEvent(function() {
+  SpecialPowers.setBoolPref("media.webaudio.enabled", true);
+
+  var context = new AudioContext();
+
+  var V0 = 0.1;
+  var V1 = 0.9;
+  var T0 = 0;
+  var T1 = 2048 / context.sampleRate;
+
+  var sourceBuffer = context.createBuffer(1, 2048, context.sampleRate);
+  for (var i = 0; i < 2048; ++i) {
+    sourceBuffer.getChannelData(0)[i] = 1;
+  }
+  var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
+  for (var i = 0; i < 2048; ++i) {
+    var t = i / context.sampleRate;
+    expectedBuffer.getChannelData(0)[i] = V0 + (V1 - V0) * ((t - T0) / (T1 - T0));
+  }
+
+  var destination = context.destination;
+
+  var source = context.createBufferSource();
+  source.buffer = sourceBuffer;
+
+  var gain = context.createGain();
+  gain.gain.setValueAtTime(V0, 0);
+  gain.gain.linearRampToValueAtTime(V1, 2048/context.sampleRate);
+
+  var sp = context.createScriptProcessor(2048, 1);
+  source.connect(gain);
+  gain.connect(sp);
+  sp.connect(destination);
+
+  source.start(0);
+  sp.onaudioprocess = function(e) {
+    is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
+    compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));
+
+    sp.onaudioprocess = null;
+
+    SpecialPowers.clearUserPref("media.webaudio.enabled");
+    SimpleTest.finish();
+  };
+});
+
+</script>
+</pre>
+</body>
+</html>
--- a/content/media/webaudio/test/webaudio.js
+++ b/content/media/webaudio/test/webaudio.js
@@ -19,17 +19,17 @@ function expectTypeError(func) {
   } catch (ex) {
     threw = true;
     ok(ex instanceof TypeError, "Expect a TypeError");
   }
   ok(threw, "The exception was thrown");
 }
 
 function fuzzyCompare(a, b) {
-  return Math.abs(a - b) < 5e-5;
+  return Math.abs(a - b) < 9e-3;
 }
 
 function compareBuffers(buf1, buf2,
                         /*optional*/ offset,
                         /*optional*/ length,
                         /*optional*/ sourceOffset,
                         /*optional*/ destOffset) {
   is(buf1.length, buf2.length, "Buffers must have the same length");