summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_delayNodeWithGain.html
blob: af075c7439b886e817a6c642192c6e5c3f923fd9 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test DelayNode with a GainNode</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">

var gTest = {
  length: 4096,
  numberOfChannels: 1,
  createGraph(context) {
    var buffer = context.createBuffer(1, 2048, context.sampleRate);
    for (var i = 0; i < 2048; ++i) {
      buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
    }

    var source = context.createBufferSource();

    var delay = context.createDelay();

    source.buffer = buffer;

    var gain = context.createGain();
    gain.gain.value = 0.5;

    source.connect(gain);
    gain.connect(delay);

    // Delay the source stream by 2048 frames
    delay.delayTime.value = 2048 / context.sampleRate;

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

runTest();

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