summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_biquadFilterNodeWithGain.html
blob: d97a753de95b80849b8f2285be515491a7463737 (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 BiquadFilterNode after a GainNode and tail - Bugs 924286 and 924288</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 src="webaudio.js" type="text/javascript"></script>
<script class="testbody" type="text/javascript">

const signalLength = 2048;

var gTest = {
  length: signalLength,
  numberOfChannels: 1,
  createGraph(context) {
    // Two oscillators scheduled sequentially
    var signalDuration = signalLength / context.sampleRate;
    var osc1 = context.createOscillator();
    osc1.type = "square";
    osc1.start(0);
    osc1.stop(signalDuration / 2);
    var osc2 = context.createOscillator();
    osc2.start(signalDuration / 2);
    osc2.stop(signalDuration);

    // Comparing a biquad on each source with one on both sources checks that
    // the biquad on the first source doesn't shut down early.
    var biquad1 = context.createBiquadFilter();
    osc1.connect(biquad1);
    var biquad2 = context.createBiquadFilter();
    osc2.connect(biquad2);

    var gain = context.createGain();
    gain.gain.value = -1;
    osc1.connect(gain);
    osc2.connect(gain);

    var biquadWithGain = context.createBiquadFilter();
    gain.connect(biquadWithGain);

    // The output of biquadWithGain should be the inverse of the sum of the
    // outputs of biquad1 and biquad2, so blend them together and expect
    // silence.
    var blend = context.createGain();
    biquad1.connect(blend);
    biquad2.connect(blend);
    biquadWithGain.connect(blend);

    return blend;
  },
};

runTest();

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