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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/Panner/panner-automation-position.html

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/Panner/panner-automation-position.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/Panner/panner-automation-position.html b/third_party/WebKit/LayoutTests/webaudio/Panner/panner-automation-position.html
index 9e19068d9fca750c43e61e81ad0f4629cf902ec8..7beabb2edff26c65af6210d36531d73c8728f0ec 100644
--- a/third_party/WebKit/LayoutTests/webaudio/Panner/panner-automation-position.html
+++ b/third_party/WebKit/LayoutTests/webaudio/Panner/panner-automation-position.html
@@ -1,150 +1,152 @@
-<!doctype html>
+<!DOCTYPE html>
<html>
<head>
+ <title>
+ Test Automation of PannerNode Positions
+ </title>
<script src="../../resources/testharness.js"></script>
- <script src="../../resources/testharnessreport.js"></script>
+ <script src="../../resources/testharnessreport.js"></script>
<script src="../resources/audit-util.js"></script>
<script src="../resources/audit.js"></script>
<script src="../resources/panner-formulas.js"></script>
- <title>Test Automation of PannerNode Positions</title>
</head>
-
<body>
- <script>
- var sampleRate = 48000;
- // These tests are quite slow, so don't run for many frames. 256 frames should be enough to
- // demonstrate that automations are working.
- var renderFrames = 256;
- var renderDuration = renderFrames / sampleRate;
-
- var context;
- var panner;
-
- var audit = Audit.createTaskRunner();
-
- // Set of tests for the panner node with automations applied to the position of the source.
- var testConfigs = [{
- // Distance model parameters for the panner
- distanceModel: {
- model: "inverse",
- rolloff: 1
- },
- // Initial location of the source
- startPosition: [0, 0, 1],
- // Final position of the source. For this test, we only want to move on the z axis which
- // doesn't change the azimuth angle.
- endPosition: [0, 0, 10000],
- }, {
- distanceModel: {
- model: "inverse",
- rolloff: 1
+ <script id="layout-test-code">
+ let sampleRate = 48000;
+ // These tests are quite slow, so don't run for many frames. 256 frames
+ // should be enough to demonstrate that automations are working.
+ let renderFrames = 256;
+ let renderDuration = renderFrames / sampleRate;
+
+ let context;
+ let panner;
+
+ let audit = Audit.createTaskRunner();
+
+ // Set of tests for the panner node with automations applied to the
+ // position of the source.
+ let testConfigs = [
+ {
+ // Distance model parameters for the panner
+ distanceModel: {model: 'inverse', rolloff: 1},
+ // Initial location of the source
+ startPosition: [0, 0, 1],
+ // Final position of the source. For this test, we only want to move
+ // on the z axis which
+ // doesn't change the azimuth angle.
+ endPosition: [0, 0, 10000],
},
- startPosition: [0, 0, 1],
- // An essentially random end position, but it should be such that azimuth angle changes as
- // we move from the start to the end.
- endPosition: [20000, 30000, 10000],
- errorThreshold: [{
- // Error threshold for 1-channel case
- relativeThreshold: 4.8124e-7
- }, {
- // Error threshold for 2-channel case
- relativeThreshold: 4.3267e-7
- }],
- }, {
- distanceModel: {
- model: "exponential",
- rolloff: 1.5
+ {
+ distanceModel: {model: 'inverse', rolloff: 1},
+ startPosition: [0, 0, 1],
+ // An essentially random end position, but it should be such that
+ // azimuth angle changes as
+ // we move from the start to the end.
+ endPosition: [20000, 30000, 10000],
+ errorThreshold: [
+ {
+ // Error threshold for 1-channel case
+ relativeThreshold: 4.8124e-7
+ },
+ {
+ // Error threshold for 2-channel case
+ relativeThreshold: 4.3267e-7
+ }
+ ],
},
- startPosition: [0, 0, 1],
- endPosition: [20000, 30000, 10000],
- errorThreshold: [{
- relativeThreshold: 5.0783e-7
- }, {
- relativeThreshold: 5.2180e-7
- }]
- }, {
- distanceModel: {
- model: "linear",
- rolloff: 1
+ {
+ distanceModel: {model: 'exponential', rolloff: 1.5},
+ startPosition: [0, 0, 1],
+ endPosition: [20000, 30000, 10000],
+ errorThreshold:
+ [{relativeThreshold: 5.0783e-7}, {relativeThreshold: 5.2180e-7}]
},
- startPosition: [0, 0, 1],
- endPosition: [20000, 30000, 10000],
- errorThreshold: [{
- relativeThreshold: 6.5324e-6
- }, {
- relativeThreshold: 6.5756e-6
- }]
- }];
-
- for (var k = 0; k < testConfigs.length; ++k) {
- var config = testConfigs[k];
- var tester = function (c, channelCount) {
+ {
+ distanceModel: {model: 'linear', rolloff: 1},
+ startPosition: [0, 0, 1],
+ endPosition: [20000, 30000, 10000],
+ errorThreshold: [
+ {relativeThreshold: 6.5324e-6}, {relativeThreshold: 6.5756e-6}
+ ]
+ }
+ ];
+
+ for (let k = 0; k < testConfigs.length; ++k) {
+ let config = testConfigs[k];
+ let tester = function(c, channelCount) {
return (task, should) => {
- runTest(should, c, channelCount)
- .then(() => task.done());
+ runTest(should, c, channelCount).then(() => task.done());
}
};
- var baseTestName = config.distanceModel.model + " rolloff: " + config.distanceModel.rolloff;
+ let baseTestName = config.distanceModel.model +
+ ' rolloff: ' + config.distanceModel.rolloff;
// Define tasks for both 1-channel and 2-channel
- audit.define(k + ": 1-channel " + baseTestName, tester(config, 1));
- audit.define(k + ": 2-channel " + baseTestName, tester(config, 2));
+ audit.define(k + ': 1-channel ' + baseTestName, tester(config, 1));
+ audit.define(k + ': 2-channel ' + baseTestName, tester(config, 2));
}
audit.run();
function runTest(should, options, channelCount) {
- // Output has 5 channels: channels 0 and 1 are for the stereo output of the panner node.
- // Channels 2-5 are the for automation of the x,y,z coordinate so that we have actual
- // coordinates used for the panner automation.
+ // Output has 5 channels: channels 0 and 1 are for the stereo output of
+ // the panner node. Channels 2-5 are the for automation of the x,y,z
+ // coordinate so that we have actual coordinates used for the panner
+ // automation.
context = new OfflineAudioContext(5, renderFrames, sampleRate);
// Stereo source for the panner.
- var source = context.createBufferSource();
- source.buffer = createConstantBuffer(context, renderFrames, channelCount == 1 ? 1 : [1, 2]);
+ let source = context.createBufferSource();
+ source.buffer = createConstantBuffer(
+ context, renderFrames, channelCount == 1 ? 1 : [1, 2]);
panner = context.createPanner();
panner.distanceModel = options.distanceModel.model;
panner.rolloffFactor = options.distanceModel.rolloff;
- panner.panningModel = "equalpower";
+ panner.panningModel = 'equalpower';
// Source and gain node for the z-coordinate calculation.
- var dist = context.createBufferSource();
+ let dist = context.createBufferSource();
dist.buffer = createConstantBuffer(context, 1, 1);
dist.loop = true;
- var gainX = context.createGain();
- var gainY = context.createGain();
- var gainZ = context.createGain();
+ let gainX = context.createGain();
+ let gainY = context.createGain();
+ let gainZ = context.createGain();
dist.connect(gainX);
dist.connect(gainY);
dist.connect(gainZ);
- // Set the gain automation to match the z-coordinate automation of the panner.
+ // Set the gain automation to match the z-coordinate automation of the
+ // panner.
- // End the automation some time before the end of the rendering so we can verify that
- // automation has the correct end time and value.
- var endAutomationTime = 0.75 * renderDuration;
+ // End the automation some time before the end of the rendering so we
+ // can verify that automation has the correct end time and value.
+ let endAutomationTime = 0.75 * renderDuration;
gainX.gain.setValueAtTime(options.startPosition[0], 0);
- gainX.gain.linearRampToValueAtTime(options.endPosition[0], endAutomationTime);
+ gainX.gain.linearRampToValueAtTime(
+ options.endPosition[0], endAutomationTime);
gainY.gain.setValueAtTime(options.startPosition[1], 0);
- gainY.gain.linearRampToValueAtTime(options.endPosition[1], endAutomationTime);
+ gainY.gain.linearRampToValueAtTime(
+ options.endPosition[1], endAutomationTime);
gainZ.gain.setValueAtTime(options.startPosition[2], 0);
- gainZ.gain.linearRampToValueAtTime(options.endPosition[2], endAutomationTime);
+ gainZ.gain.linearRampToValueAtTime(
+ options.endPosition[2], endAutomationTime);
dist.start();
- // Splitter and merger to map the panner output and the z-coordinate automation to the
- // correct channels in the destination.
- var splitter = context.createChannelSplitter(2);
- var merger = context.createChannelMerger(5);
+ // Splitter and merger to map the panner output and the z-coordinate
+ // automation to the correct channels in the destination.
+ let splitter = context.createChannelSplitter(2);
+ let merger = context.createChannelMerger(5);
source.connect(panner);
// Split the output of the panner to separate channels
panner.connect(splitter);
- // Merge the panner outputs and the z-coordinate output to the correct destination channels.
+ // Merge the panner outputs and the z-coordinate output to the correct
+ // destination channels.
splitter.connect(merger, 0, 0);
splitter.connect(merger, 1, 1);
gainX.connect(merger, 0, 2);
@@ -159,101 +161,104 @@
panner.positionZ.setValueAtTime(options.startPosition[2], 0);
// Automate z coordinate to move away from the listener
- panner.positionX.linearRampToValueAtTime(options.endPosition[0], 0.75 * renderDuration);
- panner.positionY.linearRampToValueAtTime(options.endPosition[1], 0.75 * renderDuration);
- panner.positionZ.linearRampToValueAtTime(options.endPosition[2], 0.75 * renderDuration);
+ panner.positionX.linearRampToValueAtTime(
+ options.endPosition[0], 0.75 * renderDuration);
+ panner.positionY.linearRampToValueAtTime(
+ options.endPosition[1], 0.75 * renderDuration);
+ panner.positionZ.linearRampToValueAtTime(
+ options.endPosition[2], 0.75 * renderDuration);
source.start();
// Go!
- return context.startRendering()
- .then(function (renderedBuffer) {
- // Get the panner outputs
- var data0 = renderedBuffer.getChannelData(0);
- var data1 = renderedBuffer.getChannelData(1);
- var xcoord = renderedBuffer.getChannelData(2);
- var ycoord = renderedBuffer.getChannelData(3);
- var zcoord = renderedBuffer.getChannelData(4);
-
- // We're doing a linear ramp on the Z axis with the equalpower panner, so the equalpower
- // panning gain remains constant. We only need to model the distance effect.
-
- // Compute the distance gain
- var distanceGain = new Float32Array(xcoord.length);;
-
- if (panner.distanceModel === "inverse") {
- for (var k = 0; k < distanceGain.length; ++k) {
- distanceGain[k] = inverseDistance(panner, xcoord[k], ycoord[k], zcoord[k])
- }
- } else if (panner.distanceModel === "linear") {
- for (var k = 0; k < distanceGain.length; ++k) {
- distanceGain[k] = linearDistance(panner, xcoord[k], ycoord[k], zcoord[k])
- }
- } else if (panner.distanceModel === "exponential") {
- for (var k = 0; k < distanceGain.length; ++k) {
- distanceGain[k] = exponentialDistance(panner, xcoord[k], ycoord[k], zcoord[k])
- }
+ return context.startRendering().then(function(renderedBuffer) {
+ // Get the panner outputs
+ let data0 = renderedBuffer.getChannelData(0);
+ let data1 = renderedBuffer.getChannelData(1);
+ let xcoord = renderedBuffer.getChannelData(2);
+ let ycoord = renderedBuffer.getChannelData(3);
+ let zcoord = renderedBuffer.getChannelData(4);
+
+ // We're doing a linear ramp on the Z axis with the equalpower panner,
+ // so the equalpower panning gain remains constant. We only need to
+ // model the distance effect.
+
+ // Compute the distance gain
+ let distanceGain = new Float32Array(xcoord.length);
+ ;
+
+ if (panner.distanceModel === 'inverse') {
+ for (let k = 0; k < distanceGain.length; ++k) {
+ distanceGain[k] =
+ inverseDistance(panner, xcoord[k], ycoord[k], zcoord[k])
}
-
- // Compute the expected result. Since we're on the z-axis, the left and right channels
- // pass through the equalpower panner unchanged. Only need to apply the distance gain.
- var buffer0 = source.buffer.getChannelData(0);
- var buffer1 = channelCount == 2 ? source.buffer.getChannelData(1) : buffer0;
-
- var azimuth = new Float32Array(buffer0.length);
-
- for (var k = 0; k < data0.length; ++k) {
- azimuth[k] = calculateAzimuth([
- xcoord[k],
- ycoord[k],
- zcoord[k]
- ], [
- context.listener.positionX.value,
- context.listener.positionY.value,
- context.listener.positionZ.value
- ], [
- context.listener.forwardX.value,
- context.listener.forwardY.value,
- context.listener.forwardZ.value
- ], [
- context.listener.upX.value,
- context.listener.upY.value,
- context.listener.upZ.value
- ]);
+ } else if (panner.distanceModel === 'linear') {
+ for (let k = 0; k < distanceGain.length; ++k) {
+ distanceGain[k] =
+ linearDistance(panner, xcoord[k], ycoord[k], zcoord[k])
}
-
- var expected = applyPanner(azimuth, buffer0, buffer1, channelCount);
- var expected0 = expected.left;
- var expected1 = expected.right;
-
- for (var k = 0; k < expected0.length; ++k) {
- expected0[k] *= distanceGain[k];
- expected1[k] *= distanceGain[k];
+ } else if (panner.distanceModel === 'exponential') {
+ for (let k = 0; k < distanceGain.length; ++k) {
+ distanceGain[k] =
+ exponentialDistance(panner, xcoord[k], ycoord[k], zcoord[k])
}
+ }
+
+ // Compute the expected result. Since we're on the z-axis, the left
+ // and right channels pass through the equalpower panner unchanged.
+ // Only need to apply the distance gain.
+ let buffer0 = source.buffer.getChannelData(0);
+ let buffer1 =
+ channelCount == 2 ? source.buffer.getChannelData(1) : buffer0;
+
+ let azimuth = new Float32Array(buffer0.length);
+
+ for (let k = 0; k < data0.length; ++k) {
+ azimuth[k] = calculateAzimuth(
+ [xcoord[k], ycoord[k], zcoord[k]],
+ [
+ context.listener.positionX.value,
+ context.listener.positionY.value,
+ context.listener.positionZ.value
+ ],
+ [
+ context.listener.forwardX.value,
+ context.listener.forwardY.value,
+ context.listener.forwardZ.value
+ ],
+ [
+ context.listener.upX.value, context.listener.upY.value,
+ context.listener.upZ.value
+ ]);
+ }
+
+ let expected = applyPanner(azimuth, buffer0, buffer1, channelCount);
+ let expected0 = expected.left;
+ let expected1 = expected.right;
+
+ for (let k = 0; k < expected0.length; ++k) {
+ expected0[k] *= distanceGain[k];
+ expected1[k] *= distanceGain[k];
+ }
+
+ let info = options.distanceModel.model +
+ ', rolloff: ' + options.distanceModel.rolloff;
+ let prefix = channelCount + '-channel ' +
+ '[' + options.startPosition[0] + ', ' + options.startPosition[1] +
+ ', ' + options.startPosition[2] + '] -> [' +
+ options.endPosition[0] + ', ' + options.endPosition[1] + ', ' +
+ options.endPosition[2] + ']: ';
+
+ let errorThreshold = 0;
+
+ if (options.errorThreshold)
+ errorThreshold = options.errorThreshold[channelCount - 1]
- var info = options.distanceModel.model + ", rolloff: " + options.distanceModel.rolloff;
- var prefix = channelCount + "-channel "
- + "[" + options.startPosition[0] + ", "
- + options.startPosition[1] + ", "
- + options.startPosition[2] + "] -> ["
- + options.endPosition[0] + ", "
- + options.endPosition[1] + ", "
- + options.endPosition[2] + "]: ";
-
- var errorThreshold = 0;
-
- if (options.errorThreshold)
- errorThreshold = options.errorThreshold[channelCount - 1]
-
- should(data0, prefix + "distanceModel: " + info + ", left channel")
- .beCloseToArray(expected0, {
- absoluteThreshold: errorThreshold
- });
- should(data1, prefix + "distanceModel: " + info + ", right channel")
- .beCloseToArray(expected1, {
- absoluteThreshold: errorThreshold
- });
- });
+ should(data0, prefix + 'distanceModel: ' + info + ', left channel')
+ .beCloseToArray(expected0, {absoluteThreshold: errorThreshold});
+ should(data1, prefix + 'distanceModel: ' + info + ', right channel')
+ .beCloseToArray(expected1, {absoluteThreshold: errorThreshold});
+ });
}
</script>
</body>

Powered by Google App Engine
This is Rietveld 408576698