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 Should("osc.type = '" + oscTypes
[k
] + "'", osc
.type
).beEqualTo(oscTypes
[k
]);
45 // Verify that setting a custom type directly does not set the custom type. This test has to be
46 // done before using setPeriodicWave.
48 Should("osc.type = 'custom'", function () {
50 }).throw('InvalidStateError');
52 // Now set a custom oscillator
53 var coeffA
= new Float32Array([0, 1, 0.5]);
54 var coeffB
= new Float32Array([0, 0, 0]);
55 var wave
= context
.createPeriodicWave(coeffA
, coeffB
);
57 Should("osc.setPeriodicWave(wave)", function () {
58 osc
.setPeriodicWave(wave
);
60 Should("osc.type", osc
.type
).beEqualTo("custom");
62 // Check that numerical values are no longer supported
63 var oldType
= osc
.type
;
65 Should("osc.type = 0", osc
.type
).notBeEqualTo(0);
66 Should("osc.type", osc
.type
).beEqualTo(oldType
);
72 successfullyParsed
= true;