1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webaudio/test/test_scriptProcessorNodeChannelCount.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test AudioBufferSourceNode</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 testing logic here is sort of complicated, and would 1.18 +// not be easy to map to OfflineAudioContext, as ScriptProcessorNodes 1.19 +// can experience delays. 1.20 + 1.21 +SimpleTest.waitForExplicitFinish(); 1.22 +addLoadEvent(function() { 1.23 + var context = new AudioContext(); 1.24 + var buffer = context.createBuffer(6, 2048, context.sampleRate); 1.25 + for (var i = 0; i < 2048; ++i) { 1.26 + for (var j = 0; j < 6; ++j) { 1.27 + buffer.getChannelData(0)[i] = Math.sin(440 * j * Math.PI * i / context.sampleRate); 1.28 + } 1.29 + } 1.30 + 1.31 + var monoBuffer = context.createBuffer(1, 2048, context.sampleRate); 1.32 + for (var i = 0; i < 2048; ++i) { 1.33 + monoBuffer.getChannelData(0)[i] = 1; 1.34 + } 1.35 + 1.36 + var source = context.createBufferSource(); 1.37 + 1.38 + var sp = context.createScriptProcessor(2048, 3); 1.39 + expectException(function() { sp.channelCount = 2; }, 1.40 + DOMException.NOT_SUPPORTED_ERR); 1.41 + sp.channelCountMode = "explicit"; 1.42 + expectException(function() { sp.channelCountMode = "max"; }, 1.43 + DOMException.NOT_SUPPORTED_ERR); 1.44 + expectException(function() { sp.channelCountMode = "clamped-max"; }, 1.45 + DOMException.NOT_SUPPORTED_ERR); 1.46 + sp.channelInterpretation = "discrete"; 1.47 + source.start(0); 1.48 + source.buffer = buffer; 1.49 + source.connect(sp); 1.50 + sp.connect(context.destination); 1.51 + 1.52 + var monoSource = context.createBufferSource(); 1.53 + monoSource.buffer = monoBuffer; 1.54 + monoSource.connect(sp); 1.55 + monoSource.start(2048 / context.sampleRate); 1.56 + 1.57 + sp.onaudioprocess = function(e) { 1.58 + is(e.inputBuffer.numberOfChannels, 3, "Should be correctly down-mixed to three channels"); 1.59 + for (var i = 0; i < 3; ++i) { 1.60 + compareChannels(e.inputBuffer.getChannelData(i), buffer.getChannelData(i)); 1.61 + } 1.62 + 1.63 + // On the next iteration, we'll get a silence buffer 1.64 + sp.onaudioprocess = function(e) { 1.65 + var emptyBuffer = context.createBuffer(1, 2048, context.sampleRate); 1.66 + is(e.inputBuffer.numberOfChannels, 3, "Should be correctly up-mixed to three channels"); 1.67 + compareChannels(e.inputBuffer.getChannelData(0), monoBuffer.getChannelData(0)); 1.68 + for (var i = 1; i < 3; ++i) { 1.69 + compareChannels(e.inputBuffer.getChannelData(i), emptyBuffer.getChannelData(0)); 1.70 + } 1.71 + 1.72 + sp.onaudioprocess = null; 1.73 + sp.disconnect(context.destination); 1.74 + 1.75 + SimpleTest.finish(); 1.76 + }; 1.77 + }; 1.78 +}); 1.79 + 1.80 +</script> 1.81 +</pre> 1.82 +</body> 1.83 +</html>