tor-browser

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

test_analyserNode.html (6620B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test AnalyserNode</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script type="text/javascript" src="webaudio.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <pre id="test">
     11 <script class="testbody" type="text/javascript">
     12 
     13 function testNode() {
     14  var context = new AudioContext();
     15  var buffer = context.createBuffer(1, 2048, context.sampleRate);
     16  for (var i = 0; i < 2048; ++i) {
     17    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
     18  }
     19 
     20  var destination = context.destination;
     21 
     22  var source = context.createBufferSource();
     23 
     24  var analyser = context.createAnalyser();
     25 
     26  source.buffer = buffer;
     27 
     28  source.connect(analyser);
     29  analyser.connect(destination);
     30 
     31  is(analyser.channelCount, 2, "analyser node has 2 input channels by default");
     32  is(analyser.channelCountMode, "max", "Correct channelCountMode for the analyser node");
     33  is(analyser.channelInterpretation, "speakers", "Correct channelCountInterpretation for the analyser node");
     34 
     35  is(analyser.fftSize, 2048, "Correct default value for fftSize");
     36  is(analyser.frequencyBinCount, 1024, "Correct default value for frequencyBinCount");
     37  expectException(function() {
     38    analyser.fftSize = 0;
     39  }, DOMException.INDEX_SIZE_ERR);
     40  expectException(function() {
     41    analyser.fftSize = 1;
     42  }, DOMException.INDEX_SIZE_ERR);
     43  expectException(function() {
     44    analyser.fftSize = 8;
     45  }, DOMException.INDEX_SIZE_ERR);
     46  expectException(function() {
     47    analyser.fftSize = 100; // non-power of two
     48  }, DOMException.INDEX_SIZE_ERR);
     49  expectException(function() {
     50    analyser.fftSize = 2049;
     51  }, DOMException.INDEX_SIZE_ERR);
     52  expectException(function() {
     53    analyser.fftSize = 4097;
     54  }, DOMException.INDEX_SIZE_ERR);
     55  expectException(function() {
     56    analyser.fftSize = 8193;
     57  }, DOMException.INDEX_SIZE_ERR);
     58  expectException(function() {
     59    analyser.fftSize = 16385;
     60  }, DOMException.INDEX_SIZE_ERR);
     61  expectException(function() {
     62    analyser.fftSize = 32769;
     63  }, DOMException.INDEX_SIZE_ERR);
     64  expectException(function() {
     65    analyser.fftSize = 65536;
     66  }, DOMException.INDEX_SIZE_ERR);
     67  analyser.fftSize = 1024;
     68  is(analyser.frequencyBinCount, 512, "Correct new value for frequencyBinCount");
     69 
     70  is(analyser.minDecibels, -100, "Correct default value for minDecibels");
     71  is(analyser.maxDecibels, -30, "Correct default value for maxDecibels");
     72  expectException(function() {
     73    analyser.minDecibels = -30;
     74  }, DOMException.INDEX_SIZE_ERR);
     75  expectException(function() {
     76    analyser.minDecibels = -29;
     77  }, DOMException.INDEX_SIZE_ERR);
     78  expectException(function() {
     79    analyser.maxDecibels = -100;
     80  }, DOMException.INDEX_SIZE_ERR);
     81  expectException(function() {
     82    analyser.maxDecibels = -101;
     83  }, DOMException.INDEX_SIZE_ERR);
     84 
     85  ok(Math.abs(analyser.smoothingTimeConstant - 0.8) < 0.001, "Correct default value for smoothingTimeConstant");
     86  expectException(function() {
     87    analyser.smoothingTimeConstant = -0.1;
     88  }, DOMException.INDEX_SIZE_ERR);
     89  expectException(function() {
     90    analyser.smoothingTimeConstant = 1.1;
     91  }, DOMException.INDEX_SIZE_ERR);
     92  analyser.smoothingTimeConstant = 0;
     93  analyser.smoothingTimeConstant = 1;
     94 }
     95 
     96 function testConstructor() {
     97  var context = new AudioContext();
     98 
     99  var analyser = new AnalyserNode(context);
    100  is(analyser.channelCount, 2, "analyser node has 2 input channels by default");
    101  is(analyser.channelCountMode, "max", "Correct channelCountMode for the analyser node");
    102  is(analyser.channelInterpretation, "speakers", "Correct channelCountInterpretation for the analyser node");
    103 
    104  is(analyser.fftSize, 2048, "Correct default value for fftSize");
    105  is(analyser.frequencyBinCount, 1024, "Correct default value for frequencyBinCount");
    106  is(analyser.minDecibels, -100, "Correct default value for minDecibels");
    107  is(analyser.maxDecibels, -30, "Correct default value for maxDecibels");
    108  ok(Math.abs(analyser.smoothingTimeConstant - 0.8) < 0.001, "Correct default value for smoothingTimeConstant");
    109 
    110  expectException(function() {
    111    analyser = new AnalyserNode(context, { fftSize: 0 });
    112  }, DOMException.INDEX_SIZE_ERR);
    113  expectException(function() {
    114    analyser = new AnalyserNode(context, { fftSize: 1 });
    115  }, DOMException.INDEX_SIZE_ERR);
    116  expectException(function() {
    117    analyser = new AnalyserNode(context, { fftSize: 8 });
    118  }, DOMException.INDEX_SIZE_ERR);
    119  expectException(function() {
    120    analyser = new AnalyserNode(context, { fftSize: 100 }); // non-power of two
    121  }, DOMException.INDEX_SIZE_ERR);
    122  expectException(function() {
    123    analyser = new AnalyserNode(context, { fftSize: 2049 });
    124  }, DOMException.INDEX_SIZE_ERR);
    125  expectException(function() {
    126    analyser = new AnalyserNode(context, { fftSize: 4097 });
    127  }, DOMException.INDEX_SIZE_ERR);
    128  expectException(function() {
    129    analyser = new AnalyserNode(context, { fftSize: 8193 });
    130  }, DOMException.INDEX_SIZE_ERR);
    131  expectException(function() {
    132    analyser = new AnalyserNode(context, { fftSize: 16385 });
    133  }, DOMException.INDEX_SIZE_ERR);
    134  expectException(function() {
    135    analyser = new AnalyserNode(context, { fftSize: 32769 });
    136  }, DOMException.INDEX_SIZE_ERR);
    137  expectException(function() {
    138    analyser = new AnalyserNode(context, { fftSize: 65536 });
    139  }, DOMException.INDEX_SIZE_ERR);
    140  analyser = new AnalyserNode(context, { fftSize: 1024 });
    141  is(analyser.frequencyBinCount, 512, "Correct new value for frequencyBinCount");
    142 
    143  expectException(function() {
    144    analyser = new AnalyserNode(context, { minDecibels: -30 });
    145  }, DOMException.INDEX_SIZE_ERR);
    146  expectException(function() {
    147    analyser = new AnalyserNode(context, { minDecibels: -29 });
    148  }, DOMException.INDEX_SIZE_ERR);
    149  expectException(function() {
    150    analyser = new AnalyserNode(context, { maxDecibels: -100 });
    151  }, DOMException.INDEX_SIZE_ERR);
    152  expectException(function() {
    153    analyser = new AnalyserNode(context, { maxDecibels: -101 });
    154  }, DOMException.INDEX_SIZE_ERR);
    155 
    156  expectException(function() {
    157    analyser = new AnalyserNode(context, { smoothingTimeConstant: -0.1 });
    158  }, DOMException.INDEX_SIZE_ERR);
    159  expectException(function() {
    160    analyser = new AnalyserNode(context, { smoothingTimeConstant: -1.1 });
    161  }, DOMException.INDEX_SIZE_ERR);
    162  analyser = new AnalyserNode(context, { smoothingTimeConstant: 0 });
    163  analyser = new AnalyserNode(context, { smoothingTimeConstant: 1 });
    164 }
    165 
    166 SimpleTest.waitForExplicitFinish();
    167 addLoadEvent(function() {
    168 
    169  testNode();
    170  testConstructor();
    171 
    172  SimpleTest.finish();
    173 });
    174 
    175 </script>
    176 </pre>
    177 </body>
    178 </html>