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 AudioParam with pre-gain </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 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 14 | |
michael@0 | 15 | var ctx = new AudioContext(); |
michael@0 | 16 | var source = ctx.createOscillator(); |
michael@0 | 17 | var lfo = ctx.createOscillator(); |
michael@0 | 18 | var lfoIntensity = ctx.createGain(); |
michael@0 | 19 | var effect = ctx.createGain(); |
michael@0 | 20 | var sp = ctx.createScriptProcessor(2048, 1); |
michael@0 | 21 | |
michael@0 | 22 | source.frequency.value = 440; |
michael@0 | 23 | lfo.frequency.value = 2; |
michael@0 | 24 | // Very low gain, so the LFO should have very little influence |
michael@0 | 25 | // on the source, its RMS value should be close to the nominal value |
michael@0 | 26 | // for a sine wave. |
michael@0 | 27 | lfoIntensity.gain.value = 0.0001; |
michael@0 | 28 | |
michael@0 | 29 | lfo.connect(lfoIntensity); |
michael@0 | 30 | lfoIntensity.connect(effect.gain); |
michael@0 | 31 | source.connect(effect); |
michael@0 | 32 | effect.connect(sp); |
michael@0 | 33 | |
michael@0 | 34 | sp.onaudioprocess = function(e) { |
michael@0 | 35 | var buffer = e.inputBuffer.getChannelData(0); |
michael@0 | 36 | var rms = 0; |
michael@0 | 37 | for (var i = 0; i < buffer.length; i++) { |
michael@0 | 38 | rms += buffer[i] * buffer[i]; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | rms /= buffer.length; |
michael@0 | 42 | rms = Math.sqrt(rms); |
michael@0 | 43 | |
michael@0 | 44 | // 1 / Math.sqrt(2) is the theoretical RMS value for a sine wave. |
michael@0 | 45 | ok(fuzzyCompare(rms, 1 / Math.sqrt(2)), |
michael@0 | 46 | "Gain correctly applied to the AudioParam."); |
michael@0 | 47 | |
michael@0 | 48 | ctx = null; |
michael@0 | 49 | sp.onaudioprocess = null; |
michael@0 | 50 | lfo.stop(0); |
michael@0 | 51 | source.stop(0); |
michael@0 | 52 | |
michael@0 | 53 | SimpleTest.finish(); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | lfo.start(0); |
michael@0 | 57 | source.start(0); |
michael@0 | 58 | |
michael@0 | 59 | </script> |
michael@0 | 60 | </pre> |
michael@0 | 61 | </body> |