gecko-dev/content/media/webaudio/test/test_gainNode.html

69 lines
2.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test GainNode</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() {
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
var context = new AudioContext();
var buffer = context.createBuffer(1, 2048, context.sampleRate);
for (var i = 0; i < 2048; ++i) {
buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
}
var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
for (var i = 0; i < 2048; ++i) {
expectedBuffer.getChannelData(0)[i] = buffer.getChannelData(0)[i] / 2;
}
var destination = context.destination;
var source = context.createBufferSource();
var gain = context.createGain();
var gain2 = context.createGainNode();
isnot(gain, gain2, "createGainNode should create a different gain node");
source.buffer = buffer;
source.connect(gain);
var sp = context.createScriptProcessor(2048, 1);
gain.connect(sp);
sp.connect(destination);
ok(gain.gain, "The audioparam member must exist");
is(gain.gain.value, 1.0, "Correct initial value");
is(gain.gain.defaultValue, 1.0, "Correct default value");
gain.gain.value = 0.5;
is(gain.gain.value, 0.5, "Correct initial value");
is(gain.gain.defaultValue, 1.0, "Correct default value");
is(gain.channelCount, 2, "gain node has 2 input channels by default");
is(gain.channelCountMode, "max", "Correct channelCountMode for the gain node");
is(gain.channelInterpretation, "speakers", "Correct channelCountInterpretation for the gain node");
source.start(0);
sp.onaudioprocess = function(e) {
is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));
sp.onaudioprocess = null;
SpecialPowers.clearUserPref("media.webaudio.enabled");
SimpleTest.finish();
};
});
</script>
</pre>
</body>
</html>