1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 Create an oscillator of each type and verify that the type is set correctly.
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>
14 <div id="description"></div>
15 <div id="console"></div>
18 description("Basic test of setting Oscillator node types.");
20 var sampleRate = 44100;
21 var renderLengthSeconds = 0.25;
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"}];
31 if (window.testRunner) {
32 testRunner.dumpAsText();
33 testRunner.waitUntilDone();
36 window.jsTestIsAsync = true;
38 // Create offline audio context.
39 var context = new webkitAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
40 var osc = context.createOscillator();
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.");
48 testFailed("Oscillator set to " + oscTypes[k].name + " type, but returns " + oscTypes[osc.type].name + " type.");
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.");
59 testFailed("Oscillator set to CUSTOM type, but returns " + oscTypes[osc.type].name + " type.");
65 successfullyParsed = true;
69 <script src="../fast/js/resources/js-test-post.js"></script>