2013-08-19 18:53:00 +00:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test the OscillatorNode interface</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript" src="webaudio.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
addLoadEvent(function() {
|
|
|
|
|
|
|
|
var context = new AudioContext();
|
|
|
|
var osc = context.createOscillator();
|
|
|
|
|
|
|
|
is(osc.channelCount, 2, "Oscillator node has 2 input channels by default");
|
|
|
|
is(osc.channelCountMode, "max", "Correct channelCountMode for the Oscillator node");
|
|
|
|
is(osc.channelInterpretation, "speakers", "Correct channelCountInterpretation for the Oscillator node");
|
|
|
|
is(osc.type, "sine", "Correct default type");
|
|
|
|
expectException(function() {
|
|
|
|
osc.type = "custom";
|
2013-08-28 22:39:26 +00:00
|
|
|
}, DOMException.INVALID_STATE_ERR);
|
2013-08-19 18:54:00 +00:00
|
|
|
expectException(function() {
|
|
|
|
osc.type = osc.CUSTOM;
|
2013-08-28 22:39:26 +00:00
|
|
|
}, DOMException.INVALID_STATE_ERR);
|
2013-08-19 18:54:00 +00:00
|
|
|
is(osc.type, "sine", "Cannot set the type to custom");
|
2013-08-19 18:53:00 +00:00
|
|
|
is(osc.frequency.value, 440, "Correct default frequency value");
|
|
|
|
is(osc.detune.value, 0, "Correct default detine value");
|
|
|
|
|
2013-08-19 18:54:00 +00:00
|
|
|
// Make sure that we can set all of the valid type values
|
|
|
|
var types = [
|
|
|
|
"sine",
|
|
|
|
"square",
|
|
|
|
"sawtooth",
|
|
|
|
"triangle",
|
|
|
|
];
|
|
|
|
for (var i = 0; i < types.length; ++i) {
|
|
|
|
osc.type = osc[types[i].toUpperCase()];
|
|
|
|
is(osc.type, types[i], "Correct alternname type enum value");
|
|
|
|
osc.type = types[i];
|
|
|
|
}
|
|
|
|
|
2013-08-28 22:39:26 +00:00
|
|
|
// Verify setPeriodicWave()
|
|
|
|
var real = new Float32Array([1.0, 0.5, 0.25, 0.125]);
|
|
|
|
var imag = new Float32Array([1.0, 0.7, -1.0, 0.5]);
|
|
|
|
osc.setPeriodicWave(context.createPeriodicWave(real, imag));
|
|
|
|
is(osc.type, "custom", "Failed to set custom waveform");
|
|
|
|
|
2013-08-19 18:53:00 +00:00
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|