2012-09-24 20:31:58 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test whether we can create an AudioContext interface</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
2013-04-11 19:08:05 -07:00
|
|
|
<script type="text/javascript" src="webaudio.js"></script>
|
2012-09-24 20:31:58 -07:00
|
|
|
<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() {
|
|
|
|
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
|
|
|
|
|
2013-01-22 17:12:21 -08:00
|
|
|
var context = new AudioContext();
|
2013-02-04 13:57:36 -08:00
|
|
|
var buffer = context.createBuffer(1, 2048, context.sampleRate);
|
2012-09-24 20:31:58 -07:00
|
|
|
for (var i = 0; i < 2048; ++i) {
|
2013-02-04 13:57:36 -08:00
|
|
|
buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
|
2012-09-24 20:31:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var destination = context.destination;
|
|
|
|
is(destination.context, context, "Destination node has proper context");
|
|
|
|
is(destination.context, context, "Destination node has proper context");
|
2013-01-23 16:50:18 -08:00
|
|
|
is(destination.numberOfInputs, 1, "Destination node has 1 inputs");
|
2012-09-24 20:31:58 -07:00
|
|
|
is(destination.numberOfOutputs, 0, "Destination node has 0 outputs");
|
|
|
|
|
2013-04-11 19:08:05 -07:00
|
|
|
testWith(context, buffer, destination, function(source) {
|
|
|
|
source.start(0);
|
|
|
|
}, function(source) {
|
|
|
|
source.stop();
|
|
|
|
}, function() {
|
|
|
|
testWith(context, buffer, destination, function(source) {
|
|
|
|
source.start(0, 1);
|
|
|
|
}, function(source) {
|
|
|
|
expectTypeError(function() {
|
|
|
|
source.noteOff();
|
|
|
|
});
|
|
|
|
source.noteOff(0);
|
|
|
|
}, function() {
|
|
|
|
testWith(context, buffer, destination, function(source) {
|
|
|
|
source.start(0, 1, 0.5);
|
|
|
|
}, function(source) {
|
|
|
|
source.stop(0);
|
|
|
|
}, function() {
|
|
|
|
testWith(context, buffer, destination, function(source) {
|
|
|
|
source.noteOn(0);
|
|
|
|
}, function(source) {
|
|
|
|
source.noteOff(0);
|
|
|
|
}, function() {
|
|
|
|
testWith(context, buffer, destination, function(source) {
|
|
|
|
source.noteGrainOn(0, 1, 0.5);
|
|
|
|
}, function(source) {
|
|
|
|
source.stop();
|
|
|
|
}, function() {
|
|
|
|
SpecialPowers.clearUserPref("media.webaudio.enabled");
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function testWith(context, buffer, destination, start, stop, callback)
|
|
|
|
{
|
|
|
|
var source = createNode(context, buffer, destination);
|
|
|
|
start(source);
|
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
stop(source);
|
|
|
|
callback();
|
|
|
|
source.disconnect();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function createNode(context, buffer, destination) {
|
2012-09-24 20:31:58 -07:00
|
|
|
var source = context.createBufferSource();
|
|
|
|
is(source.context, context, "Source node has proper context");
|
|
|
|
is(source.numberOfInputs, 0, "Source node has 0 inputs");
|
2013-01-23 16:50:18 -08:00
|
|
|
is(source.numberOfOutputs, 1, "Source node has 1 outputs");
|
2013-03-10 09:56:14 -07:00
|
|
|
is(source.loop, false, "Source node is not looping");
|
|
|
|
is(source.loopStart, 0, "Correct default value for loopStart");
|
|
|
|
is(source.loopEnd, 0, "Correct default value for loopEnd");
|
2012-09-24 20:31:58 -07:00
|
|
|
ok(!source.buffer, "Source node should not have a buffer when it's created");
|
|
|
|
|
|
|
|
source.buffer = buffer;
|
|
|
|
ok(source.buffer, "Source node should have a buffer now");
|
|
|
|
|
|
|
|
source.connect(destination);
|
|
|
|
|
|
|
|
is(source.numberOfInputs, 0, "Source node has 0 inputs");
|
|
|
|
is(source.numberOfOutputs, 1, "Source node has 0 outputs");
|
|
|
|
is(destination.numberOfInputs, 1, "Destination node has 0 inputs");
|
|
|
|
is(destination.numberOfOutputs, 0, "Destination node has 0 outputs");
|
|
|
|
|
2013-04-11 19:08:05 -07:00
|
|
|
return source;
|
|
|
|
}
|
2012-09-24 20:31:58 -07:00
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|