tor-browser

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

audiobuffersource-grain.html (2136B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test Start Grain with Delayed Buffer Setting
      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      let context;
     16      let source;
     17      let buffer;
     18      let renderedData;
     19 
     20      let sampleRate = 44100;
     21 
     22      let testDurationSec = 1;
     23      let testDurationSamples = testDurationSec * sampleRate;
     24      let startTime = 0.9 * testDurationSec;
     25 
     26      audit.define(
     27          'Test setting the source buffer after starting the grain',
     28          function(task, should) {
     29            context =
     30                new OfflineAudioContext(1, testDurationSamples, sampleRate);
     31 
     32            buffer = createConstantBuffer(context, testDurationSamples, 1);
     33            source = context.createBufferSource();
     34            source.connect(context.destination);
     35 
     36            // Start the source BEFORE we set the buffer. The grain offset and
     37            // duration aren't important, as long as we specify some offset.
     38            source.start(startTime, .1);
     39            source.buffer = buffer;
     40 
     41            // Render it!
     42            context.startRendering()
     43                .then(function(buffer) {
     44                  checkResult(buffer, should);
     45                })
     46                .then(task.done.bind(task));
     47            ;
     48          });
     49 
     50      function checkResult(buffer, should) {
     51        let success = false;
     52 
     53        renderedData = buffer.getChannelData(0);
     54 
     55        // Check that the rendered data is not all zeroes.  Any non-zero data
     56        // means the test passed.
     57        let startFrame = Math.round(startTime * sampleRate);
     58        for (k = 0; k < renderedData.length; ++k) {
     59          if (renderedData[k]) {
     60            success = true;
     61            break;
     62          }
     63        }
     64 
     65        should(success, 'Buffer was played').beTrue();
     66      }
     67 
     68      audit.run();
     69    </script>
     70  </body>
     71 </html>