summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_pannerNode_maxDistance.html
blob: bb70b0a0eca6a907703fdbb359f935f9fb03a978 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test PannerNode outputs silence when the distance is greater than maxDist</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="webaudio.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

// BUF_SIZE must be greater than HRTF delay.
const BUF_SIZE = 1024;
const sampleRate = 44100;
var types = [
  "equalpower",
  "HRTF"
]

async function test(panningModel) {
  var ac = new OfflineAudioContext(1, 1024, sampleRate);
  var osc = ac.createOscillator();
  var panner = new PannerNode(ac, {
    panningModel,
    distanceModel: "linear",
    maxDistance: 100,
    positionY: 200,
  });

  ac.listener.setPosition(0, 0, 0);

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

  osc.start();

  const buffer = await ac.startRendering()

  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.");
}

add_task(async function() {
  await promiseHRTFReady(sampleRate);
  for (const panningModel of types) {
    await test(panningModel);
  }
});

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