tor-browser

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

active-processing.https.html (3162B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <title>
      5    Test Active Processing for AudioBufferSourceNode
      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    // Arbitrary sample rate. And we only new a few blocks for rendering to
     14    // see if things are working.
     15    const sampleRate = 8000;
     16    const renderLength = 10 * RENDER_QUANTUM_FRAMES;
     17 
     18    // Offline context used for the tests.
     19    let context;
     20 
     21    // Number of channels for the AudioBufferSource. Fairly arbitrary, but
     22    // should be more than 2.
     23    const numberOfChannels = 7;
     24 
     25    // Number of frames in the AudioBuffer.  Fairly arbitrary, but should
     26    // probably be more than one render quantum and significantly less than
     27    // |renderLength|.
     28    const bufferFrames = 131;
     29 
     30    const filePath =
     31        '../the-audioworklet-interface/processors/input-count-processor.js';
     32 
     33    promise_test(async (t) => {
     34      context = new OfflineAudioContext(
     35          numberOfChannels, renderLength, sampleRate);
     36 
     37      await context.audioWorklet.addModule(filePath);
     38      const buffer = new AudioBuffer({
     39        numberOfChannels: numberOfChannels,
     40        length: bufferFrames,
     41        sampleRate: context.sampleRate
     42      });
     43 
     44      const src = new AudioBufferSourceNode(context, {buffer});
     45      const counter = new AudioWorkletNode(context, 'counter');
     46 
     47      src.connect(counter).connect(context.destination);
     48      src.start();
     49    }, 'Setup graph with AudioWorklet and AudioBufferSourceNode');
     50 
     51    promise_test(async () => {
     52      const renderedBuffer = await context.startRendering();
     53      const output = renderedBuffer.getChannelData(0);
     54 
     55      // Find the first time the number of channels changes to 0.
     56      const countChangeIndex = output.findIndex(x => x == 0);
     57 
     58      // Verify that the count did change.  If it didn't there's a bug
     59      // in the implementation, or it takes longer than the render
     60      // length to change.  For the latter case, increase the render
     61      // length, but it can't be arbitrarily large.  The change needs to
     62      // happen at some reasonable time after the source stops.
     63      assert_greater_than_equal(countChangeIndex, 0,
     64          'Number of channels changed');
     65      assert_less_than_equal(countChangeIndex, renderLength,
     66          'Index where input channel count changed');
     67 
     68      // Verify the number of channels at the beginning matches the
     69      // number of channels in the AudioBuffer.
     70      assert_array_equals(
     71          output.slice(0, countChangeIndex),
     72          new Float32Array(countChangeIndex).fill(numberOfChannels),
     73          `Number of channels in input[0:${countChangeIndex - 1}]`);
     74 
     75      // Verify that after the source has stopped, the number of
     76      // channels is 0.
     77      assert_array_equals(
     78          output.slice(countChangeIndex),
     79          new Float32Array(renderLength - countChangeIndex),
     80          `Number of channels in input[${countChangeIndex}:]`);
     81    }, 'Verify input channel count change after AudioBufferSourceNode stops');
     82  </script>
     83 </body>
     84 </html>