Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / test-basic.html
blob74571faac58c3d803762e60eecbb79e476a877fc
1 <!DOCTYPE html>
3 <!--
4 This is a very basic test to make sure testRunner.setAudioData() 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 -->
9 <html>
10 <head>
11 <script src="../resources/js-test.js"></script>
12 <script type="text/javascript" src="resources/audio-testing.js"></script>
14 </head>
15 <body>
17 <div id="description"></div>
18 <div id="console"></div>
20 <script>
21 description("Tests basic audio test infrastructure: specifically testRunner.setAudioData()");
23 var sampleRate = 44100.0;
24 var lengthInSeconds = 2;
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;
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);
38 function runTest() {
39 if (!window.testRunner)
40 return;
42 var context = new AudioContext();
43 var audioBuffer = context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate);
45 generateSinWave(audioBuffer);
47 var audioData = createAudioData(audioBuffer);
48 testRunner.setAudioData(audioData);
50 testRunner.notifyDone();
53 runTest();
55 </script>
58 <body>
59 </body>
60 </html>