Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test AudioBufferSourceNode</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">
13 // We do not use our generic graph test framework here because
14 // the testing logic here is sort of complicated, and would
15 // not be easy to map to OfflineAudioContext, as ScriptProcessorNodes
16 // can experience delays.
18 SimpleTest.waitForExplicitFinish();
19 addLoadEvent(function() {
20 var context = new AudioContext();
21 var buffer = context.createBuffer(6, 2048, context.sampleRate);
22 for (var i = 0; i < 2048; ++i) {
23 for (var j = 0; j < 6; ++j) {
24 buffer.getChannelData(0)[i] = Math.sin(440 * j * Math.PI * i / context.sampleRate);
25 }
26 }
28 var monoBuffer = context.createBuffer(1, 2048, context.sampleRate);
29 for (var i = 0; i < 2048; ++i) {
30 monoBuffer.getChannelData(0)[i] = 1;
31 }
33 var source = context.createBufferSource();
35 var sp = context.createScriptProcessor(2048, 3);
36 expectException(function() { sp.channelCount = 2; },
37 DOMException.NOT_SUPPORTED_ERR);
38 sp.channelCountMode = "explicit";
39 expectException(function() { sp.channelCountMode = "max"; },
40 DOMException.NOT_SUPPORTED_ERR);
41 expectException(function() { sp.channelCountMode = "clamped-max"; },
42 DOMException.NOT_SUPPORTED_ERR);
43 sp.channelInterpretation = "discrete";
44 source.start(0);
45 source.buffer = buffer;
46 source.connect(sp);
47 sp.connect(context.destination);
49 var monoSource = context.createBufferSource();
50 monoSource.buffer = monoBuffer;
51 monoSource.connect(sp);
52 monoSource.start(2048 / context.sampleRate);
54 sp.onaudioprocess = function(e) {
55 is(e.inputBuffer.numberOfChannels, 3, "Should be correctly down-mixed to three channels");
56 for (var i = 0; i < 3; ++i) {
57 compareChannels(e.inputBuffer.getChannelData(i), buffer.getChannelData(i));
58 }
60 // On the next iteration, we'll get a silence buffer
61 sp.onaudioprocess = function(e) {
62 var emptyBuffer = context.createBuffer(1, 2048, context.sampleRate);
63 is(e.inputBuffer.numberOfChannels, 3, "Should be correctly up-mixed to three channels");
64 compareChannels(e.inputBuffer.getChannelData(0), monoBuffer.getChannelData(0));
65 for (var i = 1; i < 3; ++i) {
66 compareChannels(e.inputBuffer.getChannelData(i), emptyBuffer.getChannelData(0));
67 }
69 sp.onaudioprocess = null;
70 sp.disconnect(context.destination);
72 SimpleTest.finish();
73 };
74 };
75 });
77 </script>
78 </pre>
79 </body>
80 </html>