|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test the OscillatorNode interface</title> |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <script type="text/javascript" src="webaudio.js"></script> |
|
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
8 </head> |
|
9 <body> |
|
10 <pre id="test"> |
|
11 <script class="testbody" type="text/javascript"> |
|
12 |
|
13 SimpleTest.waitForExplicitFinish(); |
|
14 addLoadEvent(function() { |
|
15 |
|
16 var context = new AudioContext(); |
|
17 var osc = context.createOscillator(); |
|
18 |
|
19 is(osc.channelCount, 2, "Oscillator node has 2 input channels by default"); |
|
20 is(osc.channelCountMode, "max", "Correct channelCountMode for the Oscillator node"); |
|
21 is(osc.channelInterpretation, "speakers", "Correct channelCountInterpretation for the Oscillator node"); |
|
22 is(osc.type, "sine", "Correct default type"); |
|
23 expectException(function() { |
|
24 osc.type = "custom"; |
|
25 }, DOMException.INVALID_STATE_ERR); |
|
26 expectException(function() { |
|
27 osc.type = osc.CUSTOM; |
|
28 }, DOMException.INVALID_STATE_ERR); |
|
29 is(osc.type, "sine", "Cannot set the type to custom"); |
|
30 is(osc.frequency.value, 440, "Correct default frequency value"); |
|
31 is(osc.detune.value, 0, "Correct default detine value"); |
|
32 |
|
33 // Make sure that we can set all of the valid type values |
|
34 var types = [ |
|
35 "sine", |
|
36 "square", |
|
37 "sawtooth", |
|
38 "triangle", |
|
39 ]; |
|
40 for (var i = 0; i < types.length; ++i) { |
|
41 osc.type = osc[types[i].toUpperCase()]; |
|
42 is(osc.type, types[i], "Correct alternname type enum value"); |
|
43 osc.type = types[i]; |
|
44 } |
|
45 |
|
46 // Verify setPeriodicWave() |
|
47 var real = new Float32Array([1.0, 0.5, 0.25, 0.125]); |
|
48 var imag = new Float32Array([1.0, 0.7, -1.0, 0.5]); |
|
49 osc.setPeriodicWave(context.createPeriodicWave(real, imag)); |
|
50 is(osc.type, "custom", "Failed to set custom waveform"); |
|
51 |
|
52 expectNoException(function() { |
|
53 osc.start(); |
|
54 }); |
|
55 expectNoException(function() { |
|
56 osc.stop(); |
|
57 }); |
|
58 |
|
59 SimpleTest.finish(); |
|
60 }); |
|
61 |
|
62 </script> |
|
63 </pre> |
|
64 </body> |
|
65 </html> |