tor-browser

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

test_analyserScale.html (1421B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test AnalyserNode when the input is scaled </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 addLoadEvent(function() {
     15 
     16  var context = new AudioContext();
     17 
     18  var gain = context.createGain();
     19  var analyser = context.createAnalyser();
     20  var osc = context.createOscillator();
     21 
     22 
     23  osc.connect(gain);
     24  gain.connect(analyser);
     25 
     26  osc.start();
     27 
     28  var array = new Uint8Array(analyser.frequencyBinCount);
     29 
     30  function getAnalyserData() {
     31    gain.gain.setValueAtTime(currentGain, context.currentTime);
     32    analyser.getByteTimeDomainData(array);
     33    var max = -1;
     34    for (var i = 0; i < array.length; i++) {
     35      if (array[i] > max) {
     36        max = Math.abs(array[i] - 128);
     37      }
     38    }
     39    if (max <= currentGain * 128) {
     40      ok(true, "Analyser got scaled data for " + currentGain);
     41      currentGain = tests.shift();
     42      if (currentGain == undefined) {
     43        SimpleTest.finish();
     44        return;
     45      }
     46    }
     47    requestAnimationFrame(getAnalyserData);
     48  }
     49 
     50  var tests = [1.0, 0.5, 0.0];
     51  var currentGain = tests.shift();
     52  requestAnimationFrame(getAnalyserData);
     53 });
     54 
     55 </script>
     56 </pre>
     57 </body>
     58 </html>