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