content/media/webaudio/test/test_bug956489.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test when and currentTime are in the same coordinate system</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     7 </head>
     8 <body>
     9 <pre id="test">
    10 <script class="testbody" type="text/javascript">
    12 SimpleTest.waitForExplicitFinish();
    13 addLoadEvent(function() {
    14   var freq = 330;
    16   var context = new AudioContext();
    18   var buffer = context.createBuffer(1, context.sampleRate / freq, context.sampleRate);
    19   for (var i = 0; i < buffer.length; ++i) {
    20     buffer.getChannelData(0)[i] = Math.sin(2 * Math.PI * i / buffer.length);
    21   }
    23   var source = context.createBufferSource();
    24   source.loop = true;
    25   source.buffer = buffer;
    27   setTimeout(function () {
    28       var finished = false;
    30       source.start(context.currentTime);
    31       var processor = context.createScriptProcessor(256, 1, 1);
    32       processor.onaudioprocess = function (e) {
    33           if (finished) return;
    34           var c = e.inputBuffer.getChannelData(0);
    35           var result = true;
    37           for (var i = 0; i < buffer.length; ++i) {
    38               if (Math.abs(c[i] - buffer.getChannelData(0)[i]) > 1e-9) {
    39                   result = false;
    40                   break;
    41               }
    42           }
    43           finished = true;
    44           ok(result, "when and currentTime are in same time coordinate system");
    45           SimpleTest.finish();
    46       }
    47       processor.connect(context.destination);
    48       source.connect(processor);
    49   }, 500);
    50 });
    52 </script>
    53 </pre>
    54 </body>
    55 </html>

mercurial