Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / audiochannelsplitter.html
blobcdde37dd46881a9070b59cfe65fc53ecbad7845b
1 <!DOCTYPE html>
3 <!--
4 Tests that AudioChannelSplitter works correctly.
5 -->
7 <html>
8 <head>
9 <script src="../resources/js-test.js"></script>
10 <script src="resources/compatibility.js"></script>
11 <script type="text/javascript" src="resources/audio-testing.js"></script>
12 </head>
14 <body>
16 <div id="description"></div>
17 <div id="console"></div>
19 <script>
20 description("Tests AudioChannelSplitter.");
22 var sampleRate = 44100.0;
23 var lengthInSampleFrames = 512;
25 var context = 0;
26 var sourceBuffer;
27 var sourceNode;
28 var channelSplitter;
29 var channelMerger;
31 function createStereoBufferWithDCOffset(length, sampleRate, offset) {
32 var buffer = context.createBuffer(2, length, sampleRate);
33 var n = buffer.length;
34 var channelL = buffer.getChannelData(0);
35 var channelR = buffer.getChannelData(1);
37 for (var i = 0; i < n; ++i) {
38 channelL[i] = offset;
39 channelR[i] = -1.0 * offset;
42 return buffer;
45 // checkResult() checks that the rendered buffer is stereo and that the left channel is all -1 and right channel all +1.
46 // In other words, we've reversed the order of the two channels.
47 function checkResult(event) {
48 var buffer = event.renderedBuffer;
50 var success = true;
52 if (buffer.numberOfChannels == 2) {
53 var bufferDataL = buffer.getChannelData(0);
54 var bufferDataR = buffer.getChannelData(1);
56 // Go through every sample and make sure it's all -1 for the left-channel, and all +1 for the right-channel.
57 for (var i = 0; i < buffer.length; ++i) {
58 if (bufferDataL[i] != -1 || bufferDataR[i] != 1) {
59 success = false;
60 break;
63 } else {
64 success = false;
67 if (success) {
68 testPassed("Correctly exchanged left and right channels.");
69 } else {
70 testFailed("Error on exchanging left and right channels.");
73 finishJSTest();
76 function runTest() {
77 if (window.testRunner) {
78 testRunner.dumpAsText();
79 testRunner.waitUntilDone();
82 window.jsTestIsAsync = true;
84 // Create stereo offline audio context.
85 context = new OfflineAudioContext(2, lengthInSampleFrames, sampleRate);
87 try {
88 var splitternode = context.createChannelSplitter(0);
89 testFailed("Exception should be thrown for numberOfOutputs <= 0.");
90 } catch(e) {
91 testPassed("Exception been thrown for numberOfOutputs <= 0.");
94 try {
95 var splitternode = context.createChannelSplitter(33);
96 testFailed("Exception should be thrown for numerOfOutputs >= 32.");
97 } catch(e) {
98 testPassed("Exception been thrown for numberOfOutputs >= 32.");
101 try {
102 var splitternode = context.createChannelSplitter(32);
103 testPassed("AudioChannelSplitter created successfully with numberOfOutputs = 32.");
104 if (splitternode.numberOfOutputs === 32)
105 testPassed("AudioChannelSplitter has 32 outputs when it is created with numberOfOutputs = 32.");
106 else
107 testFailed("AudioChannelSplitter should have 32 outputs when it is created with numberOfOutputs = 32.");
109 if (splitternode.numberOfInputs === 1)
110 testPassed("AudioChannelSplitter has one input.");
111 else
112 testFailed("AudioChannelSplitter should have one input.");
113 } catch(e) {
114 testFailed("Failed to create AudioChannelSplitter with numberOfInputs = 32.");
117 try {
118 var splitternode = context.createChannelSplitter();
119 testPassed("AudioChannelSplitter created successfully with empty parameter.");
120 if (splitternode.numberOfOutputs === 6)
121 testPassed("AudioChannelSplitter has 6 outputs when it is created with empty parameter.");
122 else
123 testFailed("AudioChannelSplitter should have 6 outputs when it is created with empty parameter.");
125 if (splitternode.toString().indexOf("ChannelSplitterNode") > -1)
126 testPassed("ChannelSplitterNode Object is available.");
127 else
128 testFailed("ChannelSplitterNode Object is not available.");
129 } catch(e) {
130 testFailed("Failed to create AudioChannelSplitter with empty parameter.");
133 // Create a stereo buffer, with all +1 values in left channel, all -1 in right channel.
134 sourceBuffer = createStereoBufferWithDCOffset(lengthInSampleFrames, sampleRate, 1);
136 sourceNode = context.createBufferSource();
137 sourceNode.buffer = sourceBuffer;
139 // Create a channel splitter and connect it so that it split the stereo stream into two mono streams.
140 channelSplitter = context.createChannelSplitter(2);
141 sourceNode.connect(channelSplitter);
143 // Create a channel merger to merge the output of channel splitter.
144 channelMerger = context.createChannelMerger();
145 channelMerger.connect(context.destination);
147 // When merging, exchange channel layout: left->right, right->left
148 channelSplitter.connect(channelMerger, 0, 1);
149 channelSplitter.connect(channelMerger, 1, 0);
151 sourceNode.start(0);
153 context.oncomplete = checkResult;
154 context.startRendering();
157 runTest();
159 </script>
161 </body>
162 </html>