content/media/webaudio/test/test_audioBufferSourceNodeOffset.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/test/test_audioBufferSourceNodeOffset.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test the offset property on AudioBufferSourceNode</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="webaudio.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body>
    1.13 +<pre id="test">
    1.14 +<script class="testbody" type="text/javascript">
    1.15 +
    1.16 +var fuzz = 0.3;
    1.17 +
    1.18 +if (navigator.platform.startsWith("Mac")) {
    1.19 +  // bug 895720
    1.20 +  fuzz = 0.6;
    1.21 +}
    1.22 +
    1.23 +SimpleTest.waitForExplicitFinish();
    1.24 +addLoadEvent(function() {
    1.25 +  var samplesFromSource = 0;
    1.26 +  var context = new AudioContext();
    1.27 +  var sp = context.createScriptProcessor(256);
    1.28 +
    1.29 +  sp.onaudioprocess = function(e) {
    1.30 +    samplesFromSource += e.inputBuffer.length;
    1.31 +  }
    1.32 +
    1.33 +  var buffer = context.createBuffer(1, context.sampleRate, context.sampleRate);
    1.34 +  for (var i = 0; i < context.sampleRate; ++i) {
    1.35 +    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
    1.36 +  }
    1.37 +
    1.38 +  var source = context.createBufferSource();
    1.39 +
    1.40 +  source.onended = function(e) {
    1.41 +    // The timing at which the audioprocess and ended listeners are called can
    1.42 +    // change, hence the fuzzy equal here.
    1.43 +    var errorRatio = samplesFromSource / (0.5 * context.sampleRate);
    1.44 +    ok(errorRatio > (1.0 - fuzz) && errorRatio < (1.0 + fuzz),
    1.45 +       "Correct number of samples received (expected: " +
    1.46 +       (0.5 * context.sampleRate) + ", actual: " + samplesFromSource + ").");
    1.47 +    SimpleTest.finish();
    1.48 +  };
    1.49 +
    1.50 +  source.buffer = buffer;
    1.51 +  source.connect(sp);
    1.52 +  source.start(0, 0.5);
    1.53 +});
    1.54 +
    1.55 +</script>
    1.56 +</pre>
    1.57 +</body>
    1.58 +</html>

mercurial