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

58 строки
1.6 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test GainNode in presence of loops</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 sourceBuffer = context.createBuffer(1, 2048, context.sampleRate);
for (var i = 0; i < 2048; ++i) {
sourceBuffer.getChannelData(0)[i] = 1;
}
var expectedBuffer = context.createBuffer(1, 4096, context.sampleRate);
for (var i = 0; i < 4096; ++i) {
expectedBuffer.getChannelData(0)[i] = 0.5;
}
var source = context.createBufferSource();
source.buffer = sourceBuffer;
source.loop = true;
source.start(0);
source.stop(sourceBuffer.duration * 2);
var gain = context.createGain();
// Adjust the gain in a way that we don't just end up modifying AudioChunk::mVolume
gain.gain.setValueAtTime(0.5, 0);
source.connect(gain);
var sp = context.createScriptProcessor(4096, 1);
gain.connect(sp);
sp.connect(context.destination);
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>