tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_audioParamGain.html (1508B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test AudioParam with pre-gain </title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script type="text/javascript" src="webaudio.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <pre id="test">
     11 <script class="testbody" type="text/javascript">
     12 
     13 SimpleTest.waitForExplicitFinish();
     14 
     15 var ctx = new AudioContext();
     16 var source = ctx.createOscillator();
     17 var lfo = ctx.createOscillator();
     18 var lfoIntensity = ctx.createGain();
     19 var effect = ctx.createGain();
     20 var sp = ctx.createScriptProcessor(2048, 1);
     21 
     22 source.frequency.value = 440;
     23 lfo.frequency.value = 2;
     24 // Very low gain, so the LFO should have very little influence
     25 // on the source, its RMS value should be close to the nominal value
     26 // for a sine wave.
     27 lfoIntensity.gain.value = 0.0001;
     28 
     29 lfo.connect(lfoIntensity);
     30 lfoIntensity.connect(effect.gain);
     31 source.connect(effect);
     32 effect.connect(sp);
     33 
     34 sp.onaudioprocess = function(e) {
     35  var buffer = e.inputBuffer.getChannelData(0);
     36  var rms = 0;
     37  for (var i = 0; i < buffer.length; i++) {
     38    rms += buffer[i] * buffer[i];
     39  }
     40 
     41  rms /= buffer.length;
     42  rms = Math.sqrt(rms);
     43 
     44  // 1 / Math.sqrt(2) is the theoretical RMS value for a sine wave.
     45  ok(fuzzyCompare(rms, 1 / Math.sqrt(2)),
     46      "Gain correctly applied to the AudioParam.");
     47 
     48  ctx = null;
     49  sp.onaudioprocess = null;
     50  lfo.stop(0);
     51  source.stop(0);
     52 
     53  SimpleTest.finish();
     54 }
     55 
     56 lfo.start(0);
     57 source.start(0);
     58 
     59 </script>
     60 </pre>
     61 </body>