tor-browser

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

audiochannelmerger-disconnect.html (2690B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      ChannelMergerNode: Asynchronous disconnect() correctly silences the
      6      output
      7    </title>
      8    <script src="/resources/testharness.js"></script>
      9    <script src="/resources/testharnessreport.js"></script>
     10    <script src="/webaudio/resources/audit-util.js"></script>
     11  </head>
     12  <body>
     13    <script>
     14      const renderQuantum = 128;
     15      const numberOfChannels = 2;
     16      const sampleRate = 44100;
     17      const renderDuration = 0.5;
     18      const disconnectTime = 0.5 * renderDuration;
     19 
     20      // Task: Check if the merger outputs a silent channel when an input is
     21      // disconnected.
     22      promise_test(async () => {
     23        const context = new OfflineAudioContext(
     24            numberOfChannels, renderDuration * sampleRate, sampleRate);
     25        const merger = new ChannelMergerNode(context, {numberOfInputs: 6});
     26        const source1 = new ConstantSourceNode(context, {offset: 1.0});
     27        const source2 = new ConstantSourceNode(context, {offset: 1.0});
     28 
     29        // Connect the sources to the first two inputs of the merger.
     30        // The merger should produce 6 channel output.
     31        source1.connect(merger, 0, 0);
     32        source2.connect(merger, 0, 1);
     33        merger.connect(context.destination);
     34        source1.start();
     35        source2.start();
     36 
     37        // Schedule the disconnection of |source2| at the half of render
     38        // duration.
     39        context.suspend(disconnectTime).then(() => {
     40          source2.disconnect();
     41          context.resume();
     42        });
     43 
     44        const resultBuffer = await context.startRendering();
     45        // The entire first channel of the output should be 1.
     46        assert_constant_value(
     47            resultBuffer.getChannelData(0), 1, 'Channel #0 should be 1.');
     48 
     49        // Calculate the first zero index in the second channel.
     50        const channel1 = resultBuffer.getChannelData(1);
     51        let disconnectIndex = disconnectTime * sampleRate;
     52        disconnectIndex = renderQuantum *
     53            Math.floor((disconnectIndex + renderQuantum - 1) / renderQuantum);
     54 
     55        const firstZeroIndex =
     56            channel1.findIndex(element => element === 0);
     57 
     58        // The second channel should contain 1, and 0 after the
     59        // disconnection.
     60        assert_constant_value(channel1.subarray(0, disconnectIndex), 1,
     61            'Channel #1 before disconnect');
     62        assert_constant_value(channel1.subarray(disconnectIndex), 0,
     63            'Channel #1 after disconnect');
     64 
     65        assert_equals(firstZeroIndex, disconnectIndex,
     66            'The index of first zero in the channel #1');
     67      }, 'Asynchronous disconnect() correctly silences the output');
     68    </script>
     69  </body>
     70 </html>