AudioBus need to support stereo->mono down mix in copyFrom sumFrom etc.
https://bugs.webkit.org/show_bug.cgi?id=77609

Patch by Wei James <james.wei@intel.com> on 2012-02-06
Reviewed by Kenneth Russell.

Test: webaudio/stereo2mono-down-mixing.html

* platform/audio/AudioBus.cpp:
(WebCore):
(WebCore::AudioBus::copyFrom):
(WebCore::AudioBus::sumFrom):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106858 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/webaudio/stereo2mono-down-mixing-expected.txt b/LayoutTests/webaudio/stereo2mono-down-mixing-expected.txt
new file mode 100644
index 0000000..96b28cc
--- /dev/null
+++ b/LayoutTests/webaudio/stereo2mono-down-mixing-expected.txt
@@ -0,0 +1,9 @@
+This test verifies whether down mixing from stereo to mono will cause assertion error.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS Test no ASSERT error.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/webaudio/stereo2mono-down-mixing.html b/LayoutTests/webaudio/stereo2mono-down-mixing.html
new file mode 100644
index 0000000..56b22d0
--- /dev/null
+++ b/LayoutTests/webaudio/stereo2mono-down-mixing.html
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+
+<body>
+
+<div id="description"></div>
+<div id="console"></div>
+
+<script>
+description("This test verifies whether down mixing from stereo to mono will cause assertion error.");
+
+var sampleRate = 44100.0;
+var renderLengthSeconds = 0.1;
+var fftSize = 32;
+
+var context;
+var toneBuffer;
+var bufferSource;
+var analyser;
+
+function createDataBuffer(context, lengthInSeconds) {
+    var audioBuffer = context.createBuffer(1, lengthInSeconds * sampleRate, sampleRate);
+
+    var n = audioBuffer.length;
+    var data = audioBuffer.getChannelData(0);
+
+    for (var i = 0; i < n; ++i) {
+        data[i] = 1.0;
+    }
+
+    return audioBuffer;
+}
+
+function testFinished() {
+    testPassed("Test no ASSERT error.");
+    finishJSTest();
+}
+
+function runTest() {
+    if (window.layoutTestController) {
+        layoutTestController.overridePreference("WebKitWebAudioEnabled", "1");
+        layoutTestController.dumpAsText();
+        layoutTestController.waitUntilDone();
+    }
+
+    window.jsTestIsAsync = true;
+
+    // Create offline audio context.
+    context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    // Explicitly create a mono AudioContext so that the destination is mono.
+    toneBuffer = createDataBuffer(context, renderLengthSeconds);
+
+    bufferSource = context.createBufferSource();
+    bufferSource.buffer = toneBuffer;
+
+    // We create an analyser here, because it has a hard-coded stereo output.
+    analyser = context.createAnalyser();
+    analyser.fftSize = fftSize;
+
+    bufferSource.connect(analyser);
+    analyser.connect(context.destination);
+
+    bufferSource.noteOn(0);
+
+    context.oncomplete = testFinished;
+    context.startRendering();
+}
+
+
+runTest();
+
+</script>
+
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>