mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
49 lines
1.4 KiB
HTML
49 lines
1.4 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test the offset property on 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">
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
addLoadEvent(function() {
|
|
var samplesFromSource = 0;
|
|
var context = new AudioContext();
|
|
var sp = context.createScriptProcessor(256);
|
|
|
|
sp.onaudioprocess = function(e) {
|
|
samplesFromSource += e.inputBuffer.length;
|
|
}
|
|
|
|
var buffer = context.createBuffer(1, context.sampleRate, context.sampleRate);
|
|
for (var i = 0; i < context.sampleRate; ++i) {
|
|
buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
|
|
}
|
|
|
|
var source = context.createBufferSource();
|
|
|
|
source.onended = function(e) {
|
|
// The timing at which the audioprocess and ended listeners are called can
|
|
// change, hence the fuzzy equal here.
|
|
var errorRatio = samplesFromSource / (0.5 * context.sampleRate);
|
|
ok(errorRatio > 0.70 && errorRatio < 1.3,
|
|
"Correct number of samples received (expected: " +
|
|
(0.5 * context.sampleRate) + ", actual: " + samplesFromSource + ").");
|
|
SimpleTest.finish();
|
|
};
|
|
|
|
source.buffer = buffer;
|
|
source.connect(sp);
|
|
source.start(0, 0.5);
|
|
});
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|