tor-browser

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

panner-rolloff-clamping.html (3248B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test Clamping of PannerNode rolloffFactor
      6    </title>
      7    <script src="/resources/testharness.js"></script>
      8    <script src="/resources/testharnessreport.js"></script>
      9  </head>
     10  <body>
     11    <script>
     12      // Fairly arbitrary sample rate and render frames.
     13      const sampleRate = 16000;
     14      const renderFrames = 2048;
     15 
     16      // Test clamping of the rolloffFactor.  The test is done by comparing the
     17      // output of a panner with the rolloffFactor set outside the nominal range
     18      // against the output of a panner with the rolloffFactor clamped to the
     19      // nominal range.  The outputs should be the same.
     20      //
     21      // The |options| dictionary should contain the members
     22      //   distanceModel  - The distance model to use for the panners
     23      //   rolloffFactor  - The desired rolloffFactor.  Should be outside the
     24      //                    nominal range of the distance model.
     25      //   clampedRolloff - The rolloffFactor (above) clamped to the nominal
     26      //                    range for the given distance model.
     27      const runTest = async (options) => {
     28        // Offline context with two channels.  The first channel is the panner
     29        // node under test.  The second channel is the reference panner node.
     30        const context = new OfflineAudioContext(2, renderFrames, sampleRate);
     31 
     32        // The source for the panner nodes.  This is fairly arbitrary.
     33        const src = new OscillatorNode(context, {type: 'sawtooth'});
     34 
     35        // Create the test panner with the specified rolloff factor.  The
     36        // position is fairly arbitrary, but something that is not the default
     37        // is good to show the distance model had some effect.
     38        const pannerTest = new PannerNode(context, {
     39          rolloffFactor: options.rolloffFactor,
     40          distanceModel: options.distanceModel,
     41          positionX: 5000
     42        });
     43 
     44        // Create the reference panner with the rolloff factor clamped to the
     45        // appropriate limit.
     46        const pannerRef = new PannerNode(context, {
     47          rolloffFactor: options.clampedRolloff,
     48          distanceModel: options.distanceModel,
     49          positionX: 5000
     50        });
     51 
     52 
     53        // Connect the source to the panners to the destination appropriately.
     54        const merger = new ChannelMergerNode(context, {numberOfInputs: 2});
     55 
     56 
     57        src.connect(pannerTest).connect(merger, 0, 0);
     58        src.connect(pannerRef).connect(merger, 0, 1);
     59 
     60        merger.connect(context.destination);
     61 
     62        src.start();
     63 
     64        const resultBuffer = await context.startRendering();
     65        // The two channels should be the same due to the clamping.  Verify
     66        // that they are the same.
     67        const actual = resultBuffer.getChannelData(0);
     68        const expected = resultBuffer.getChannelData(1);
     69        const message = `Panner distanceModel: "${options.distanceModel}", ` +
     70            `rolloffFactor: ${options.rolloffFactor}`;
     71        assert_array_equals(actual, expected, message);
     72      };
     73      promise_test(() => runTest({
     74        distanceModel: 'linear',
     75        rolloffFactor: 2,
     76        clampedRolloff: 1
     77      }), 'rolloffFactor clamping for linear distance model');
     78    </script>
     79  </body>
     80 </html>