tor-browser

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

test-analyser-scale.html (1339B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test AnalyserNode when the input is scaled</title>
      6  <script src="/resources/testharness.js"></script>
      7  <script src="/resources/testharnessreport.js"></script>
      8  <script>
      9    setup({ single_test: true });
     10 
     11    var context = new AudioContext();
     12 
     13    var gain = context.createGain();
     14    var analyser = context.createAnalyser();
     15    var osc = context.createOscillator();
     16 
     17    osc.connect(gain);
     18    gain.connect(analyser);
     19 
     20    osc.start();
     21 
     22    var array = new Uint8Array(analyser.frequencyBinCount);
     23 
     24    function getAnalyserData() {
     25      gain.gain.setValueAtTime(currentGain, context.currentTime);
     26      analyser.getByteTimeDomainData(array);
     27      var inrange = true;
     28      var max = -1;
     29      for (var i = 0; i < array.length; i++) {
     30        if (array[i] > max) {
     31          max = Math.abs(array[i] - 128);
     32        }
     33      }
     34      if (max <= currentGain * 128) {
     35        assert_true(true, "Analyser got scaled data for " + currentGain);
     36        currentGain = tests.shift();
     37        if (currentGain == undefined) {
     38          done();
     39          return;
     40        }
     41      }
     42      requestAnimationFrame(getAnalyserData);
     43    }
     44 
     45    var tests = [1.0, 0.5, 0.0];
     46    var currentGain = tests.shift();
     47    requestAnimationFrame(getAnalyserData);
     48  </script>
     49 </head>
     50 </body>
     51 </html>