content/media/webaudio/test/test_channelSplitterNodeWithVolume.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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   var expectedBuffer = context.createBuffer(4, 2048, context.sampleRate);
    22   for (var j = 0; j < 4; ++j) {
    23     for (var i = 0; i < 2048; ++i) {
    24       buffer.getChannelData(j)[i] = Math.sin(440 * 2 * (j + 1) * Math.PI * i / context.sampleRate);
    25       expectedBuffer.getChannelData(j)[i] = buffer.getChannelData(j)[i] / 2;
    26     }
    27   }
    28   var emptyBuffer = context.createBuffer(1, 2048, context.sampleRate);
    30   var destination = context.destination;
    32   var source = context.createBufferSource();
    34   var splitter = context.createChannelSplitter();
    35   is(splitter.channelCount, 2, "splitter node has 2 input channels by default");
    36   is(splitter.channelCountMode, "max", "Correct channelCountMode for the splitter node");
    37   is(splitter.channelInterpretation, "speakers", "Correct channelCountInterpretation for the splitter node");
    39   source.buffer = buffer;
    40   var gain = context.createGain();
    41   gain.gain.value = 0.5;
    42   source.connect(gain);
    43   gain.connect(splitter);
    45   var channelsSeen = 0;
    46   function createHandler(i) {
    47     return function(e) {
    48       is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
    49       if (i < 4) {
    50         compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(i));
    51       } else {
    52         compareBuffers(e.inputBuffer.getChannelData(0), emptyBuffer.getChannelData(0));
    53       }
    54       e.target.onaudioprocess = null;
    55       ++channelsSeen;
    57       if (channelsSeen == 6) {
    58         SimpleTest.finish();
    59       }
    60     };
    61   }
    63   for (var i = 0; i < 6; ++i) {
    64     var sp = context.createScriptProcessor(2048, 1);
    65     splitter.connect(sp, i);
    66     sp.onaudioprocess = createHandler(i);
    67     sp.connect(destination);
    68   }
    70   source.start(0);
    71 });
    73 </script>
    74 </pre>
    75 </body>
    76 </html>

mercurial