tor-browser

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

audioworklet-audioparam.https.html (2310B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test AudioWorkletNode's basic AudioParam features
      6    </title>
      7    <script src="/resources/testharness.js"></script>
      8    <script src="/resources/testharnessreport.js"></script>
      9  </head>
     10  <body>
     11    <script>
     12      const sampleRate = 48000;
     13      const renderLength = 48000 * 0.6;
     14      const filePath = 'processors/gain-processor.js';
     15 
     16      promise_test(async t => {
     17        const context = new OfflineAudioContext(1, renderLength, sampleRate);
     18        await context.audioWorklet.addModule(filePath);
     19        const constantSourceNode = new ConstantSourceNode(context);
     20        const gainNode = new GainNode(context);
     21        const inverterNode = new GainNode(context, {gain: -1});
     22        const gainWorkletNode = new AudioWorkletNode(context, 'gain');
     23        const gainWorkletParam = gainWorkletNode.parameters.get('gain');
     24 
     25        assert_equals(
     26            gainWorkletParam.value,
     27            Math.fround(0.707),
     28            'Default gain value of gainWorkletNode');
     29        gainWorkletParam.value = 0.1;
     30        assert_equals(
     31            gainWorkletParam.value,
     32            Math.fround(0.1),
     33            'Value of gainWorkletParam after setter = 0.1');
     34 
     35        constantSourceNode.connect(gainNode)
     36            .connect(inverterNode)
     37            .connect(context.destination);
     38        constantSourceNode.connect(gainWorkletNode)
     39            .connect(context.destination);
     40 
     41        [gainNode.gain, gainWorkletParam].forEach(param => {
     42          param.setValueAtTime(0, 0);
     43          param.linearRampToValueAtTime(1, 0.1);
     44          param.exponentialRampToValueAtTime(0.5, 0.2);
     45          param.setValueCurveAtTime([0, 2, 0.3], 0.2, 0.1);
     46          param.setTargetAtTime(0.01, 0.4, 0.5);
     47        });
     48 
     49        context.suspend(0.5).then(() => {
     50          gainNode.gain.value = 1.5;
     51          gainWorkletParam.value = 1.5;
     52          context.resume();
     53        });
     54 
     55        constantSourceNode.start();
     56        const renderedBuffer = await context.startRendering();
     57        const actual = renderedBuffer.getChannelData(0);
     58        assert_array_equals(
     59            actual,
     60            new Float32Array(actual.length),
     61            'The rendered buffer should be constant 0');
     62      }, 'Verifying AudioParam in AudioWorkletNode');
     63    </script>
     64  </body>
     65 </html>