Use stereo AudioBuffer instead of RealtimeAnalyserNode in the layout test of stereo2m...
[WebKit-https.git] / LayoutTests / webaudio / stereo2mono-down-mixing.html
1 <!DOCTYPE html>
2
3 <html>
4 <head>
5 <script src="../fast/js/resources/js-test-pre.js"></script>
6 </head>
7
8 <body>
9
10 <div id="description"></div>
11 <div id="console"></div>
12
13 <script>
14 description("This test verifies whether down mixing from stereo to mono will cause assertion error.");
15
16 var sampleRate = 44100.0;
17 var renderLengthSeconds = 0.1;
18
19 var context;
20 var toneBuffer;
21 var bufferSource;
22
23 function createDataBuffer(context, lengthInSeconds) {
24     var audioBuffer = context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate);
25
26     var n = audioBuffer.length;
27     var data0 = audioBuffer.getChannelData(0);
28     var data1 = audioBuffer.getChannelData(1);
29
30     for (var i = 0; i < n; ++i) {
31         data0[i] = 1.0;
32         data1[i] = 1.0;
33     }
34
35     return audioBuffer;
36 }
37
38 function testFinished() {
39     testPassed("Test no ASSERT error.");
40     finishJSTest();
41 }
42
43 function runTest() {
44     if (window.layoutTestController) {
45         layoutTestController.overridePreference("WebKitWebAudioEnabled", "1");
46         layoutTestController.dumpAsText();
47         layoutTestController.waitUntilDone();
48     }
49
50     window.jsTestIsAsync = true;
51
52     // Create offline audio context, the destination is mono.
53     context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
54     // Create a stereo AudioBuffer.
55     toneBuffer = createDataBuffer(context, renderLengthSeconds);
56
57     bufferSource = context.createBufferSource();
58     bufferSource.buffer = toneBuffer;
59
60     bufferSource.connect(context.destination);
61
62     bufferSource.noteOn(0);
63
64     context.oncomplete = testFinished;
65     context.startRendering();
66 }
67
68
69 runTest();
70
71 </script>
72
73 <script src="../fast/js/resources/js-test-post.js"></script>
74 </body>
75 </html>