summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_convolverNodeFiniteInfluence.html
blob: 1cfb51ce8a27b2dae5e97ca6b6aae3a95324ea72 (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
<!DOCTYPE html>
<title>Test convolution effect has finite duration</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(function() {

  const responseLength = 256;
  // Accept an influence period of twice the responseLength to accept FFT
  // implementations.
  const tolerancePeriod = 2 * responseLength;
  const totalSize = tolerancePeriod + responseLength;

  var context = new OfflineAudioContext(1, totalSize, 48000);

  var responseBuffer =
    context.createBuffer(1, responseLength, context.sampleRate);
  var responseChannelData = responseBuffer.getChannelData(0);
  responseChannelData[0] = 1;
  responseChannelData[responseLength - 1] = 1;
  var convolver = context.createConvolver();
  convolver.buffer = responseBuffer;
  convolver.connect(context.destination);

  var sourceBuffer = context.createBuffer(1, totalSize, context.sampleRate);
  sourceBuffer.getChannelData(0)[0] = NaN;
  var source = context.createBufferSource();
  source.buffer = sourceBuffer;
  source.connect(convolver);
  source.start();

  return context.startRendering().
    then((buffer) => {
      var convolverOutput = buffer.getChannelData(0);
      // There should be no non-zeros after the tolerance period.
      var testIndex = tolerancePeriod;
      for (;
           testIndex < buffer.length - 1 && convolverOutput[testIndex] == 0;
           ++testIndex) {
      }
      assert_equals(convolverOutput[testIndex], 0, "output at " + testIndex);
    });
});
</script>