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