1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webaudio/test/test_channelSplitterNodeWithVolume.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 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 + var expectedBuffer = context.createBuffer(4, 2048, context.sampleRate); 1.25 + for (var j = 0; j < 4; ++j) { 1.26 + for (var i = 0; i < 2048; ++i) { 1.27 + buffer.getChannelData(j)[i] = Math.sin(440 * 2 * (j + 1) * Math.PI * i / context.sampleRate); 1.28 + expectedBuffer.getChannelData(j)[i] = buffer.getChannelData(j)[i] / 2; 1.29 + } 1.30 + } 1.31 + var emptyBuffer = context.createBuffer(1, 2048, context.sampleRate); 1.32 + 1.33 + var destination = context.destination; 1.34 + 1.35 + var source = context.createBufferSource(); 1.36 + 1.37 + var splitter = context.createChannelSplitter(); 1.38 + is(splitter.channelCount, 2, "splitter node has 2 input channels by default"); 1.39 + is(splitter.channelCountMode, "max", "Correct channelCountMode for the splitter node"); 1.40 + is(splitter.channelInterpretation, "speakers", "Correct channelCountInterpretation for the splitter node"); 1.41 + 1.42 + source.buffer = buffer; 1.43 + var gain = context.createGain(); 1.44 + gain.gain.value = 0.5; 1.45 + source.connect(gain); 1.46 + gain.connect(splitter); 1.47 + 1.48 + var channelsSeen = 0; 1.49 + function createHandler(i) { 1.50 + return function(e) { 1.51 + is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count"); 1.52 + if (i < 4) { 1.53 + compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(i)); 1.54 + } else { 1.55 + compareBuffers(e.inputBuffer.getChannelData(0), emptyBuffer.getChannelData(0)); 1.56 + } 1.57 + e.target.onaudioprocess = null; 1.58 + ++channelsSeen; 1.59 + 1.60 + if (channelsSeen == 6) { 1.61 + SimpleTest.finish(); 1.62 + } 1.63 + }; 1.64 + } 1.65 + 1.66 + for (var i = 0; i < 6; ++i) { 1.67 + var sp = context.createScriptProcessor(2048, 1); 1.68 + splitter.connect(sp, i); 1.69 + sp.onaudioprocess = createHandler(i); 1.70 + sp.connect(destination); 1.71 + } 1.72 + 1.73 + source.start(0); 1.74 +}); 1.75 + 1.76 +</script> 1.77 +</pre> 1.78 +</body> 1.79 +</html>