summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_oscillatorNode.html
blob: 5eb48857433136715ee132f9c73023b096303470 (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 the OscillatorNode interface</title>
  <script type="text/javascript" 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">

SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {

  var context = new AudioContext();
  var osc = context.createOscillator();

  is(osc.channelCount, 2, "Oscillator node has 2 input channels by default");
  is(osc.channelCountMode, "max", "Correct channelCountMode for the Oscillator node");
  is(osc.channelInterpretation, "speakers", "Correct channelCountInterpretation for the Oscillator node");
  is(osc.type, "sine", "Correct default type");
  expectException(function() {
    osc.type = "custom";
  }, DOMException.INVALID_STATE_ERR);
  is(osc.type, "sine", "Cannot set the type to custom");
  is(osc.frequency.value, 440, "Correct default frequency value");
  is(osc.detune.value, 0, "Correct default detine value");

  // Make sure that we can set all of the valid type values
  var types = [
    "sine",
    "square",
    "sawtooth",
    "triangle",
  ];
  for (var i = 0; i < types.length; ++i) {
    osc.type = types[i];
  }

  // Verify setPeriodicWave()
  var real = new Float32Array([1.0, 0.5, 0.25, 0.125]);
  var imag = new Float32Array([1.0, 0.7, -1.0, 0.5]);
  osc.setPeriodicWave(context.createPeriodicWave(real, imag));
  is(osc.type, "custom", "Failed to set custom waveform");

  expectNoException(function() {
    osc.start();
  });
  expectNoException(function() {
    osc.stop();
  });

  SimpleTest.finish();
});

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