test for bug 964376
authorTony Young <tony@rfw.name>
Fri, 14 Feb 2014 17:48:34 +1300
changeset 169436 a310ac56a47b33cb5633207c2a1f6163ff4715dc
parent 169435 2bddbd180d2d9fa38ac4138267e1cbfebc6bb5ef
child 169437 49f896f2264116e6698eba6fd00d5ed0c1a854e8
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
bugs964376
milestone30.0a1
test for bug 964376
content/media/webaudio/test/mochitest.ini
content/media/webaudio/test/test_bug964376.html
--- a/content/media/webaudio/test/mochitest.ini
+++ b/content/media/webaudio/test/mochitest.ini
@@ -58,16 +58,17 @@ support-files =
 [test_bug866737.html]
 [test_bug867089.html]
 [test_bug867104.html]
 [test_bug867174.html]
 [test_bug867203.html]
 [test_bug875221.html]
 [test_bug875402.html]
 [test_bug894150.html]
+[test_bug964376.html]
 [test_channelMergerNode.html]
 [test_channelMergerNodeWithVolume.html]
 [test_channelSplitterNode.html]
 [test_channelSplitterNodeWithVolume.html]
 [test_convolverNode.html]
 [test_convolverNodeChannelCount.html]
 [test_convolverNodeWithGain.html]
 [test_convolverNode_mono_mono.html]
new file mode 100644
--- /dev/null
+++ b/content/media/webaudio/test/test_bug964376.html
@@ -0,0 +1,64 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test repeating audio is not distorted</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">
+
+function gcd(a, b) {
+  if (b === 0) {
+    return a;
+  }
+  return gcd(b, a % b);
+}
+
+var SAMPLE_PLACEMENT = 128;
+
+var gTest = {
+  length: 2048,
+  numberOfChannels: 1,
+
+  createGraph: function(context) {
+    var freq = Math.round(context.sampleRate / SAMPLE_PLACEMENT);
+    var dur = context.sampleRate / gcd(freq, context.sampleRate);
+    var buffer = context.createBuffer(1, dur, context.sampleRate);
+
+    for (var i = 0; i < context.sampleRate; ++i) {
+      buffer.getChannelData(0)[i] = Math.sin(freq * 2 * Math.PI * i / context.sampleRate);
+    }
+
+    var source = context.createBufferSource();
+    source.buffer = buffer;
+    source.loop = true;
+    source.playbackRate.setValueAtTime(0.5, SAMPLE_PLACEMENT / context.sampleRate);
+    source.start(0);
+
+    return source;
+  },
+
+  createExpectedBuffers: function(context) {
+    var freq = Math.round(context.sampleRate / SAMPLE_PLACEMENT);
+    var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
+    var c = expectedBuffer.getChannelData(0);
+    for (var i = 0; i < c.length; ++i) {
+      if (i < SAMPLE_PLACEMENT) {
+        c[i] = Math.sin(freq * 2 * Math.PI * i / context.sampleRate);
+      } else {
+        c[i] = Math.sin(freq / 2 * 2 * Math.PI * (i + SAMPLE_PLACEMENT) / context.sampleRate);
+      }
+    }
+
+    return expectedBuffer;
+  },
+};
+
+runTest();
+</script>
+</pre>
+</body>
+</html>