Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test when and currentTime are in the same coordinate system</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | <pre id="test"> |
michael@0 | 10 | <script class="testbody" type="text/javascript"> |
michael@0 | 11 | |
michael@0 | 12 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 13 | addLoadEvent(function() { |
michael@0 | 14 | var freq = 330; |
michael@0 | 15 | |
michael@0 | 16 | var context = new AudioContext(); |
michael@0 | 17 | |
michael@0 | 18 | var buffer = context.createBuffer(1, context.sampleRate / freq, context.sampleRate); |
michael@0 | 19 | for (var i = 0; i < buffer.length; ++i) { |
michael@0 | 20 | buffer.getChannelData(0)[i] = Math.sin(2 * Math.PI * i / buffer.length); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | var source = context.createBufferSource(); |
michael@0 | 24 | source.loop = true; |
michael@0 | 25 | source.buffer = buffer; |
michael@0 | 26 | |
michael@0 | 27 | setTimeout(function () { |
michael@0 | 28 | var finished = false; |
michael@0 | 29 | |
michael@0 | 30 | source.start(context.currentTime); |
michael@0 | 31 | var processor = context.createScriptProcessor(256, 1, 1); |
michael@0 | 32 | processor.onaudioprocess = function (e) { |
michael@0 | 33 | if (finished) return; |
michael@0 | 34 | var c = e.inputBuffer.getChannelData(0); |
michael@0 | 35 | var result = true; |
michael@0 | 36 | |
michael@0 | 37 | for (var i = 0; i < buffer.length; ++i) { |
michael@0 | 38 | if (Math.abs(c[i] - buffer.getChannelData(0)[i]) > 1e-9) { |
michael@0 | 39 | result = false; |
michael@0 | 40 | break; |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | finished = true; |
michael@0 | 44 | ok(result, "when and currentTime are in same time coordinate system"); |
michael@0 | 45 | SimpleTest.finish(); |
michael@0 | 46 | } |
michael@0 | 47 | processor.connect(context.destination); |
michael@0 | 48 | source.connect(processor); |
michael@0 | 49 | }, 500); |
michael@0 | 50 | }); |
michael@0 | 51 | |
michael@0 | 52 | </script> |
michael@0 | 53 | </pre> |
michael@0 | 54 | </body> |
michael@0 | 55 | </html> |