tor-browser

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

audioparam-setValueCurveAtTime.html (3165B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title> AudioParam.setValueCurveAtTime </title>
      5    <script src="/resources/testharness.js"></script>
      6    <script src="/resources/testharnessreport.js"></script>
      7    <script src="/webaudio/resources/audit-util.js"></script>
      8    <script src="/webaudio/resources/audioparam-testing.js"></script>
      9  </head>
     10  <body>
     11    <script>
     12 
     13      // Play a long DC signal out through an AudioGainNode and for each time
     14      // interval call setValueCurveAtTime() to set the values for the duration
     15      // of the interval.  Each curve is a sine wave, and we assume that the
     16      // time interval is not an exact multiple of the period. This causes a
     17      // discontinuity between time intervals which is used to test timing.
     18      const numberOfTests   = 20;
     19      const sineAmplitude   = 1;
     20      const freqHz          = 440;
     21 
     22      // Max allowed difference between the rendered data and the expected
     23      // result. Because of the linear interpolation, the rendered curve isn't
     24      // exactly the same as the reference.  This value is experimentally
     25      // determined.
     26      const maxAllowedError = 3.7194e-6;
     27 
     28      /* global helpers from audioparam-testing.js */
     29      const { timeInterval, sampleRate } = window;
     30 
     31      /* curve used by the automation scheduler */
     32      const curve = createSineWaveArray(
     33          timeInterval, freqHz, sineAmplitude, sampleRate);
     34 
     35      /**
     36       * Minimum required functionality for createAudioGraphAndTest.
     37       */
     38      function should(actual, description) {
     39        return {
     40          beLessThan(expected) {
     41            assert_true(actual < expected,
     42                        `${description}: ${actual}${expected}`);
     43          },
     44          beLessThanOrEqualTo(expected) {
     45            assert_true(actual <= expected,
     46                        `${description}: ${actual} > ${expected}`);
     47          },
     48          beEqualTo(expected) {
     49            assert_equals(actual, expected, description);
     50          },
     51          beTrue() {
     52            assert_true(!!actual, description);
     53          }
     54        };
     55      }
     56 
     57      function automation(value, startTime, endTime) {
     58        /* |value| is unused – mirrors the original test. */
     59        gainNode.gain.setValueCurveAtTime(
     60            curve, startTime, endTime - startTime);
     61      }
     62 
     63      promise_test(() => {
     64        /* Return a real Promise so promise_test is satisfied. */
     65        return new Promise(resolve => {
     66          /* dummy task object exposing only .done() */
     67          const task = { done: resolve };
     68 
     69          /* No value needs to be set at each interval. */
     70          const noopSetValue = () => {};
     71 
     72          createAudioGraphAndTest(
     73              task,
     74              should,
     75              numberOfTests,
     76              sineAmplitude,
     77              noopSetValue,
     78              automation,
     79              'setValueCurveAtTime()',
     80              maxAllowedError,
     81              createReferenceSineArray,
     82              2 * Math.PI * sineAmplitude * freqHz / sampleRate,
     83              differenceErrorMetric);
     84        });
     85      }, 'AudioParam.setValueCurveAtTime() reproduces the expected waveform');
     86    </script>
     87  </body>
     88 </html>