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