tor-browser

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

test_retrospective-setValueAtTime.html (1685B)


      1 <!DOCTYPE html>
      2 <title>Test setValueAtTime with startTime in the past</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script>
      6 function do_test(t, context) {
      7  var source = context.createConstantSource();
      8  source.start();
      9 
     10  // Use a ramp of slope 1/sample to measure time.
     11  // The end value is the extent of exact precision in single precision float.
     12  const rampEnd = Math.pow(2, 24);
     13  const rampEndSeconds = rampEnd / context.sampleRate;
     14  var test = context.createGain();
     15  test.gain.setValueAtTime(0.0, 0.5*context.currentTime);
     16  test.gain.linearRampToValueAtTime(rampEnd, rampEndSeconds);
     17 
     18  var reference = context.createGain();
     19  reference.gain.setValueAtTime(0.0, context.currentTime);
     20  reference.gain.linearRampToValueAtTime(rampEnd, rampEndSeconds);
     21 
     22  source.connect(test);
     23  source.connect(reference);
     24 
     25  var merger = context.createChannelMerger();
     26  test.connect(merger, 0, 0);
     27  reference.connect(merger, 0, 1);
     28 
     29  var processor = context.createScriptProcessor(0, 2, 0);
     30  merger.connect(processor);
     31  processor.onaudioprocess =
     32    t.step_func_done((e) => {
     33      source.stop();
     34      processor.onaudioprocess = null;
     35 
     36      var testValue = e.inputBuffer.getChannelData(0)[0];
     37      var referenceValue = e.inputBuffer.getChannelData(1)[0];
     38 
     39      assert_equals(testValue, referenceValue,
     40                        "ramp value matches expected");
     41    });
     42 }
     43 
     44 async_test(function(t) {
     45  var context = new AudioContext;
     46  (function waitForTimeAdvance() {
     47    if (context.currentTime == 0) {
     48      t.step_timeout(waitForTimeAdvance, 0);
     49    } else {
     50      do_test(t, context);
     51    }
     52  })();
     53 });
     54 </script>