Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Unified Diff: third_party/WebKit/LayoutTests/webaudio/resources/panner-model-testing.js

Issue 2895963003: Apply layout-test-tidy to LayoutTests/webaudio (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/webaudio/resources/panner-model-testing.js
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/panner-model-testing.js b/third_party/WebKit/LayoutTests/webaudio/resources/panner-model-testing.js
index cf9c8287edfc934a7fe58308a6b71be847657b69..8eb07050be7fac88156caf15b9c5ab260605ee32 100644
--- a/third_party/WebKit/LayoutTests/webaudio/resources/panner-model-testing.js
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/panner-model-testing.js
@@ -21,162 +21,161 @@ var bufferSource;
var panner;
var position;
var time;
-
+
var renderedBuffer;
var renderedLeft;
var renderedRight;
function createGraph(context, nodeCount, positionSetter) {
- bufferSource = new Array(nodeCount);
- panner = new Array(nodeCount);
- position = new Array(nodeCount);
- time = new Array(nodeCount);
- // Angle between panner locations. (nodeCount - 1 because we want
- // to include both 0 and 180 deg.
- var angleStep = Math.PI / (nodeCount - 1);
-
- if (numberOfChannels == 2) {
- impulse = createStereoImpulseBuffer(context, pulseLengthFrames);
- }
- else
- impulse = createImpulseBuffer(context, pulseLengthFrames);
-
- for (var k = 0; k < nodeCount; ++k) {
- bufferSource[k] = context.createBufferSource();
- bufferSource[k].buffer = impulse;
-
- panner[k] = context.createPanner();
- panner[k].panningModel = "equalpower";
- panner[k].distanceModel = "linear";
-
- var angle = angleStep * k;
- position[k] = {angle : angle, x : Math.cos(angle), z : Math.sin(angle)};
- positionSetter(panner[k], position[k].x, 0, position[k].z);
-
- bufferSource[k].connect(panner[k]);
- panner[k].connect(context.destination);
-
- // Start the source
- time[k] = k * timeStep;
- bufferSource[k].start(time[k]);
- }
+ bufferSource = new Array(nodeCount);
+ panner = new Array(nodeCount);
+ position = new Array(nodeCount);
+ time = new Array(nodeCount);
+ // Angle between panner locations. (nodeCount - 1 because we want
+ // to include both 0 and 180 deg.
+ let angleStep = Math.PI / (nodeCount - 1);
+
+ if (numberOfChannels == 2) {
+ impulse = createStereoImpulseBuffer(context, pulseLengthFrames);
+ } else
+ impulse = createImpulseBuffer(context, pulseLengthFrames);
+
+ for (let k = 0; k < nodeCount; ++k) {
+ bufferSource[k] = context.createBufferSource();
+ bufferSource[k].buffer = impulse;
+
+ panner[k] = context.createPanner();
+ panner[k].panningModel = 'equalpower';
+ panner[k].distanceModel = 'linear';
+
+ let angle = angleStep * k;
+ position[k] = {angle: angle, x: Math.cos(angle), z: Math.sin(angle)};
+ positionSetter(panner[k], position[k].x, 0, position[k].z);
+
+ bufferSource[k].connect(panner[k]);
+ panner[k].connect(context.destination);
+
+ // Start the source
+ time[k] = k * timeStep;
+ bufferSource[k].start(time[k]);
+ }
}
-function createTestAndRun(context, should, nodeCount, numberOfSourceChannels,
- positionSetter) {
- numberOfChannels = numberOfSourceChannels;
+function createTestAndRun(
+ context, should, nodeCount, numberOfSourceChannels, positionSetter) {
+ numberOfChannels = numberOfSourceChannels;
- createGraph(context, nodeCount, positionSetter);
+ createGraph(context, nodeCount, positionSetter);
- return context.startRendering()
- .then(buffer => checkResult(buffer, should));
+ return context.startRendering().then(buffer => checkResult(buffer, should));
}
// Map our position angle to the azimuth angle (in degrees).
//
// An angle of 0 corresponds to an azimuth of 90 deg; pi, to -90 deg.
function angleToAzimuth(angle) {
- return 90 - angle * 180 / Math.PI;
+ return 90 - angle * 180 / Math.PI;
}
// The gain caused by the EQUALPOWER panning model
function equalPowerGain(angle) {
- var azimuth = angleToAzimuth(angle);
+ let azimuth = angleToAzimuth(angle);
+
+ if (numberOfChannels == 1) {
+ let panPosition = (azimuth + 90) / 180;
- if (numberOfChannels == 1) {
- var panPosition = (azimuth + 90) / 180;
+ let gainL = Math.cos(0.5 * Math.PI * panPosition);
+ let gainR = Math.sin(0.5 * Math.PI * panPosition);
- var gainL = Math.cos(0.5 * Math.PI * panPosition);
- var gainR = Math.sin(0.5 * Math.PI * panPosition);
+ return {left: gainL, right: gainR};
+ } else {
+ if (azimuth <= 0) {
+ let panPosition = (azimuth + 90) / 90;
- return { left : gainL, right : gainR };
+ let gainL = 1 + Math.cos(0.5 * Math.PI * panPosition);
+ let gainR = Math.sin(0.5 * Math.PI * panPosition);
+
+ return {left: gainL, right: gainR};
} else {
- if (azimuth <= 0) {
- var panPosition = (azimuth + 90) / 90;
-
- var gainL = 1 + Math.cos(0.5 * Math.PI * panPosition);
- var gainR = Math.sin(0.5 * Math.PI * panPosition);
-
- return { left : gainL, right : gainR };
- } else {
- var panPosition = azimuth / 90;
-
- var gainL = Math.cos(0.5 * Math.PI * panPosition);
- var gainR = 1 + Math.sin(0.5 * Math.PI * panPosition);
-
- return { left : gainL, right : gainR };
- }
+ let panPosition = azimuth / 90;
+
+ let gainL = Math.cos(0.5 * Math.PI * panPosition);
+ let gainR = 1 + Math.sin(0.5 * Math.PI * panPosition);
+
+ return {left: gainL, right: gainR};
}
+ }
}
function checkResult(renderedBuffer, should) {
- renderedLeft = renderedBuffer.getChannelData(0);
- renderedRight = renderedBuffer.getChannelData(1);
-
- // The max error we allow between the rendered impulse and the
- // expected value. This value is experimentally determined. Set
- // to 0 to make the test fail to see what the actual error is.
- var maxAllowedError = 1.3e-6;
-
- var success = true;
-
- // Number of impulses found in the rendered result.
- var impulseCount = 0;
-
- // Max (relative) error and the index of the maxima for the left
- // and right channels.
- var maxErrorL = 0;
- var maxErrorIndexL = 0;
- var maxErrorR = 0;
- var maxErrorIndexR = 0;
-
- // Number of impulses that don't match our expected locations.
- var timeCount = 0;
-
- // Locations of where the impulses aren't at the expected locations.
- var timeErrors = new Array();
-
- for (var k = 0; k < renderedLeft.length; ++k) {
- // We assume that the left and right channels start at the same instant.
- if (renderedLeft[k] != 0 || renderedRight[k] != 0) {
- // The expected gain for the left and right channels.
- var pannerGain = equalPowerGain(position[impulseCount].angle);
- var expectedL = pannerGain.left;
- var expectedR = pannerGain.right;
-
- // Absolute error in the gain.
- var errorL = Math.abs(renderedLeft[k] - expectedL);
- var errorR = Math.abs(renderedRight[k] - expectedR);
-
- if (Math.abs(errorL) > maxErrorL) {
- maxErrorL = Math.abs(errorL);
- maxErrorIndexL = impulseCount;
- }
- if (Math.abs(errorR) > maxErrorR) {
- maxErrorR = Math.abs(errorR);
- maxErrorIndexR = impulseCount;
- }
-
- // Keep track of the impulses that didn't show up where we
- // expected them to be.
- var expectedOffset = timeToSampleFrame(time[impulseCount], sampleRate);
- if (k != expectedOffset) {
- timeErrors[timeCount] = { actual : k, expected : expectedOffset};
- ++timeCount;
- }
- ++impulseCount;
- }
+ renderedLeft = renderedBuffer.getChannelData(0);
+ renderedRight = renderedBuffer.getChannelData(1);
+
+ // The max error we allow between the rendered impulse and the
+ // expected value. This value is experimentally determined. Set
+ // to 0 to make the test fail to see what the actual error is.
+ let maxAllowedError = 1.3e-6;
+
+ let success = true;
+
+ // Number of impulses found in the rendered result.
+ let impulseCount = 0;
+
+ // Max (relative) error and the index of the maxima for the left
+ // and right channels.
+ let maxErrorL = 0;
+ let maxErrorIndexL = 0;
+ let maxErrorR = 0;
+ let maxErrorIndexR = 0;
+
+ // Number of impulses that don't match our expected locations.
+ let timeCount = 0;
+
+ // Locations of where the impulses aren't at the expected locations.
+ let timeErrors = new Array();
+
+ for (let k = 0; k < renderedLeft.length; ++k) {
+ // We assume that the left and right channels start at the same instant.
+ if (renderedLeft[k] != 0 || renderedRight[k] != 0) {
+ // The expected gain for the left and right channels.
+ let pannerGain = equalPowerGain(position[impulseCount].angle);
+ let expectedL = pannerGain.left;
+ let expectedR = pannerGain.right;
+
+ // Absolute error in the gain.
+ let errorL = Math.abs(renderedLeft[k] - expectedL);
+ let errorR = Math.abs(renderedRight[k] - expectedR);
+
+ if (Math.abs(errorL) > maxErrorL) {
+ maxErrorL = Math.abs(errorL);
+ maxErrorIndexL = impulseCount;
+ }
+ if (Math.abs(errorR) > maxErrorR) {
+ maxErrorR = Math.abs(errorR);
+ maxErrorIndexR = impulseCount;
+ }
+
+ // Keep track of the impulses that didn't show up where we
+ // expected them to be.
+ let expectedOffset = timeToSampleFrame(time[impulseCount], sampleRate);
+ if (k != expectedOffset) {
+ timeErrors[timeCount] = {actual: k, expected: expectedOffset};
+ ++timeCount;
+ }
+ ++impulseCount;
}
+ }
- should(impulseCount, "Number of impulses found")
- .beEqualTo(nodesToCreate);
+ should(impulseCount, 'Number of impulses found').beEqualTo(nodesToCreate);
- should(timeErrors.map(x => x.actual), "Offsets of impulses at the wrong position")
- .beEqualToArray(timeErrors.map(x => x.expected));
+ should(
+ timeErrors.map(x => x.actual),
+ 'Offsets of impulses at the wrong position')
+ .beEqualToArray(timeErrors.map(x => x.expected));
- should(maxErrorL, "Error in left channel gain values")
- .beLessThanOrEqualTo(maxAllowedError);
+ should(maxErrorL, 'Error in left channel gain values')
+ .beLessThanOrEqualTo(maxAllowedError);
- should(maxErrorR, "Error in right channel gain values")
- .beLessThanOrEqualTo(maxAllowedError);
+ should(maxErrorR, 'Error in right channel gain values')
+ .beLessThanOrEqualTo(maxAllowedError);
}

Powered by Google App Engine
This is Rietveld 408576698