tor-browser

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

delay-test.html (1998B)


      1 <!doctype html>
      2 <html>
      3  <head>
      4    <title>Test DelayNode Delay</title>
      5    <script src="/resources/testharness.js"></script>
      6    <script src="/resources/testharnessreport.js"></script>
      7    <script src="/webaudio/resources/audit-util.js"></script>
      8    <script src="/webaudio/resources/audit.js"></script>
      9  </head>
     10 
     11  <body>
     12    <script>
     13      let audit = Audit.createTaskRunner();
     14 
     15      audit.define(
     16          {label: 'test0', description: 'Test delay of 3 frames'},
     17          async (task, should) => {
     18            // Only need a few outputs samples.  The sample rate is arbitrary.
     19            const context =
     20                new OfflineAudioContext(1, RENDER_QUANTUM_FRAMES, 8192);
     21            let src;
     22            let delay;
     23 
     24            should(
     25                () => {
     26                  src = new ConstantSourceNode(context);
     27                  delay = new DelayNode(context);
     28                },
     29                'Creating ConstantSourceNode(context) and DelayNode(context)')
     30                .notThrow();
     31 
     32            // The number of frames to delay for the DelayNode.  Should be a
     33            // whole number, but is otherwise arbitrary.
     34            const delayFrames = 3;
     35 
     36            should(() => {
     37              delay.delayTime.value = delayFrames / context.sampleRate;
     38            }, `Setting delayTime to ${delayFrames} frames`).notThrow();
     39 
     40            src.connect(delay).connect(context.destination);
     41 
     42            src.start();
     43 
     44            let buffer = await context.startRendering();
     45            let output = buffer.getChannelData(0);
     46 
     47            // Verify output was delayed the correct number of frames.
     48            should(output.slice(0, delayFrames), `output[0:${delayFrames - 1}]`)
     49                .beConstantValueOf(0);
     50            should(
     51                output.slice(delayFrames),
     52                `output[${delayFrames}:${output.length - 1}]`)
     53                .beConstantValueOf(1);
     54 
     55            task.done();
     56          });
     57 
     58      audit.run();
     59    </script>
     60  </body>
     61 </html>