tor-browser

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

panner-azimuth.html (1603B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>Test Panner Azimuth Calculation</title>
      5    <script src="/resources/testharness.js"></script>
      6    <script src="/resources/testharnessreport.js"></script>
      7    <script src="../../resources/audit.js"></script>
      8  </head>
      9 
     10  <body>
     11    <script>
     12      const audit = Audit.createTaskRunner();
     13 
     14      // Fairly arbitrary sample rate
     15      const sampleRate = 16000;
     16 
     17      audit.define('Azimuth calculation', (task, should) => {
     18        // Two channels for the context so we can see each channel of the
     19        // panner node.
     20        let context = new OfflineAudioContext(2, sampleRate, sampleRate);
     21 
     22        let src = new ConstantSourceNode(context);
     23        let panner = new PannerNode(context);
     24 
     25        src.connect(panner).connect(context.destination);
     26 
     27        // The source is still pointed directly at the listener, but is now
     28        // directly above.  The audio should be the same in both the left and
     29        // right channels.
     30        panner.positionY.value = 1;
     31 
     32        src.start();
     33 
     34        context.startRendering()
     35            .then(audioBuffer => {
     36              // The left and right channels should contain the same signal.
     37              let c0 = audioBuffer.getChannelData(0);
     38              let c1 = audioBuffer.getChannelData(1);
     39 
     40              let expected = Math.fround(Math.SQRT1_2);
     41 
     42              should(c0, 'Left channel').beConstantValueOf(expected);
     43              should(c1, 'Righteft channel').beConstantValueOf(expected);
     44            })
     45            .then(() => task.done());
     46      });
     47 
     48      audit.run();
     49    </script>
     50  </body>
     51 </html>