|
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"> |
|
11 |
|
12 SimpleTest.waitForExplicitFinish(); |
|
13 addLoadEvent(function() { |
|
14 var freq = 330; |
|
15 |
|
16 var context = new AudioContext(); |
|
17 |
|
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 } |
|
22 |
|
23 var source = context.createBufferSource(); |
|
24 source.loop = true; |
|
25 source.buffer = buffer; |
|
26 |
|
27 setTimeout(function () { |
|
28 var finished = false; |
|
29 |
|
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; |
|
36 |
|
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 }); |
|
51 |
|
52 </script> |
|
53 </pre> |
|
54 </body> |
|
55 </html> |