| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 | |
| 3 <!-- | 2 <!-- |
| 4 Tests that AudioChannelSplitter works correctly. | 3 Tests that AudioChannelSplitter works correctly. |
| 5 --> | 4 --> |
| 5 <html> |
| 6 <head> |
| 7 <title> |
| 8 audiochannelsplitter.html |
| 9 </title> |
| 10 <script src="../../resources/testharness.js"></script> |
| 11 <script src="../../resources/testharnessreport.js"></script> |
| 12 <script src="../resources/audit-util.js"></script> |
| 13 <script src="../resources/audit.js"></script> |
| 14 </head> |
| 15 <body> |
| 16 <script id="layout-test-code"> |
| 17 let audit = Audit.createTaskRunner(); |
| 6 | 18 |
| 7 <html> | 19 let sampleRate = 44100.0; |
| 8 <head> | 20 let lengthInSampleFrames = 512; |
| 9 <script src="../../resources/testharness.js"></script> | |
| 10 <script src="../../resources/testharnessreport.js"></script> | |
| 11 <script src="../resources/audit-util.js"></script> | |
| 12 <script src="../resources/audit.js"></script> | |
| 13 </head> | |
| 14 | 21 |
| 15 <body> | 22 let context = 0; |
| 23 let sourceBuffer; |
| 24 let sourceNode; |
| 25 let channelSplitter; |
| 26 let channelMerger; |
| 16 | 27 |
| 17 <script> | 28 function createStereoBufferWithDCOffset(length, sampleRate, offset) { |
| 18 var audit = Audit.createTaskRunner(); | 29 let buffer = context.createBuffer(2, length, sampleRate); |
| 30 let n = buffer.length; |
| 31 let channelL = buffer.getChannelData(0); |
| 32 let channelR = buffer.getChannelData(1); |
| 19 | 33 |
| 20 var sampleRate = 44100.0; | 34 for (let i = 0; i < n; ++i) { |
| 21 var lengthInSampleFrames = 512; | 35 channelL[i] = offset; |
| 36 channelR[i] = -1.0 * offset; |
| 37 } |
| 22 | 38 |
| 23 var context = 0; | 39 return buffer; |
| 24 var sourceBuffer; | 40 } |
| 25 var sourceNode; | |
| 26 var channelSplitter; | |
| 27 var channelMerger; | |
| 28 | 41 |
| 29 function createStereoBufferWithDCOffset(length, sampleRate, offset) { | 42 // checkResult() checks that the rendered buffer is stereo and that the |
| 30 var buffer = context.createBuffer(2, length, sampleRate); | 43 // left channel is all -1 and right channel all +1. In other words, we've |
| 31 var n = buffer.length; | 44 // reversed the order of the two channels. |
| 32 var channelL = buffer.getChannelData(0); | 45 function checkResult(buffer, should) { |
| 33 var channelR = buffer.getChannelData(1); | 46 let success = true; |
| 34 | 47 |
| 35 for (var i = 0; i < n; ++i) { | 48 if (buffer.numberOfChannels == 2) { |
| 36 channelL[i] = offset; | 49 let bufferDataL = buffer.getChannelData(0); |
| 37 channelR[i] = -1.0 * offset; | 50 let bufferDataR = buffer.getChannelData(1); |
| 38 } | |
| 39 | 51 |
| 40 return buffer; | 52 success = should(bufferDataL, 'Left channel').beConstantValueOf(-1) && |
| 41 } | 53 success; |
| 54 success = should(bufferDataR, 'Right channel').beConstantValueOf(1) && |
| 55 success; |
| 56 } else { |
| 57 success = false; |
| 58 } |
| 42 | 59 |
| 43 // checkResult() checks that the rendered buffer is stereo and that the left cha
nnel is all -1 and right channel all +1. | 60 should(success, 'Left and right channels were exchanged') |
| 44 // In other words, we've reversed the order of the two channels. | 61 .message('correctly', 'incorrectly'); |
| 45 function checkResult(buffer, should) { | 62 } |
| 46 | 63 |
| 47 var success = true; | 64 audit.define( |
| 65 { |
| 66 label: 'construction', |
| 67 description: 'Construction of ChannelSplitterNode' |
| 68 }, |
| 69 function(task, should) { |
| 48 | 70 |
| 49 if (buffer.numberOfChannels == 2) { | 71 // Create stereo offline audio context. |
| 50 var bufferDataL = buffer.getChannelData(0); | 72 context = |
| 51 var bufferDataR = buffer.getChannelData(1); | 73 new OfflineAudioContext(2, lengthInSampleFrames, sampleRate); |
| 52 | 74 |
| 53 success = should(bufferDataL, "Left channel") | 75 let splitternode; |
| 54 .beConstantValueOf(-1) && success; | 76 should(() => { |
| 55 success = should(bufferDataR, "Right channel") | 77 let splitternode = context.createChannelSplitter(0); |
| 56 .beConstantValueOf(1) && success; | 78 }, 'createChannelSplitter(0)').throw('IndexSizeError'); |
| 57 } else { | |
| 58 success = false; | |
| 59 } | |
| 60 | 79 |
| 61 should(success, "Left and right channels were exchanged") | 80 should(() => { |
| 62 .message("correctly", "incorrectly"); | 81 splitternode = context.createChannelSplitter(33); |
| 63 } | 82 }, 'createChannelSplitter(33)').throw('IndexSizeError'); |
| 64 | 83 |
| 65 audit.define({ | 84 should(() => { |
| 66 label: "construction", | 85 splitternode = context.createChannelSplitter(32); |
| 67 description: "Construction of ChannelSplitterNode" | 86 }, 'splitternode = context.createChannelSplitter(32)').notThrow(); |
| 68 }, function (task, should) { | |
| 69 | 87 |
| 70 // Create stereo offline audio context. | 88 should(splitternode.numberOfOutputs, 'splitternode.numberOfOutputs') |
| 71 context = new OfflineAudioContext(2, lengthInSampleFrames, sampleRate); | 89 .beEqualTo(32); |
| 90 should(splitternode.numberOfInputs, 'splitternode.numberOfInputs') |
| 91 .beEqualTo(1) |
| 72 | 92 |
| 73 var splitternode; | 93 should(() => { |
| 74 should(() => { | 94 splitternode = context.createChannelSplitter(); |
| 75 var splitternode = context.createChannelSplitter(0); | 95 }, 'splitternode = context.createChannelSplitter()').notThrow(); |
| 76 }, "createChannelSplitter(0)") | |
| 77 .throw("IndexSizeError"); | |
| 78 | 96 |
| 79 should(() => { | 97 should(splitternode.numberOfOutputs, 'splitternode.numberOfOutputs') |
| 80 splitternode = context.createChannelSplitter(33); | 98 .beEqualTo(6); |
| 81 }, "createChannelSplitter(33)") | |
| 82 .throw("IndexSizeError"); | |
| 83 | 99 |
| 84 should(() => { | 100 task.done(); |
| 85 splitternode = context.createChannelSplitter(32); | 101 }); |
| 86 }, "splitternode = context.createChannelSplitter(32)") | |
| 87 .notThrow(); | |
| 88 | 102 |
| 89 should(splitternode.numberOfOutputs, | 103 audit.define( |
| 90 "splitternode.numberOfOutputs") | 104 { |
| 91 .beEqualTo(32); | 105 label: 'functionality', |
| 92 should(splitternode.numberOfInputs, | 106 description: 'Functionality of ChannelSplitterNode' |
| 93 "splitternode.numberOfInputs") | 107 }, |
| 94 .beEqualTo(1) | 108 function(task, should) { |
| 95 | 109 |
| 96 should(() => { | 110 // Create a stereo buffer, with all +1 values in left channel, all |
| 97 splitternode = context.createChannelSplitter(); | 111 // -1 in right channel. |
| 98 }, "splitternode = context.createChannelSplitter()") | 112 sourceBuffer = createStereoBufferWithDCOffset( |
| 99 .notThrow(); | 113 lengthInSampleFrames, sampleRate, 1); |
| 100 | 114 |
| 101 should(splitternode.numberOfOutputs, | 115 sourceNode = context.createBufferSource(); |
| 102 "splitternode.numberOfOutputs") | 116 sourceNode.buffer = sourceBuffer; |
| 103 .beEqualTo(6); | |
| 104 | 117 |
| 105 task.done(); | 118 // Create a channel splitter and connect it so that it split the |
| 106 }); | 119 // stereo stream into two mono streams. |
| 120 channelSplitter = context.createChannelSplitter(2); |
| 121 sourceNode.connect(channelSplitter); |
| 107 | 122 |
| 108 audit.define({ | 123 // Create a channel merger to merge the output of channel splitter. |
| 109 label: "functionality", | 124 channelMerger = context.createChannelMerger(); |
| 110 description: "Functionality of ChannelSplitterNode" | 125 channelMerger.connect(context.destination); |
| 111 }, function (task, should) { | |
| 112 | 126 |
| 113 // Create a stereo buffer, with all +1 values in left channel, all -1 in rig
ht channel. | 127 // When merging, exchange channel layout: left->right, right->left |
| 114 sourceBuffer = createStereoBufferWithDCOffset(lengthInSampleFrames, sampleRa
te, 1); | 128 channelSplitter.connect(channelMerger, 0, 1); |
| 129 channelSplitter.connect(channelMerger, 1, 0); |
| 115 | 130 |
| 116 sourceNode = context.createBufferSource(); | 131 sourceNode.start(0); |
| 117 sourceNode.buffer = sourceBuffer; | |
| 118 | 132 |
| 119 // Create a channel splitter and connect it so that it split the stereo stre
am into two mono streams. | 133 context.startRendering() |
| 120 channelSplitter = context.createChannelSplitter(2); | 134 .then(buffer => checkResult(buffer, should)) |
| 121 sourceNode.connect(channelSplitter); | 135 .then(task.done.bind(task)); |
| 136 }); |
| 122 | 137 |
| 123 // Create a channel merger to merge the output of channel splitter. | 138 audit.run(); |
| 124 channelMerger = context.createChannelMerger(); | 139 </script> |
| 125 channelMerger.connect(context.destination); | 140 </body> |
| 126 | |
| 127 // When merging, exchange channel layout: left->right, right->left | |
| 128 channelSplitter.connect(channelMerger, 0, 1); | |
| 129 channelSplitter.connect(channelMerger, 1, 0); | |
| 130 | |
| 131 sourceNode.start(0); | |
| 132 | |
| 133 context.startRendering() | |
| 134 .then(buffer => checkResult(buffer, should)) | |
| 135 .then(task.done.bind(task)); | |
| 136 }); | |
| 137 | |
| 138 audit.run(); | |
| 139 | |
| 140 </script> | |
| 141 | |
| 142 </body> | |
| 143 </html> | 141 </html> |
| OLD | NEW |