Refactoring: Pull all fullscreen code out of Document and into its own helper class
[WebKit-https.git] / LayoutTests / webaudio / test-basic.html
1 <!DOCTYPE html>
2
3 <!--
4 This is a very basic test to make sure testRunner.setAudioResult() works correctly.
5 It generates a 2 seconds long stereo result @44.1KHz
6 The left channel will be a 880Hz tone, while the right will be 440Hz.
7 -->
8
9 <html>
10 <head>
11 <script src="../resources/js-test.js"></script>
12 <script type="text/javascript" src="resources/audio-testing.js"></script>
13
14 </head>
15 <body>
16
17 <div id="description"></div>
18 <div id="console"></div>
19
20 <script>
21 description("Tests basic audio test infrastructure: specifically testRunner.setAudioResult()");
22
23 var sampleRate = 44100.0;
24 var lengthInSeconds = 2;
25
26 function generateSinWave(audioBuffer) {
27     var n = audioBuffer.length;
28     var channelL = audioBuffer.getChannelData(0);
29     var channelR = audioBuffer.getChannelData(1);
30     var sampleRate = audioBuffer.sampleRate;
31     
32     for (var i = 0; i < n; ++i) {
33         channelL[i] = Math.sin(880.0 * 2.0*Math.PI * i / sampleRate);
34         channelR[i] = Math.sin(440.0 * 2.0*Math.PI * i / sampleRate);
35     }
36 }
37
38 function runTest() {
39     if (!window.testRunner)
40         return;
41     
42     var context = new webkitAudioContext();
43     var audioBuffer = context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate);
44     
45     generateSinWave(audioBuffer);
46
47     var audioData = createAudioData(audioBuffer);
48     testRunner.setAudioResult(audioData);
49 }
50
51 runTest();
52
53 </script>
54 <body>
55 </body>
56 </html>