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 <script src="resources/compatibility.js"></script>
9 <script type="text/javascript" src="resources/audio-testing.js"></script>
10 <script type="text/javascript" src="../resources/js-test.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 = ["sine", "square", "sawtooth", "triangle", "custom"];
27 if (window.testRunner) {
28 testRunner.dumpAsText();
29 testRunner.waitUntilDone();
32 window.jsTestIsAsync = true;
34 // Create offline audio context.
35 var context = new OfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
36 var osc = context.createOscillator();
38 // Set each possible oscillator type (except CUSTOM) and verify that the type is correct.
39 // Here we're setting the type using WebIDL enum values which are strings.
40 for (var k = 0; k < oscTypes.length - 1; ++k) {
41 osc.type = oscTypes[k];
42 if (osc.type == oscTypes[k])
43 testPassed('Oscillator correctly set to "' + oscTypes[k] + '" type.');
45 testFailed('Oscillator set to "' + oscTypes[k] + '" type, but returns "' + osc.type + '" type.');
48 // Verify that setting a custom type directly does not set the custom type. This test has to be
49 // done before using setPeriodicWave.
52 if (osc.type == "custom")
53 testFailed('Directly setting oscillator type to "custom" incorrectly succeeded.');
55 testPassed('Directly setting oscillator type to "custom" correctly failed.');
57 // Now set a custom oscillator
58 var coeffA = new Float32Array([0, 1, 0.5]);
59 var coeffB = new Float32Array([0, 0, 0]);
60 var wave = context.createPeriodicWave(coeffA, coeffB);
61 osc.setPeriodicWave(wave);
62 if (osc.type == "custom")
63 testPassed('Oscillator correctly set to "custom" type using setPeriodicWave.');
65 testFailed('Oscillator set to "custom" type, but returns "' + osc.type + '" type.');
68 // Check that numerical values are no longer supported
71 testFailed("Oscillator incorrectly set to 0.")
73 testPassed("Oscillator correctly not set to 0.");
79 successfullyParsed = true;