content/media/webaudio/test/test_bug956489.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/test/test_bug956489.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 when and currentTime are in the same coordinate system</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +</head>
    1.11 +<body>
    1.12 +<pre id="test">
    1.13 +<script class="testbody" type="text/javascript">
    1.14 +
    1.15 +SimpleTest.waitForExplicitFinish();
    1.16 +addLoadEvent(function() {
    1.17 +  var freq = 330;
    1.18 +
    1.19 +  var context = new AudioContext();
    1.20 +
    1.21 +  var buffer = context.createBuffer(1, context.sampleRate / freq, context.sampleRate);
    1.22 +  for (var i = 0; i < buffer.length; ++i) {
    1.23 +    buffer.getChannelData(0)[i] = Math.sin(2 * Math.PI * i / buffer.length);
    1.24 +  }
    1.25 +
    1.26 +  var source = context.createBufferSource();
    1.27 +  source.loop = true;
    1.28 +  source.buffer = buffer;
    1.29 +
    1.30 +  setTimeout(function () {
    1.31 +      var finished = false;
    1.32 +
    1.33 +      source.start(context.currentTime);
    1.34 +      var processor = context.createScriptProcessor(256, 1, 1);
    1.35 +      processor.onaudioprocess = function (e) {
    1.36 +          if (finished) return;
    1.37 +          var c = e.inputBuffer.getChannelData(0);
    1.38 +          var result = true;
    1.39 +
    1.40 +          for (var i = 0; i < buffer.length; ++i) {
    1.41 +              if (Math.abs(c[i] - buffer.getChannelData(0)[i]) > 1e-9) {
    1.42 +                  result = false;
    1.43 +                  break;
    1.44 +              }
    1.45 +          }
    1.46 +          finished = true;
    1.47 +          ok(result, "when and currentTime are in same time coordinate system");
    1.48 +          SimpleTest.finish();
    1.49 +      }
    1.50 +      processor.connect(context.destination);
    1.51 +      source.connect(processor);
    1.52 +  }, 500);
    1.53 +});
    1.54 +
    1.55 +</script>
    1.56 +</pre>
    1.57 +</body>
    1.58 +</html>

mercurial