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 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 | 55 |
| 56 bufferSource[k].connect(panner[k]); | 56 bufferSource[k].connect(panner[k]); |
| 57 panner[k].connect(context.destination); | 57 panner[k].connect(context.destination); |
| 58 | 58 |
| 59 // Start the source | 59 // Start the source |
| 60 time[k] = k * timeStep; | 60 time[k] = k * timeStep; |
| 61 bufferSource[k].start(time[k]); | 61 bufferSource[k].start(time[k]); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 function createTestAndRun(context, nodeCount, numberOfSourceChannels, positionSe tter) { | 65 function createTestAndRun(context, should, nodeCount, numberOfSourceChannels, po sitionSetter) { |
|
hongchan
2017/02/24 22:07:24
Let's wrap this line.
Raymond Toy
2017/02/24 22:19:24
Done.
| |
| 66 numberOfChannels = numberOfSourceChannels; | 66 numberOfChannels = numberOfSourceChannels; |
| 67 | 67 |
| 68 createGraph(context, nodeCount, positionSetter); | 68 createGraph(context, nodeCount, positionSetter); |
| 69 | 69 |
| 70 context.oncomplete = checkResult; | 70 return context.startRendering() |
| 71 context.startRendering(); | 71 .then(buffer => checkResult(buffer, should));; |
|
hongchan
2017/02/24 22:07:24
Two semicolons.
Raymond Toy
2017/02/24 22:19:24
Done.
| |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Map our position angle to the azimuth angle (in degrees). | 74 // Map our position angle to the azimuth angle (in degrees). |
| 75 // | 75 // |
| 76 // An angle of 0 corresponds to an azimuth of 90 deg; pi, to -90 deg. | 76 // An angle of 0 corresponds to an azimuth of 90 deg; pi, to -90 deg. |
| 77 function angleToAzimuth(angle) { | 77 function angleToAzimuth(angle) { |
| 78 return 90 - angle * 180 / Math.PI; | 78 return 90 - angle * 180 / Math.PI; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // The gain caused by the EQUALPOWER panning model | 81 // The gain caused by the EQUALPOWER panning model |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 101 var panPosition = azimuth / 90; | 101 var panPosition = azimuth / 90; |
| 102 | 102 |
| 103 var gainL = Math.cos(0.5 * Math.PI * panPosition); | 103 var gainL = Math.cos(0.5 * Math.PI * panPosition); |
| 104 var gainR = 1 + Math.sin(0.5 * Math.PI * panPosition); | 104 var gainR = 1 + Math.sin(0.5 * Math.PI * panPosition); |
| 105 | 105 |
| 106 return { left : gainL, right : gainR }; | 106 return { left : gainL, right : gainR }; |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 function checkResult(event) { | 111 function checkResult(renderedBuffer, should) { |
| 112 renderedBuffer = event.renderedBuffer; | |
| 113 renderedLeft = renderedBuffer.getChannelData(0); | 112 renderedLeft = renderedBuffer.getChannelData(0); |
| 114 renderedRight = renderedBuffer.getChannelData(1); | 113 renderedRight = renderedBuffer.getChannelData(1); |
| 115 | 114 |
| 116 // The max error we allow between the rendered impulse and the | 115 // The max error we allow between the rendered impulse and the |
| 117 // expected value. This value is experimentally determined. Set | 116 // expected value. This value is experimentally determined. Set |
| 118 // to 0 to make the test fail to see what the actual error is. | 117 // to 0 to make the test fail to see what the actual error is. |
| 119 var maxAllowedError = 1.3e-6; | 118 var maxAllowedError = 1.3e-6; |
| 120 | 119 |
| 121 var success = true; | 120 var success = true; |
| 122 | 121 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 // expected them to be. | 160 // expected them to be. |
| 162 var expectedOffset = timeToSampleFrame(time[impulseCount], sampleRat e); | 161 var expectedOffset = timeToSampleFrame(time[impulseCount], sampleRat e); |
| 163 if (k != expectedOffset) { | 162 if (k != expectedOffset) { |
| 164 timeErrors[timeCount] = { actual : k, expected : expectedOffset} ; | 163 timeErrors[timeCount] = { actual : k, expected : expectedOffset} ; |
| 165 ++timeCount; | 164 ++timeCount; |
| 166 } | 165 } |
| 167 ++impulseCount; | 166 ++impulseCount; |
| 168 } | 167 } |
| 169 } | 168 } |
| 170 | 169 |
| 171 if (impulseCount == nodesToCreate) { | 170 should(impulseCount, "Number of impulses found") |
| 172 testPassed("Number of impulses matches the number of panner nodes."); | 171 .beEqualTo(nodesToCreate); |
| 173 } else { | |
| 174 testFailed("Number of impulses is incorrect. (Found " + impulseCount + " but expected " + nodesToCreate + ")"); | |
| 175 success = false; | |
| 176 } | |
| 177 | 172 |
| 178 if (timeErrors.length > 0) { | 173 should(timeErrors.map(x => x.actual), "Offsets of impulses at the wrong posi tion") |
| 179 success = false; | 174 .beEqualToArray(timeErrors.map(x => x.expected)); |
| 180 testFailed(timeErrors.length + " timing errors found in " + nodesToCreat e + " panner nodes."); | |
| 181 for (var k = 0; k < timeErrors.length; ++k) { | |
| 182 testFailed("Impulse at sample " + timeErrors[k].actual + " but expec ted " + timeErrors[k].expected); | |
| 183 } | |
| 184 } else { | |
| 185 testPassed("All impulses at expected offsets."); | |
| 186 } | |
| 187 | 175 |
| 188 if (maxErrorL <= maxAllowedError) { | 176 should(maxErrorL, "Error in left channel gain values") |
| 189 testPassed("Left channel gain values are correct."); | 177 .beLessThanOrEqualTo(maxAllowedError); |
| 190 } else { | |
| 191 testFailed("Left channel gain values are incorrect. Max error = " + max ErrorL + " at time " + time[maxErrorIndexL] + " (threshold = " + maxAllowedError + ")"); | |
| 192 success = false; | |
| 193 } | |
| 194 | |
| 195 if (maxErrorR <= maxAllowedError) { | |
| 196 testPassed("Right channel gain values are correct."); | |
| 197 } else { | |
| 198 testFailed("Right channel gain values are incorrect. Max error = " + ma xErrorR + " at time " + time[maxErrorIndexR] + " (threshold = " + maxAllowedErro r + ")"); | |
| 199 success = false; | |
| 200 } | |
| 201 | 178 |
| 202 if (success) { | 179 should(maxErrorR, "Error in right channel gain values") |
| 203 testPassed("EqualPower panner test passed"); | 180 .beLessThanOrEqualTo(maxAllowedError); |
| 204 } else { | |
| 205 testFailed("EqualPower panner test failed"); | |
| 206 } | |
| 207 | |
| 208 finishJSTest(); | |
| 209 } | 181 } |
| OLD | NEW |