test_bug956489.html (1664B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test when and currentTime are in the same coordinate system</title> 5 <script 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"> 11 12 SimpleTest.waitForExplicitFinish(); 13 SimpleTest.requestFlakyTimeout("This test needs to wait a while for the AudioContext's timer to start."); 14 addLoadEvent(function() { 15 var freq = 330; 16 17 var context = new AudioContext(); 18 19 var buffer = context.createBuffer(1, context.sampleRate / freq, context.sampleRate); 20 for (var i = 0; i < buffer.length; ++i) { 21 buffer.getChannelData(0)[i] = Math.sin(2 * Math.PI * i / buffer.length); 22 } 23 24 var source = context.createBufferSource(); 25 source.loop = true; 26 source.buffer = buffer; 27 28 setTimeout(function () { 29 var finished = false; 30 31 source.start(context.currentTime); 32 var processor = context.createScriptProcessor(256, 1, 1); 33 processor.onaudioprocess = function (e) { 34 if (finished) return; 35 var c = e.inputBuffer.getChannelData(0); 36 var result = true; 37 38 for (var i = 0; i < buffer.length; ++i) { 39 if (Math.abs(c[i] - buffer.getChannelData(0)[i]) > 1e-9) { 40 result = false; 41 break; 42 } 43 } 44 finished = true; 45 ok(result, "when and currentTime are in same time coordinate system"); 46 SimpleTest.finish(); 47 } 48 processor.connect(context.destination); 49 source.connect(processor); 50 }, 500); 51 }); 52 53 </script> 54 </pre> 55 </body> 56 </html>