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

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

Issue 1820403002: Implement Automations for PannerNode and AutioListener (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase UseCounter.h Created 4 years, 8 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-automation-position.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/panner-automation-position.html b/third_party/WebKit/LayoutTests/webaudio/panner-automation-position.html
new file mode 100644
index 0000000000000000000000000000000000000000..0b73411f409230400c97eb2e71d0fde6fd5db279
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/panner-automation-position.html
@@ -0,0 +1,243 @@
+<!doctype html>
+<html>
+ <head>
+ <script src="../resources/js-test.js"></script>
+ <script src="resources/compatibility.js"></script>
+ <script src="resources/audio-testing.js"></script>
+ <script src="resources/panner-formulas.js"></script>
+ <title>Test Automation of SpatialPanner Position</title>
+ </head>
+
+ <body>
+ <script>
+ description("Test Automation of SpatialPannerNode Position.");
+ window.jsTestIsAsync = true;
+
+ 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();
+
+ audit.defineTask("z only", function (done) {
+ runTest({
+ distanceModel: {
+ model: "inverse",
+ rolloff: 1
+ },
+ startPosition: [0, 0, 1],
+ endPosition: [0, 0, 10000],
+ })
+ .then(done);
+ });
+
+ audit.defineTask("inverse", function (done) {
+ runTest({
+ distanceModel: {
+ model: "inverse",
+ rolloff: 1
+ },
+ startPosition: [0, 0, 1],
+ endPosition: [20000, 20000, 20000],
+ errorThreshold: { relativeThreshold: 4.0842e-7}
+ })
+ .then(done);
+ });
+
+ audit.defineTask("exponential", function (done) {
+ runTest({
+ distanceModel: {
+ model: "exponential",
+ rolloff: 1.5
+ },
+ startPosition: [0, 0, 1],
+ endPosition: [20000, 20000, 20000],
+ errorThreshold: { relativeThreshold: 3.4117e-7}
+ })
+ .then(done);
+ });
+
+ audit.defineTask("linear", function (done) {
+ runTest({
+ distanceModel: {
+ model: "linear",
+ rolloff: 1
+ },
+ startPosition: [0, 0, 1],
+ endPosition: [20000, 20000, 20000],
+ errorThreshold: { relativeThreshold: 6.5756e-6}
+ })
+ .then(done);
+ });
+
+ audit.defineTask("finish", function (done) {
+ finishJSTest();
+ done();
+ });
+
+ audit.runTasks();
+
+ function runTest(options) {
+ // 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, [1, 2]);
+
+ panner = context.createPanner();
+ panner.distanceModel = options.distanceModel.model;
+ panner.rolloffFactor = options.distanceModel.rolloff;
+ panner.panningModel = "equalpower";
+ //console.log("distanceModel = " + panner.distanceModel);
+
+ // Source and gain node for the z-coordinate calculation.
+ var dist = context.createBufferSource();
+ dist.buffer = createConstantBuffer(context, 1, 1);
+ dist.loop = true;
+ var gainX = context.createGain();
+ var gainY = context.createGain();
+ var 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.
+ gainX.gain.setValueAtTime(options.startPosition[0], 0);
+ gainX.gain.linearRampToValueAtTime(options.endPosition[0], 0.75 * renderDuration);
+ gainY.gain.setValueAtTime(options.startPosition[1], 0);
+ gainY.gain.linearRampToValueAtTime(options.endPosition[1], 0.75 * renderDuration);
+ gainZ.gain.setValueAtTime(options.startPosition[2], 0);
+ gainZ.gain.linearRampToValueAtTime(options.endPosition[2], 0.75 * renderDuration);
+
+ 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);
+
+ 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.
+ splitter.connect(merger, 0, 0);
+ splitter.connect(merger, 1, 1);
+ gainX.connect(merger, 0, 2);
+ gainY.connect(merger, 0, 3);
+ gainZ.connect(merger, 0, 4);
+
+ merger.connect(context.destination);
+
+ // Initialize starting point of the panner.
+ panner.positionX.setValueAtTime(options.startPosition[0], 0);
+ panner.positionY.setValueAtTime(options.startPosition[1], 0);
+ 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);
+
+ 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);
+
+ //console.log("data0");
+ //console.log(data0);
+
+ // 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.
+
+ //console.log("zcoord");
+ //console.log(zcoord);
+
+ // 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])
+ }
+ }
+
+ //console.log("distanceGain");
+ //console.log(distanceGain);
+ // 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 = source.buffer.getChannelData(1);
+
+ 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
+ ]);
+ }
+
+ var expected = applyPanner(azimuth, buffer0, buffer1, 2);
+ var expected0 = expected.left;
+ var expected1 = expected.right;
+
+ for (var k = 0; k < expected0.length; ++k) {
+ expected0[k] *= distanceGain[k];
+ expected1[k] *= distanceGain[k];
+ }
+
+ var info = options.distanceModel.model + ", rolloff: " + options.distanceModel.rolloff;
+ var prefix = "[" + options.startPosition[0] + ", ";
+ prefix += options.startPosition[1] + ", ";
+ prefix += options.startPosition[2];
+ prefix += "] -> [";
+ prefix += options.endPosition[0] + ", ";
+ prefix += options.endPosition[1] + ", ";
+ prefix += options.endPosition[2] + "]: ";
+
+
+
+ Should(prefix + "distanceModel: " + info + ", left channel", data0, {
+ verbose: true
+ })
+ .beCloseToArray(expected0, options.errorThreshold || 0);
+ Should(prefix + "distanceModel: " + info + ", right channel", data1, {
+ verbose: true
+ })
+ .beCloseToArray(expected1, options.errorThreshold || 0);
+ });
+ }
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698