summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_nodeToParamConnection.html
blob: 8a77e7d0a2e3622e8ac73f0745c55938c1cfc47c (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test connecting an AudioNode to an AudioParam</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" 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">

var gTest = {
  length: 2048,
  createGraph(context) {
    var sourceBuffer = context.createBuffer(2, 2048, context.sampleRate);
    for (var i = 0; i < 2048; ++i) {
      sourceBuffer.getChannelData(0)[i] = 1;
      sourceBuffer.getChannelData(1)[i] = -1;
    }

    var destination = context.destination;

    var paramSource = context.createBufferSource();
    paramSource.buffer = this.buffer;

    var source = context.createBufferSource();
    source.buffer = sourceBuffer;

    var gain = context.createGain();

    paramSource.connect(gain.gain);
    source.connect(gain);

    paramSource.start(0);
    source.start(0);
    return gain;
  },
  createExpectedBuffers(context) {
    this.buffer = context.createBuffer(2, 2048, context.sampleRate);
    for (var i = 0; i < 2048; ++i) {
      for (var j = 0; j < 2; ++j) {
        this.buffer.getChannelData(j)[i] = Math.sin(440 * 2 * (j + 1) * Math.PI * i / context.sampleRate);
      }
    }
    var expectedBuffer = context.createBuffer(2, 2048, context.sampleRate);
    for (var i = 0; i < 2048; ++i) {
      expectedBuffer.getChannelData(0)[i] = 1 + (this.buffer.getChannelData(0)[i] + this.buffer.getChannelData(1)[i]) / 2;
      expectedBuffer.getChannelData(1)[i] = -(1 + (this.buffer.getChannelData(0)[i] + this.buffer.getChannelData(1)[i]) / 2);
    }
    return expectedBuffer;
  },
};

runTest();

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