| Index: third_party/WebKit/LayoutTests/webaudio/panner-rolloff-clamping.html
|
| diff --git a/third_party/WebKit/LayoutTests/webaudio/panner-rolloff-clamping.html b/third_party/WebKit/LayoutTests/webaudio/panner-rolloff-clamping.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0f1d7edf1de14befa837890eb4e99c88657c8da9
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/webaudio/panner-rolloff-clamping.html
|
| @@ -0,0 +1,129 @@
|
| +<!doctype html>
|
| +<html>
|
| + <head>
|
| + <title>Test Clamping of PannerNode rolloffFactor</title>
|
| + <script src="../resources/testharness.js"></script>
|
| + <script src="../resources/testharnessreport.js"></script>
|
| + <script src="resources/audio-testing.js"></script>
|
| + </head>
|
| +
|
| + <body>
|
| + <script>
|
| + // Fairly arbitrary sample rate and render frames.
|
| + var sampleRate = 16000;
|
| + var renderFrames = 2048;
|
| +
|
| + var audit = Audit.createTaskRunner();
|
| +
|
| + audit.defineTask("linear-clamp-low", function (taskDone) {
|
| + runTest({
|
| + distanceModel: "linear",
|
| + // Fairly arbitrary value outside the nominal range
|
| + rolloffFactor: -1,
|
| + clampedRolloff: 0
|
| + }).then(taskDone);
|
| + });
|
| +
|
| + audit.defineTask("linear-clamp-high", function (taskDone) {
|
| + runTest({
|
| + distanceModel: "linear",
|
| + // Fairly arbitrary value outside the nominal range
|
| + rolloffFactor: 2,
|
| + clampedRolloff: 1
|
| + }).then(taskDone);
|
| + });
|
| +
|
| + audit.defineTask("inverse-clamp", function (taskDone) {
|
| + runTest({
|
| + distanceModel: "inverse",
|
| + // Fairly arbitrary value outside the nominal range
|
| + rolloffFactor: -1,
|
| + clampedRolloff: 0
|
| + }).then(taskDone);
|
| + });
|
| +
|
| + audit.defineTask("exponential-clamp", function (taskDone) {
|
| + runTest({
|
| + distanceModel: "exponential",
|
| + // Fairly arbitrary value outside the nominal range
|
| + rolloffFactor: -2,
|
| + clampedRolloff: 0
|
| + }).then(taskDone);
|
| + });
|
| +
|
| + // Test clamping of the rolloffFactor. The test is done by comparing the
|
| + // output of a panner with the rolloffFactor set outside the nominal range
|
| + // against the output of a panner with the rolloffFactor clamped to the
|
| + // nominal range. The outputs should be the same.
|
| + //
|
| + // The |options| dictionary should contain the members
|
| + // distanceModel - The distance model to use for the panners
|
| + // rolloffFactor - The desired rolloffFactor. Should be outside the
|
| + // nominal range of the distance model.
|
| + // clampedRolloff - The rolloffFactor (above) clamped to the nominal
|
| + // range for the given distance model.
|
| + function runTest(options) {
|
| + // Offline context with two channels. The first channel is the panner
|
| + // node under test. The second channel is the reference panner node.
|
| + var context = new OfflineAudioContext(2, renderFrames, sampleRate);
|
| +
|
| + // The source for the panner nodes. This is fairly arbitrary.
|
| + var src = new OscillatorNode(context, {
|
| + type: "sawtooth"
|
| + });
|
| +
|
| + // Create the test panner with the specified rolloff factor. The
|
| + // position is fairly arbitrary, but something that is not the default
|
| + // is good to show the distance model had some effect.
|
| + var pannerTest = new PannerNode(context, {
|
| + rolloffFactor: options.rolloffFactor,
|
| + distanceModel: options.distanceModel,
|
| + positionX: 5000
|
| + });
|
| +
|
| + // Create the reference panner with the rolloff factor clamped to the
|
| + // appropriate limit.
|
| + var pannerRef = new PannerNode(context, {
|
| + rolloffFactor: options.clampedRolloff,
|
| + distanceModel: options.distanceModel,
|
| + positionX: 5000
|
| + });
|
| +
|
| +
|
| + // Connect the source to the panners to the destination appropriately.
|
| + var merger = new ChannelMergerNode(context, {
|
| + numberOfInputs: 2
|
| + });
|
| +
|
| +
|
| + src.connect(pannerTest).connect(merger, 0, 0);
|
| + src.connect(pannerRef).connect(merger, 0, 1);
|
| +
|
| + merger.connect(context.destination);
|
| +
|
| + src.start();
|
| +
|
| + return context.startRendering()
|
| + .then(function (resultBuffer) {
|
| + // The two channels should be the same due to the clamping. Verify
|
| + // that they are the same.
|
| + var actual = resultBuffer.getChannelData(0);
|
| + var expected = resultBuffer.getChannelData(1);
|
| +
|
| + var message = 'Panner distanceModel: "' + options.distanceModel +
|
| + '", rolloffFactor: ' + options.rolloffFactor;
|
| +
|
| + var success = Should(message, actual)
|
| + .beEqualToArray(expected);
|
| +
|
| + Should(message, success)
|
| + .summarize(
|
| + "correctly clamped rolloffFactor to " + options.clampedRolloff,
|
| + "did not correctly clamp rolloffFactor to " + options.clampedRolloff);
|
| + });
|
| + }
|
| +
|
| + audit.runTasks();
|
| + </script>
|
| + </body>
|
| +</html>
|
|
|