tor-browser

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

silent-inputs.html (2632B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test Silent Inputs to WaveShaperNode
      6    </title>
      7    <script src="/resources/testharness.js"></script>
      8    <script src="/resources/testharnessreport.js"></script>
      9    <script src="/webaudio/resources/audit-util.js"></script>
     10  </head>
     11  <body>
     12    <script>
     13      const sampleRate = 16000;
     14 
     15      // Identity curve for the wave shaper: the input value is mapped directly
     16      // to the output value.
     17      const identityCurve = [-1, 0, 1];
     18      const nonZeroCurve = [0.5, 0.5, 0.5];
     19 
     20      promise_test(async (t) => {
     21        const {context, source, shaper} =
     22            setupGraph(nonZeroCurve, sampleRate, sampleRate);
     23 
     24        source.offset.setValueAtTime(0, 0);
     25 
     26        const audioBuffer = await context.startRendering();
     27 
     28        assert_array_equals(
     29            audioBuffer.getChannelData(0),
     30            new Float32Array(sampleRate).fill(0.5),
     31            'WaveShaper with silent inputs and curve ' +
     32                JSON.stringify(shaper.curve));
     33      }, 'test-0: curve output is non-zero for silent inputs');
     34 
     35      promise_test(async (t) => {
     36        const {context, source, shaper} =
     37            setupGraph(nonZeroCurve, sampleRate, sampleRate);
     38 
     39        source.offset.setValueAtTime(0, 0);
     40        shaper.overSample = '2x';
     41 
     42        const audioBuffer = await context.startRendering();
     43 
     44        assert_array_equals(
     45            audioBuffer.getChannelData(0),
     46            new Float32Array(sampleRate).fill(0.5),
     47            `WaveShaper with ${shaper.overSample} oversample, ` +
     48                `silent inputs, and curve ${JSON.stringify(shaper.curve)}`);
     49      }, 'test-1: 2x curve output is non-zero for silent inputs');
     50 
     51      promise_test(async (t) => {
     52        const {context, source, shaper} =
     53            setupGraph(nonZeroCurve, sampleRate, sampleRate);
     54 
     55        source.disconnect();
     56 
     57        const audioBuffer = await context.startRendering();
     58 
     59        assert_array_equals(
     60            audioBuffer.getChannelData(0),
     61            new Float32Array(sampleRate).fill(0.5),
     62            'WaveShaper with no inputs and curve ' +
     63                JSON.stringify(shaper.curve));
     64      }, 'test-2: curve output is non-zero for no inputs');
     65 
     66      function setupGraph(curve, testFrames, sampleRate) {
     67        const context = new OfflineAudioContext(1, testFrames, sampleRate);
     68        const source = new ConstantSourceNode(context);
     69        const shaper = new WaveShaperNode(context, {curve: curve});
     70 
     71        source.connect(shaper).connect(context.destination);
     72 
     73        return {context: context, source: source, shaper: shaper};
     74      }
     75    </script>
     76  </body>
     77 </html>