content/media/webaudio/test/test_channelSplitterNode.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test ChannelSplitterNode</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="text/javascript" src="webaudio.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     8 </head>
     9 <body>
    10 <pre id="test">
    11 <script class="testbody" type="text/javascript">
    13 // We do not use our generic graph test framework here because
    14 // the splitter node is special in that it creates multiple
    15 // output ports.
    17 SimpleTest.waitForExplicitFinish();
    18 addLoadEvent(function() {
    19   var context = new AudioContext();
    20   var buffer = context.createBuffer(4, 2048, context.sampleRate);
    21   for (var j = 0; j < 4; ++j) {
    22     for (var i = 0; i < 2048; ++i) {
    23       buffer.getChannelData(j)[i] = Math.sin(440 * 2 * (j + 1) * Math.PI * i / context.sampleRate);
    24     }
    25   }
    26   var emptyBuffer = context.createBuffer(1, 2048, context.sampleRate);
    28   var destination = context.destination;
    30   var source = context.createBufferSource();
    32   var splitter = context.createChannelSplitter();
    33   is(splitter.channelCount, 2, "splitter node has 2 input channels by default");
    34   is(splitter.channelCountMode, "max", "Correct channelCountMode for the splitter node");
    35   is(splitter.channelInterpretation, "speakers", "Correct channelCountInterpretation for the splitter node");
    37   source.buffer = buffer;
    38   source.connect(splitter);
    40   var channelsSeen = 0;
    41   function createHandler(i) {
    42     return function(e) {
    43       is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
    44       if (i < 4) {
    45         compareChannels(e.inputBuffer.getChannelData(0), buffer.getChannelData(i));
    46       } else {
    47         compareChannels(e.inputBuffer.getChannelData(0), emptyBuffer.getChannelData(0));
    48       }
    49       e.target.onaudioprocess = null;
    50       ++channelsSeen;
    52       if (channelsSeen == 6) {
    53         SimpleTest.finish();
    54       }
    55     };
    56   }
    58   for (var i = 0; i < 6; ++i) {
    59     var sp = context.createScriptProcessor(2048, 1);
    60     splitter.connect(sp, i);
    61     sp.onaudioprocess = createHandler(i);
    62     sp.connect(destination);
    63   }
    65   source.start(0);
    66 });
    68 </script>
    69 </pre>
    70 </body>
    71 </html>

mercurial