tor-browser

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

note-grain-on-play.html (3102B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      note-grain-on-play.html
      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/note-grain-on-testing.js"></script>
     11  </head>
     12  <body>
     13    <div id="description"></div>
     14    <div id="console"></div>
     15    <script>
     16      // To test noteGrainOn, a single ramp signal is created.
     17      // Various sections of the ramp are rendered by noteGrainOn() at
     18      // different times, and we verify that the actual output
     19      // consists of the correct section of the ramp at the correct
     20      // time.
     21 
     22      let linearRampBuffer;
     23 
     24      // Array of the grain offset used for each ramp played.
     25      let grainOffsetTime = [];
     26 
     27      // Verify the received signal is a ramp from the correct section
     28      // of our ramp signal.
     29      function verifyGrain(renderedData, startFrame, endFrame, grainIndex) {
     30        const grainOffsetFrame =
     31            timeToSampleFrame(grainOffsetTime[grainIndex], sampleRate);
     32        const grainFrameLength = endFrame - startFrame;
     33        const ramp = linearRampBuffer.getChannelData(0);
     34        let isCorrect = true;
     35 
     36        let expected;
     37        let actual;
     38        let frame;
     39 
     40        for (let k = 0; k < grainFrameLength; ++k) {
     41          if (renderedData[startFrame + k] != ramp[grainOffsetFrame + k]) {
     42            expected = ramp[grainOffsetFrame + k];
     43            actual = renderedData[startFrame + k];
     44            frame = startFrame + k;
     45            isCorrect = false;
     46            break;
     47          }
     48        }
     49        return {
     50          verified: isCorrect,
     51          expected: expected,
     52          actual: actual,
     53          frame: frame,
     54        };
     55      }
     56 
     57      function checkResult(buffer) {
     58        renderedData = buffer.getChannelData(0);
     59        const startEndFrames = findStartAndEndSamples(renderedData);
     60 
     61        verifyStartAndEndFrames_W3CTH(startEndFrames);
     62 
     63        for (let k = 0; k < startEndFrames.start.length; ++k) {
     64          const result =
     65              verifyGrain(
     66                  renderedData, startEndFrames.start[k],
     67                  startEndFrames.end[k], k);
     68          assert_true(
     69              result.verified,
     70              `Pulse ${k} contained the expected data. Frame: ${result.frame}` +
     71                  ` Expected: ${result.expected} Actual: ${result.actual}`);
     72        }
     73      }
     74 
     75      promise_test(async (t) => {
     76        context =
     77            new OfflineAudioContext(2, sampleRate * renderTime, sampleRate);
     78 
     79        // Use a linear ramp for testing noteGrainOn(). The ramp to start
     80        // with 1, not 0.
     81        linearRampBuffer = createSignalBuffer(context, (k) => k + 1);
     82 
     83        const grainInfo =
     84            playAllGrains(context, linearRampBuffer, numberOfTests);
     85 
     86        grainOffsetTime = grainInfo.grainOffsetTimes;
     87 
     88        const renderedBuffer = await context.startRendering();
     89        checkResult(renderedBuffer);
     90      }, 'Test noteGrainOn offset rendering');
     91    </script>
     92  </body>
     93 </html>