mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
76 lines
2.4 KiB
HTML
76 lines
2.4 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test AudioBufferSourceNode</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">
|
|
|
|
// We do not use our generic graph test framework here because
|
|
// the testing logic here is sort of complicated, and would
|
|
// not be easy to map to OfflineAudioContext, as ScriptProcessorNodes
|
|
// can experience delays.
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
addLoadEvent(function() {
|
|
var context = new AudioContext();
|
|
var buffer = context.createBuffer(6, 2048, context.sampleRate);
|
|
for (var i = 0; i < 2048; ++i) {
|
|
for (var j = 0; j < 6; ++j) {
|
|
buffer.getChannelData(0)[i] = Math.sin(440 * j * Math.PI * i / context.sampleRate);
|
|
}
|
|
}
|
|
|
|
var monoBuffer = context.createBuffer(1, 2048, context.sampleRate);
|
|
for (var i = 0; i < 2048; ++i) {
|
|
monoBuffer.getChannelData(0)[i] = 1;
|
|
}
|
|
|
|
var source = context.createBufferSource();
|
|
|
|
var sp = context.createScriptProcessor(2048);
|
|
sp.channelCount = 3;
|
|
sp.channelCountMode = "explicit";
|
|
sp.channelInterpretation = "discrete";
|
|
source.start(0);
|
|
source.buffer = buffer;
|
|
source.connect(sp);
|
|
sp.connect(context.destination);
|
|
|
|
var monoSource = context.createBufferSource();
|
|
monoSource.buffer = monoBuffer;
|
|
monoSource.connect(sp);
|
|
monoSource.start(2048 / context.sampleRate);
|
|
|
|
sp.onaudioprocess = function(e) {
|
|
is(e.inputBuffer.numberOfChannels, 3, "Should be correctly down-mixed to three channels");
|
|
for (var i = 0; i < 3; ++i) {
|
|
compareBuffers(e.inputBuffer.getChannelData(i), buffer.getChannelData(i));
|
|
}
|
|
|
|
// On the next iteration, we'll get a silence buffer
|
|
sp.onaudioprocess = function(e) {
|
|
var emptyBuffer = context.createBuffer(1, 2048, context.sampleRate);
|
|
is(e.inputBuffer.numberOfChannels, 3, "Should be correctly up-mixed to three channels");
|
|
compareBuffers(e.inputBuffer.getChannelData(0), monoBuffer.getChannelData(0));
|
|
for (var i = 1; i < 3; ++i) {
|
|
compareBuffers(e.inputBuffer.getChannelData(i), emptyBuffer.getChannelData(0));
|
|
}
|
|
|
|
sp.onaudioprocess = null;
|
|
sp.disconnect(context.destination);
|
|
|
|
SimpleTest.finish();
|
|
};
|
|
};
|
|
});
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|