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