Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 var sampleRate = 44100.0; | 1 var sampleRate = 44100.0; |
| 2 | 2 |
| 3 var numberOfChannels = 1; | 3 var numberOfChannels = 1; |
| 4 | 4 |
| 5 // Time step when each panner node starts. | 5 // Time step when each panner node starts. |
| 6 var timeStep = 0.001; | 6 var timeStep = 0.001; |
| 7 | 7 |
| 8 // Length of the impulse signal. | 8 // Length of the impulse signal. |
| 9 var pulseLengthFrames = Math.round(timeStep * sampleRate); | 9 var pulseLengthFrames = Math.round(timeStep * sampleRate); |
| 10 | 10 |
| 11 // How many panner nodes to create for the test | 11 // How many panner nodes to create for the test |
| 12 var nodesToCreate = 100; | 12 var nodesToCreate = 100; |
| 13 | 13 |
| 14 // Be sure we render long enough for all of our nodes. | 14 // Be sure we render long enough for all of our nodes. |
| 15 var renderLengthSeconds = timeStep * (nodesToCreate + 1); | 15 var renderLengthSeconds = timeStep * (nodesToCreate + 1); |
| 16 | 16 |
| 17 // These are global mostly for debugging. | 17 // These are global mostly for debugging. |
| 18 var context; | 18 var context; |
| 19 var impulse; | 19 var impulse; |
| 20 var bufferSource; | 20 var bufferSource; |
| 21 var panner; | 21 var panner; |
| 22 var position; | 22 var position; |
| 23 var time; | 23 var time; |
| 24 | 24 |
| 25 var renderedBuffer; | 25 var renderedBuffer; |
| 26 var renderedLeft; | 26 var renderedLeft; |
| 27 var renderedRight; | 27 var renderedRight; |
| 28 | 28 |
| 29 function createGraph(context, nodeCount) { | 29 function createGraph(context, nodeCount) { |
| 30 bufferSource = new Array(nodeCount); | 30 bufferSource = new Array(nodeCount); |
| 31 panner = new Array(nodeCount); | 31 panner = new Array(nodeCount); |
| 32 position = new Array(nodeCount); | 32 position = new Array(nodeCount); |
| 33 time = new Array(nodeCount); | 33 time = new Array(nodeCount); |
| 34 // Angle between panner locations. (nodeCount - 1 because we want | 34 // Angle between panner locations. (nodeCount - 1 because we want |
| 35 // to include both 0 and 180 deg. | 35 // to include both 0 and 180 deg. |
| 36 var angleStep = Math.PI / (nodeCount - 1); | 36 var angleStep = Math.PI / (nodeCount - 1); |
| 37 | 37 |
| 38 if (numberOfChannels == 2) { | 38 if (numberOfChannels == 2) { |
| 39 impulse = createStereoImpulseBuffer(context, pulseLengthFrames); | 39 impulse = createStereoImpulseBuffer(context, pulseLengthFrames); |
| 40 } | 40 } |
| 41 else | 41 else |
| 42 impulse = createImpulseBuffer(context, pulseLengthFrames); | 42 impulse = createImpulseBuffer(context, pulseLengthFrames); |
| 43 | 43 |
| 44 for (var k = 0; k < nodeCount; ++k) { | 44 for (var k = 0; k < nodeCount; ++k) { |
| 45 bufferSource[k] = context.createBufferSource(); | 45 bufferSource[k] = context.createBufferSource(); |
| 46 bufferSource[k].buffer = impulse; | 46 bufferSource[k].buffer = impulse; |
| 47 | 47 |
| 48 panner[k] = context.createPanner(); | 48 panner[k] = context.createPanner(); |
| 49 // Equalpower is default now. May not be necessary. | |
| 50 // https://code.google.com/p/chromium/issues/detail?id=424356 | |
| 49 panner[k].panningModel = "equalpower"; | 51 panner[k].panningModel = "equalpower"; |
|
Raymond Toy
2014/10/17 17:39:30
I would just remove the comment and the assignment
hongchan
2014/10/17 18:13:41
Done.
| |
| 50 panner[k].distanceModel = "linear"; | 52 panner[k].distanceModel = "linear"; |
| 51 | 53 |
| 52 var angle = angleStep * k; | 54 var angle = angleStep * k; |
| 53 position[k] = {angle : angle, x : Math.cos(angle), z : Math.sin(angle)}; | 55 position[k] = {angle : angle, x : Math.cos(angle), z : Math.sin(angle)}; |
| 54 panner[k].setPosition(position[k].x, 0, position[k].z); | 56 panner[k].setPosition(position[k].x, 0, position[k].z); |
| 55 | 57 |
| 56 bufferSource[k].connect(panner[k]); | 58 bufferSource[k].connect(panner[k]); |
| 57 panner[k].connect(context.destination); | 59 panner[k].connect(context.destination); |
| 58 | 60 |
| 59 // Start the source | 61 // Start the source |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 85 if (numberOfChannels == 1) { | 87 if (numberOfChannels == 1) { |
| 86 var panPosition = (azimuth + 90) / 180; | 88 var panPosition = (azimuth + 90) / 180; |
| 87 | 89 |
| 88 var gainL = Math.cos(0.5 * Math.PI * panPosition); | 90 var gainL = Math.cos(0.5 * Math.PI * panPosition); |
| 89 var gainR = Math.sin(0.5 * Math.PI * panPosition); | 91 var gainR = Math.sin(0.5 * Math.PI * panPosition); |
| 90 | 92 |
| 91 return { left : gainL, right : gainR }; | 93 return { left : gainL, right : gainR }; |
| 92 } else { | 94 } else { |
| 93 if (azimuth <= 0) { | 95 if (azimuth <= 0) { |
| 94 var panPosition = (azimuth + 90) / 90; | 96 var panPosition = (azimuth + 90) / 90; |
| 95 | 97 |
|
Raymond Toy
2014/10/17 17:39:30
Removing more blank lines?
hongchan
2014/10/17 18:13:41
Yes.
| |
| 96 var gainL = 1 + Math.cos(0.5 * Math.PI * panPosition); | 98 var gainL = 1 + Math.cos(0.5 * Math.PI * panPosition); |
| 97 var gainR = Math.sin(0.5 * Math.PI * panPosition); | 99 var gainR = Math.sin(0.5 * Math.PI * panPosition); |
| 98 | 100 |
| 99 return { left : gainL, right : gainR }; | 101 return { left : gainL, right : gainR }; |
| 100 } else { | 102 } else { |
| 101 var panPosition = azimuth / 90; | 103 var panPosition = azimuth / 90; |
| 102 | 104 |
| 103 var gainL = Math.cos(0.5 * Math.PI * panPosition); | 105 var gainL = Math.cos(0.5 * Math.PI * panPosition); |
| 104 var gainR = 1 + Math.sin(0.5 * Math.PI * panPosition); | 106 var gainR = 1 + Math.sin(0.5 * Math.PI * panPosition); |
| 105 | 107 |
| 106 return { left : gainL, right : gainR }; | 108 return { left : gainL, right : gainR }; |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 } | 111 } |
| 110 | 112 |
| 111 function checkResult(event) { | 113 function checkResult(event) { |
| 112 renderedBuffer = event.renderedBuffer; | 114 renderedBuffer = event.renderedBuffer; |
| 113 renderedLeft = renderedBuffer.getChannelData(0); | 115 renderedLeft = renderedBuffer.getChannelData(0); |
| 114 renderedRight = renderedBuffer.getChannelData(1); | 116 renderedRight = renderedBuffer.getChannelData(1); |
| 115 | 117 |
| 116 // The max error we allow between the rendered impulse and the | 118 // The max error we allow between the rendered impulse and the |
| 117 // expected value. This value is experimentally determined. Set | 119 // expected value. This value is experimentally determined. Set |
| 118 // to 0 to make the test fail to see what the actual error is. | 120 // to 0 to make the test fail to see what the actual error is. |
| 119 var maxAllowedError = 1.3e-6; | 121 var maxAllowedError = 1.3e-6; |
| 120 | 122 |
| 121 var success = true; | 123 var success = true; |
| 122 | 124 |
| 123 // Number of impulses found in the rendered result. | 125 // Number of impulses found in the rendered result. |
| 124 var impulseCount = 0; | 126 var impulseCount = 0; |
| 125 | 127 |
| 126 // Max (relative) error and the index of the maxima for the left | 128 // Max (relative) error and the index of the maxima for the left |
| 127 // and right channels. | 129 // and right channels. |
| 128 var maxErrorL = 0; | 130 var maxErrorL = 0; |
| 129 var maxErrorIndexL = 0; | 131 var maxErrorIndexL = 0; |
| 130 var maxErrorR = 0; | 132 var maxErrorR = 0; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 } else { | 186 } else { |
| 185 testPassed("All impulses at expected offsets."); | 187 testPassed("All impulses at expected offsets."); |
| 186 } | 188 } |
| 187 | 189 |
| 188 if (maxErrorL <= maxAllowedError) { | 190 if (maxErrorL <= maxAllowedError) { |
| 189 testPassed("Left channel gain values are correct."); | 191 testPassed("Left channel gain values are correct."); |
| 190 } else { | 192 } else { |
| 191 testFailed("Left channel gain values are incorrect. Max error = " + max ErrorL + " at time " + time[maxErrorIndexL] + " (threshold = " + maxAllowedError + ")"); | 193 testFailed("Left channel gain values are incorrect. Max error = " + max ErrorL + " at time " + time[maxErrorIndexL] + " (threshold = " + maxAllowedError + ")"); |
| 192 success = false; | 194 success = false; |
| 193 } | 195 } |
| 194 | 196 |
| 195 if (maxErrorR <= maxAllowedError) { | 197 if (maxErrorR <= maxAllowedError) { |
| 196 testPassed("Right channel gain values are correct."); | 198 testPassed("Right channel gain values are correct."); |
| 197 } else { | 199 } else { |
| 198 testFailed("Right channel gain values are incorrect. Max error = " + ma xErrorR + " at time " + time[maxErrorIndexR] + " (threshold = " + maxAllowedErro r + ")"); | 200 testFailed("Right channel gain values are incorrect. Max error = " + ma xErrorR + " at time " + time[maxErrorIndexR] + " (threshold = " + maxAllowedErro r + ")"); |
| 199 success = false; | 201 success = false; |
| 200 } | 202 } |
| 201 | 203 |
| 202 if (success) { | 204 if (success) { |
| 203 testPassed("EqualPower panner test passed"); | 205 testPassed("EqualPower panner test passed"); |
| 204 } else { | 206 } else { |
| 205 testFailed("EqualPower panner test failed"); | 207 testFailed("EqualPower panner test failed"); |
| 206 } | 208 } |
| 207 | 209 |
| 208 finishJSTest(); | 210 finishJSTest(); |
| 209 } | 211 } |
| OLD | NEW |