tor-browser

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

test_audioParamChaining.html (2538B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test whether we can create an AudioContext interface</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 <pre id="test">
     10 <script class="testbody" type="text/javascript">
     11 
     12 SimpleTest.waitForExplicitFinish()
     13 
     14 function frameToTime(frame, rate)
     15 {
     16  return frame / rate;
     17 }
     18 
     19 const RATE = 44100;
     20 
     21 var oc = new OfflineAudioContext(1, 44100, RATE);
     22 // This allows us to have a source that is simply a DC offset.
     23 var source = oc.createBufferSource();
     24 var buf = oc.createBuffer(1, 1, RATE);
     25 buf.getChannelData(0)[0] = 1;
     26 source.loop = true;
     27 source.buffer = buf;
     28 
     29 source.start(0);
     30 
     31 var gain = oc.createGain();
     32 
     33 source.connect(gain).connect(oc.destination);
     34 
     35 var gain2 = oc.createGain();
     36 var rv2 = gain2.gain.linearRampToValueAtTime(0.1, 0.5);
     37 ok(rv2 instanceof AudioParam, "linearRampToValueAtTime returns an AudioParam.");
     38 ok(rv2 == gain2.gain, "linearRampToValueAtTime returns the right AudioParam.");
     39 
     40 rv2 = gain2.gain.exponentialRampToValueAtTime(0.01, 1.0);
     41 ok(rv2 instanceof AudioParam,
     42    "exponentialRampToValueAtTime returns an AudioParam.");
     43 ok(rv2 == gain2.gain,
     44    "exponentialRampToValueAtTime returns the right AudioParam.");
     45 
     46 rv2 = gain2.gain.setTargetAtTime(1.0, 2.0, 0.1);
     47 ok(rv2 instanceof AudioParam, "setTargetAtTime returns an AudioParam.");
     48 ok(rv2 == gain2.gain, "setTargetAtTime returns the right AudioParam.");
     49 
     50 var array = new Float32Array(10);
     51 rv2 = gain2.gain.setValueCurveAtTime(array, 10, 11);
     52 ok(rv2 instanceof AudioParam, "setValueCurveAtTime returns an AudioParam.");
     53 ok(rv2 == gain2.gain, "setValueCurveAtTime returns the right AudioParam.");
     54 
     55 // We chain three automation methods, making a gain step.
     56 var rv = gain.gain.setValueAtTime(0, frameToTime(0, RATE))
     57                  .setValueAtTime(0.5, frameToTime(22000, RATE))
     58                  .setValueAtTime(1, frameToTime(44000, RATE));
     59 
     60 ok(rv instanceof AudioParam, "setValueAtTime returns an AudioParam.");
     61 ok(rv == gain.gain, "setValueAtTime returns the right AudioParam.");
     62 
     63 oc.startRendering().then(function(rendered) {
     64    console.log(rendered.getChannelData(0));
     65    is(rendered.getChannelData(0)[0], 0,
     66      "The value of the first step is correct.");
     67    is(rendered.getChannelData(0)[22050], 0.5,
     68      "The value of the second step is correct");
     69    is(rendered.getChannelData(0)[44099], 1,
     70      "The value of the third step is correct.");
     71    SimpleTest.finish();
     72 });
     73 
     74 </script>
     75 </pre>
     76 </body>
     77 </html>