tor-browser

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

audiobuffersource-multi-channels.html (2130B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test AudioBufferSourceNode supports 5.1 channel playback
      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    <script src="/webaudio/resources/mix-testing.js"></script>
     11  </head>
     12  <body>
     13    <script>
     14      // Test AudioBufferSourceNode supports 5.1 channel.
     15      // Creating context and fetching expected audio.
     16      promise_test(async () => {
     17        const sampleRate = 44100.0;
     18        const context = new OfflineAudioContext(
     19            6, sampleRate * toneLengthSeconds, sampleRate);
     20 
     21        let expectedAudio;
     22 
     23        const response = await fetch(
     24            'resources/audiobuffersource-multi-channels-expected.wav');
     25        const arrayBuffer = await response.arrayBuffer();
     26        try {
     27          expectedAudio = await context.decodeAudioData(arrayBuffer);
     28        } catch (error) {
     29          assert_unreached(
     30              `Could not decode audio data due to ${error.message}`);
     31        }
     32 
     33        // Render and verify output.
     34        const toneBuffer = createToneBuffer(context, 440, toneLengthSeconds, 6);
     35        const source = new AudioBufferSourceNode(context, {buffer:toneBuffer});
     36 
     37        source.connect(context.destination);
     38        source.start();
     39 
     40        const renderedAudio = await context.startRendering();
     41 
     42        // Compute a threshold based on the maximum error, |maxUlp|,
     43        // in ULP. This is experimentally determined. Assuming that
     44        // the reference file is a 16-bit wav file, the max values in
     45        // the wave file are +/- 32768.
     46        const maxUlp = 1;
     47        const threshold = maxUlp / 32768;
     48        for (let k = 0; k < renderedAudio.numberOfChannels; ++k) {
     49          assert_array_approx_equals(
     50              renderedAudio.getChannelData(k),
     51              expectedAudio.getChannelData(k),
     52              threshold,
     53              `Rendered audio for channel ${k}`);
     54        }
     55      }, 'AudioBufferSourceNode 5.1 channel playback verification');
     56    </script>
     57  </body>
     58 </html>