summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_dynamicsCompressorNode.html
blob: 052b276714d4e6be1b680da59c1dde81ac21d376 (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
62
63
64
65
66
67
68
69
70
<!DOCTYPE HTML>
<html>
<head>
  <title>Test DynamicsCompressorNode</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

function near(a, b, msg) {
  ok(Math.abs(a - b) < 1e-4, msg);
}

SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
  var context = new AudioContext();

  var osc = context.createOscillator();
  var sp = context.createScriptProcessor();

  var compressor = context.createDynamicsCompressor();

  osc.connect(compressor);
  osc.connect(sp);
  compressor.connect(context.destination);

  is(compressor.channelCount, 2, "compressor node has 2 input channels by default");
  is(compressor.channelCountMode, "explicit", "Correct channelCountMode for the compressor node");
  is(compressor.channelInterpretation, "speakers", "Correct channelCountInterpretation for the compressor node");

  // Verify default values
  with (compressor) {
    ok(threshold instanceof AudioParam, "treshold is an AudioParam");
    near(threshold.defaultValue, -24, "Correct default value for threshold");
    ok(knee instanceof AudioParam, "knee is an AudioParam");
    near(knee.defaultValue, 30, "Correct default value for knee");
    ok(ratio instanceof AudioParam, "knee is an AudioParam");
    near(ratio.defaultValue, 12, "Correct default value for ratio");
    is(typeof reduction, "number", "reduction is a number");
    near(reduction, 0, "Correct default value for reduction");
    ok(attack instanceof AudioParam, "attack is an AudioParam");
    near(attack.defaultValue, 0.003, "Correct default value for attack");
    ok(release instanceof AudioParam, "release is an AudioParam");
    near(release.defaultValue, 0.25, "Correct default value for release");
  }

  compressor.threshold.value = -80;

  osc.start();
  var iteration = 0;
  sp.onaudioprocess = function(e) {
    if (iteration > 10) {
      ok(compressor.reduction < 0,
         "Feeding a full-scale sine to a compressor should result in an db" +
         "reduction.");
      sp.onaudioprocess = null;
      osc.stop(0);

      SimpleTest.finish();
    }
    iteration++;
  }
});

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