summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_pannerNode_maxDistance.html
blob: b5286e56e1a9601022c7f56ebaea54c53bdf8b0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE HTML>
<html>
<head>
  <title>Test PannerNode outputs silence when the distance is greater than maxDist</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

var types = [
  "equalpower",
  "HRTF"
]

var finished = types.length;

function finish() {
  if (!--finished) {
    SimpleTest.finish();
  }
}

function test(type) {
  var ac = new OfflineAudioContext(1, 128, 44100);
  var osc = ac.createOscillator();
  var panner = ac.createPanner();

  panner.distanceModel = "linear";
  panner.maxDistance = 100;
  panner.positionY.value = 200;
  ac.listener.setPosition(0, 0, 0);

  osc.connect(panner);
  panner.connect(ac.destination);

  osc.start();

  ac.startRendering().then(function(buffer) {
    var silence = true;
    var array = buffer.getChannelData(0);
    for (var i = 0; i < buffer.length; i++) {
      if (array[i] != 0) {
        ok(false, "Found noise in the buffer.");
        silence = false;
      }
    }
    ok(silence, "The buffer is silent.");
    finish();
  });
}


addLoadEvent(function() {
  types.forEach(test);
});

SimpleTest.waitForExplicitFinish();

</script>
</pre>
</body>
</html>