content/media/webaudio/test/test_channelSplitterNode.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/test/test_channelSplitterNode.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test ChannelSplitterNode</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="webaudio.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body>
    1.13 +<pre id="test">
    1.14 +<script class="testbody" type="text/javascript">
    1.15 +
    1.16 +// We do not use our generic graph test framework here because
    1.17 +// the splitter node is special in that it creates multiple
    1.18 +// output ports.
    1.19 +
    1.20 +SimpleTest.waitForExplicitFinish();
    1.21 +addLoadEvent(function() {
    1.22 +  var context = new AudioContext();
    1.23 +  var buffer = context.createBuffer(4, 2048, context.sampleRate);
    1.24 +  for (var j = 0; j < 4; ++j) {
    1.25 +    for (var i = 0; i < 2048; ++i) {
    1.26 +      buffer.getChannelData(j)[i] = Math.sin(440 * 2 * (j + 1) * Math.PI * i / context.sampleRate);
    1.27 +    }
    1.28 +  }
    1.29 +  var emptyBuffer = context.createBuffer(1, 2048, context.sampleRate);
    1.30 +
    1.31 +  var destination = context.destination;
    1.32 +
    1.33 +  var source = context.createBufferSource();
    1.34 +
    1.35 +  var splitter = context.createChannelSplitter();
    1.36 +  is(splitter.channelCount, 2, "splitter node has 2 input channels by default");
    1.37 +  is(splitter.channelCountMode, "max", "Correct channelCountMode for the splitter node");
    1.38 +  is(splitter.channelInterpretation, "speakers", "Correct channelCountInterpretation for the splitter node");
    1.39 +
    1.40 +  source.buffer = buffer;
    1.41 +  source.connect(splitter);
    1.42 +
    1.43 +  var channelsSeen = 0;
    1.44 +  function createHandler(i) {
    1.45 +    return function(e) {
    1.46 +      is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
    1.47 +      if (i < 4) {
    1.48 +        compareChannels(e.inputBuffer.getChannelData(0), buffer.getChannelData(i));
    1.49 +      } else {
    1.50 +        compareChannels(e.inputBuffer.getChannelData(0), emptyBuffer.getChannelData(0));
    1.51 +      }
    1.52 +      e.target.onaudioprocess = null;
    1.53 +      ++channelsSeen;
    1.54 +
    1.55 +      if (channelsSeen == 6) {
    1.56 +        SimpleTest.finish();
    1.57 +      }
    1.58 +    };
    1.59 +  }
    1.60 +
    1.61 +  for (var i = 0; i < 6; ++i) {
    1.62 +    var sp = context.createScriptProcessor(2048, 1);
    1.63 +    splitter.connect(sp, i);
    1.64 +    sp.onaudioprocess = createHandler(i);
    1.65 +    sp.connect(destination);
    1.66 +  }
    1.67 +
    1.68 +  source.start(0);
    1.69 +});
    1.70 +
    1.71 +</script>
    1.72 +</pre>
    1.73 +</body>
    1.74 +</html>

mercurial