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 the offset property on AudioBufferSourceNode</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="webaudio.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <pre id="test"> |
michael@0 | 11 | <script class="testbody" type="text/javascript"> |
michael@0 | 12 | |
michael@0 | 13 | var fuzz = 0.3; |
michael@0 | 14 | |
michael@0 | 15 | if (navigator.platform.startsWith("Mac")) { |
michael@0 | 16 | // bug 895720 |
michael@0 | 17 | fuzz = 0.6; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 21 | addLoadEvent(function() { |
michael@0 | 22 | var samplesFromSource = 0; |
michael@0 | 23 | var context = new AudioContext(); |
michael@0 | 24 | var sp = context.createScriptProcessor(256); |
michael@0 | 25 | |
michael@0 | 26 | sp.onaudioprocess = function(e) { |
michael@0 | 27 | samplesFromSource += e.inputBuffer.length; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | var buffer = context.createBuffer(1, context.sampleRate, context.sampleRate); |
michael@0 | 31 | for (var i = 0; i < context.sampleRate; ++i) { |
michael@0 | 32 | buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | var source = context.createBufferSource(); |
michael@0 | 36 | |
michael@0 | 37 | source.onended = function(e) { |
michael@0 | 38 | // The timing at which the audioprocess and ended listeners are called can |
michael@0 | 39 | // change, hence the fuzzy equal here. |
michael@0 | 40 | var errorRatio = samplesFromSource / (0.5 * context.sampleRate); |
michael@0 | 41 | ok(errorRatio > (1.0 - fuzz) && errorRatio < (1.0 + fuzz), |
michael@0 | 42 | "Correct number of samples received (expected: " + |
michael@0 | 43 | (0.5 * context.sampleRate) + ", actual: " + samplesFromSource + ")."); |
michael@0 | 44 | SimpleTest.finish(); |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | source.buffer = buffer; |
michael@0 | 48 | source.connect(sp); |
michael@0 | 49 | source.start(0, 0.5); |
michael@0 | 50 | }); |
michael@0 | 51 | |
michael@0 | 52 | </script> |
michael@0 | 53 | </pre> |
michael@0 | 54 | </body> |
michael@0 | 55 | </html> |