Creating "basic waveform" Oscillator nodes is not efficient
[WebKit-https.git] / LayoutTests / webaudio / oscillator-basic.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
3 <!--
4 Create an oscillator of each type and verify that the type is set correctly.
5 -->
6 <html>
7 <head>
8 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css"/>
9 <script type="text/javascript" src="resources/audio-testing.js"></script>
10 <script type="text/javascript" src="../fast/js/resources/js-test-pre.js"></script>
11 </head>
12
13 <body>
14 <div id="description"></div>
15 <div id="console"></div>
16
17 <script>
18 description("Basic test of setting Oscillator node types.");
19
20 var sampleRate = 44100;
21 var renderLengthSeconds = 0.25;
22
23 var oscTypes = [{type: 0, name: "SINE"},
24                 {type: 1, name: "SQUARE"},
25                 {type: 2, name: "SAWTOOTH"},
26                 {type: 3, name: "TRIANGLE"},
27                 {type: 4, name: "CUSTOM"}];
28
29 function runTest() 
30 {
31     if (window.testRunner) {
32         testRunner.dumpAsText();
33         testRunner.waitUntilDone();
34     }
35     
36     window.jsTestIsAsync = true;
37         
38     // Create offline audio context.
39     var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
40     var osc = context.createOscillator();
41
42     // Set each possible oscillator type (except CUSTOM) and verify that the type is correct.
43     for (var k = 0; k < oscTypes.length - 1; ++k) {
44         osc.type = oscTypes[k].type
45         if (osc.type == oscTypes[k].type)
46             testPassed("Oscillator correctly set to " + oscTypes[k].name + " type.");
47         else
48             testFailed("Oscillator set to " + oscTypes[k].name + " type, but returns " + oscTypes[osc.type].name + " type.");
49     }
50
51     // Now set a custom oscillator
52     var coeffA = new Float32Array([0, 1, 0.5]);
53     var coeffB = new Float32Array([0, 0, 0]);        
54     var wavetable = context.createWaveTable(coeffA, coeffB);
55     osc.setWaveTable(wavetable);
56     if (osc.type == osc.CUSTOM)
57         testPassed("Oscillator correctly set to CUSTOM type.");
58     else
59         testFailed("Oscillator set to CUSTOM type, but returns " + oscTypes[osc.type].name + " type.");
60
61     finishJSTest();
62 }
63
64 runTest();
65 successfullyParsed = true;
66
67 </script>
68
69 <script src="../fast/js/resources/js-test-post.js"></script>
70
71 </body>
72 </html>