Index: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-sampling.html |
diff --git a/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-sampling.html b/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-sampling.html |
index 930e2c96de40a9d617ff5248d0aa4516b9da3592..bb06289a7d94e55dbb7fe36f80605e9f3c34814a 100644 |
--- a/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-sampling.html |
+++ b/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-sampling.html |
@@ -1,35 +1,35 @@ |
-<!doctype html> |
+<!DOCTYPE html> |
<html> |
<head> |
+ <title> |
+ Test Sampling of LinearRampToValueAtTime |
+ </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/audioparam-testing.js"></script> |
- <title>Test Sampling of LinearRampToValueAtTime</title> |
</head> |
- |
<body> |
- <script> |
- |
- var sampleRate = 12800; |
- var context; |
+ <script id="layout-test-code"> |
+ let sampleRate = 12800; |
+ let context; |
- var audit = Audit.createTaskRunner(); |
+ let audit = Audit.createTaskRunner(); |
function runTest(should, config) { |
- // Create a short context with a constant signal source connected to a gain node that will |
- // be automated. |
+ // Create a short context with a constant signal source connected to a |
+ // gain node that will be automated. |
context = new OfflineAudioContext(1, 256, sampleRate); |
// Create a constant unit amplitude source. |
- var source = context.createBufferSource(); |
- var b = createConstantBuffer(context, 1, 1); |
+ let source = context.createBufferSource(); |
+ let b = createConstantBuffer(context, 1, 1); |
source.buffer = b; |
source.loop = true; |
// Gain node that is to be automated. |
- var gain = context.createGain(); |
+ let gain = context.createGain(); |
gain.gain.value = 0; |
gain.gain.setValueAtTime(config.startValue, config.startTime); |
config.automationFunction(gain); |
@@ -39,37 +39,39 @@ |
source.start(); |
- return context.startRendering().then(function (resultBuffer) { |
+ return context.startRendering().then(function(resultBuffer) { |
// Check that the automation has the correct sampling. |
- var resultData = resultBuffer.getChannelData(0); |
+ let resultData = resultBuffer.getChannelData(0); |
- // The automation has starts at config.startTime, so the frame just after this should have |
- // the automation applied. |
- var startFrame = Math.ceil(config.startTime * sampleRate); |
+ // The automation has starts at config.startTime, so the frame just |
+ // after this should have the automation applied. |
+ let startFrame = Math.ceil(config.startTime * sampleRate); |
- // The automation ends at config.endTime so the frame just before this should have the |
- // automation applied. |
- var endFrame = Math.floor(config.endTime * sampleRate); |
+ // The automation ends at config.endTime so the frame just before this |
+ // should have the automation applied. |
+ let endFrame = Math.floor(config.endTime * sampleRate); |
// Use the true automation to find the expected values. |
- var expectedStart = config.expectedFunction(startFrame / sampleRate); |
- var expectedEnd = config.expectedFunction(endFrame / sampleRate); |
- |
- should(resultData[startFrame], config.desc + ": Sample " + startFrame) |
- .beCloseTo(expectedStart, {threshold: config.startValueThreshold}); |
- should(resultData[endFrame], config.desc + ": Sample " + endFrame) |
- .beCloseTo(expectedEnd, {threshold: config.endValueThreshold}); |
+ let expectedStart = config.expectedFunction(startFrame / sampleRate); |
+ let expectedEnd = config.expectedFunction(endFrame / sampleRate); |
+ |
+ should(resultData[startFrame], config.desc + ': Sample ' + startFrame) |
+ .beCloseTo( |
+ expectedStart, {threshold: config.startValueThreshold}); |
+ should(resultData[endFrame], config.desc + ': Sample ' + endFrame) |
+ .beCloseTo(expectedEnd, {threshold: config.endValueThreshold}); |
}); |
} |
function expectedLinear(t) { |
- var slope = (this.endValue - this.startValue) / (this.endTime - this.startTime); |
+ let slope = |
+ (this.endValue - this.startValue) / (this.endTime - this.startTime); |
return this.startValue + slope * (t - this.startTime); |
}; |
function expectedExponential(t) { |
- var ratio = this.endValue / this.startValue; |
- var exponent = (t - this.startTime) / (this.endTime - this.startTime); |
+ let ratio = this.endValue / this.startValue; |
+ let exponent = (t - this.startTime) / (this.endTime - this.startTime); |
return this.startValue * Math.pow(ratio, exponent); |
}; |
@@ -81,11 +83,13 @@ |
g.gain.exponentialRampToValueAtTime(this.endValue, this.endTime); |
} |
- // Basically want to test that if neither the start time nor end time is on a frame boundary |
- // that we sample the automation curve correctly. The start times and end times are mostly |
- // arbitrary, except that they cannot be on a frame boundary. |
- var testConfigs = [{ |
- desc: "linearRamp", |
+ // Basically want to test that if neither the start time nor end time is |
+ // on a frame boundary that we sample the automation curve correctly. The |
+ // start times and end times are mostly arbitrary, except that they cannot |
+ // be on a frame boundary. |
+ let testConfigs = [ |
+ { |
+ desc: 'linearRamp', |
startTime: .1 / sampleRate, |
endTime: 128.1 / sampleRate, |
startValue: 1, |
@@ -94,8 +98,9 @@ |
endValueThreshold: 1.526e-5, |
automationFunction: linearAutomation, |
expectedFunction: expectedLinear |
- }, { |
- desc: "linearRamp:short", |
+ }, |
+ { |
+ desc: 'linearRamp:short', |
startTime: .1 / sampleRate, |
endTime: 5.1 / sampleRate, |
startValue: 1, |
@@ -104,8 +109,9 @@ |
endValueThreshold: 9.537e-7, |
automationFunction: linearAutomation, |
expectedFunction: expectedLinear |
- }, { |
- desc: "linearRamp:long", |
+ }, |
+ { |
+ desc: 'linearRamp:long', |
startTime: .1 / sampleRate, |
endTime: 200.1 / sampleRate, |
startValue: 1, |
@@ -114,8 +120,9 @@ |
endValueThreshold: 4.674e-5, |
automationFunction: linearAutomation, |
expectedFunction: expectedLinear |
- }, { |
- desc: "exponentialRamp", |
+ }, |
+ { |
+ desc: 'exponentialRamp', |
startTime: .1 / sampleRate, |
endTime: 128.1 / sampleRate, |
startValue: 1, |
@@ -124,8 +131,9 @@ |
endValueThreshold: 1.484e-7, |
automationFunction: exponentialAutomation, |
expectedFunction: expectedExponential |
- }, { |
- desc: "exponentialRamp:short", |
+ }, |
+ { |
+ desc: 'exponentialRamp:short', |
startTime: .1 / sampleRate, |
endTime: 5.1 / sampleRate, |
startValue: 1, |
@@ -134,8 +142,9 @@ |
endValueThreshold: 3.821e-7, |
automationFunction: exponentialAutomation, |
expectedFunction: expectedExponential |
- }, { |
- desc: "exponentialRamp:long", |
+ }, |
+ { |
+ desc: 'exponentialRamp:long', |
startTime: .1 / sampleRate, |
endTime: 200.1 / sampleRate, |
startValue: 1, |
@@ -154,9 +163,9 @@ |
} |
// Create all of the tasks from the test configs |
- for (var k = 0; k < testConfigs.length; ++k) { |
- var config = testConfigs[k]; |
- var taskName = config.desc + ":task" + k; |
+ for (let k = 0; k < testConfigs.length; ++k) { |
+ let config = testConfigs[k]; |
+ let taskName = config.desc + ':task' + k; |
audit.define(taskName, createTaskFunction(config)); |
} |