tor-browser

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

audiobuffersource-duration-loop.html (1739B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test AudioBufferSourceNode With Looping And Duration
      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/audit.js"></script>
     11  </head>
     12  <body>
     13    <script id="layout-test-code">
     14      let audit = Audit.createTaskRunner();
     15      audit.define('loop with duration', (task, should) => {
     16        // Create the context
     17        let context = new OfflineAudioContext(1, 4096, 48000);
     18 
     19        // Create the sample buffer and fill the second half with 1
     20        let buffer = context.createBuffer(1, 2048, context.sampleRate);
     21        for (let i = 1024; i < 2048; i++) {
     22          buffer.getChannelData(0)[i] = 1;
     23        }
     24 
     25        // Create the source and set its value
     26        let source = context.createBufferSource();
     27        source.loop = true;
     28        source.loopStart = 1024 / context.sampleRate;
     29        source.loopEnd = 2048 / context.sampleRate;
     30        source.buffer = buffer;
     31        source.connect(context.destination);
     32        source.start(0, 1024 / context.sampleRate, 2048 / context.sampleRate);
     33        // Expectations
     34        let expected = new Float32Array(4096);
     35        for (let i = 0; i < 2048; i++) {
     36          expected[i] = 1;
     37        }
     38        // Render it!
     39        context.startRendering()
     40            .then(function(audioBuffer) {
     41              should(
     42                  audioBuffer.getChannelData(0), 'audioBuffer.getChannelData')
     43                  .beEqualToArray(expected);
     44            })
     45            .then(task.done.bind(task));
     46      });
     47 
     48      audit.run();
     49 
     50    </script>
     51  </body>
     52 </html>