Bug 1308438 - Part 7: Test AudioBufferSourceNode with negative playback rate and resampling. r?dminor, r?padenot
MozReview-Commit-ID: KA8SvCQupFn
--- a/dom/media/webaudio/test/mochitest.ini
+++ b/dom/media/webaudio/test/mochitest.ini
@@ -40,16 +40,17 @@ support-files =
[test_audioBufferSourceNodeEnded.html]
[test_audioBufferSourceNodeLazyLoopParam.html]
[test_audioBufferSourceNodeLoop.html]
[test_audioBufferSourceNodeLoopStartEnd.html]
[test_audioBufferSourceNodeLoopStartEndSame.html]
[test_audioBufferSourceNodeDetached.html]
[test_audioBufferSourceNodeNegativePlaybackRate.html]
[test_audioBufferSourceNodeNegativePlaybackRateLoop.html]
+[test_audioBufferSourceNodeNegativePlaybackRateResampling.html]
skip-if = (toolkit == 'android' && debug) || os == 'win' # bug 1127845, bug 1138468
[test_audioBufferSourceNodeNoStart.html]
[test_audioBufferSourceNodeNullBuffer.html]
[test_audioBufferSourceNodeOffset.html]
skip-if = (toolkit == 'android') || debug #bug 906752
[test_audioBufferSourceNodePassThrough.html]
[test_audioBufferSourceNodeRate.html]
[test_AudioContext.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_audioBufferSourceNodeNegativePlaybackRateResampling.html
@@ -0,0 +1,51 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Bug 1308438 - Test AudioBufferSourceNode with negative playback rate and resampling</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();
+
+var rate = 44100;
+var off = new OfflineAudioContext(1, 2048, rate);
+var off2 = new OfflineAudioContext(1, 2048, rate);
+
+var source = off.createBufferSource();
+var source2 = off2.createBufferSource();
+
+var buf = off.createBuffer(1, 2048, rate);
+var buf2 = off2.createBuffer(1, 2048, rate);
+for (var i = 0; i < 2048; ++i) {
+ var val = Math.sin(i * 440 * 2 * Math.PI / rate);
+ buf.getChannelData(0)[i] = val;
+ buf2.getChannelData(0)[2047 - i] = val;
+}
+
+// source 1 play forward
+source.buffer = buf;
+source.playbackRate.value = 0.5;
+source.connect(off.destination);
+source.start(0);
+
+// source 2 play backward
+source2.buffer = buf2;
+source2.playbackRate.value = -0.5;
+source2.connect(off2.destination);
+source2.start(0, buf.duration);
+
+off.startRendering().then((bufferForward) => {
+ off2.startRendering().then((bufferBackward) => {
+ // The two buffers should be the same
+ compareBuffers(bufferBackward, bufferForward);
+ SimpleTest.finish();
+ });
+});
+</script>
+</pre>
+</body>
+</html>