tor-browser

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

retrospective-setTargetAtTime.html (2251B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <html>
      4  <head>
      5    <title>Test setTargetAtTime with start time in the past</title>
      6    <script src="/resources/testharness.js"></script>
      7    <script src="/resources/testharnessreport.js"></script>
      8  </head>
      9  <body>
     10    <script>
     11      const suspendFrame = 128;
     12 
     13      promise_test(async () => {
     14        // Use a sample rate that is a power of two to eliminate round-off
     15        // in computing the currentTime.
     16        const context = new OfflineAudioContext(2, 16384, 16384);
     17        const source = new ConstantSourceNode(context);
     18 
     19        const test = new GainNode(context);
     20        const reference = new GainNode(context);
     21 
     22        source.connect(test);
     23        source.connect(reference);
     24 
     25        const merger = new ChannelMergerNode(
     26            context, {numberOfInputs: context.destination.channelCount});
     27        test.connect(merger, 0, 0);
     28        reference.connect(merger, 0, 1);
     29 
     30        merger.connect(context.destination);
     31 
     32        context.suspend(suspendFrame / context.sampleRate).then(() => {
     33          // Call setTargetAtTime with a time in the past
     34          test.gain.setTargetAtTime(0.1, 0.5*context.currentTime, 0.1);
     35          reference.gain.setTargetAtTime(0.1, context.currentTime, 0.1);
     36          context.resume();
     37        });
     38 
     39        source.start();
     40 
     41        const resultBuffer = await context.startRendering();
     42        const testValue = resultBuffer.getChannelData(0);
     43        const referenceValue = resultBuffer.getChannelData(1);
     44 
     45        // Until the suspendFrame, both should be exactly equal to 1.
     46        assert_array_equals(
     47            testValue.slice(0, suspendFrame),
     48            new Float32Array(suspendFrame).fill(1),
     49            `Test[0:${suspendFrame - 1}]`);
     50        assert_array_equals(
     51            referenceValue.slice(0, suspendFrame),
     52            new Float32Array(suspendFrame).fill(1),
     53            `Reference[0:${suspendFrame - 1}]`);
     54 
     55        // After the suspendFrame, both should be equal (and not constant)
     56        assert_array_equals(
     57            testValue.slice(suspendFrame),
     58            referenceValue.slice(suspendFrame),
     59            `Test[${suspendFrame}:]`);
     60      }, 'Test setTargetAtTime with start time in the past');
     61    </script>
     62  </body>
     63 </html>