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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/audioparam-clamp-time-to-current-time.html

Issue 2391893005: Implement clamping of AudioParam time. (Closed)
Patch Set: Address review comments Created 4 years, 2 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/webaudio/audioparam-clamp-time-to-current-time.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/audioparam-clamp-time-to-current-time.html b/third_party/WebKit/LayoutTests/webaudio/audioparam-clamp-time-to-current-time.html
new file mode 100644
index 0000000000000000000000000000000000000000..4cf38d907ab39e34a54f14c21996c5299c2138aa
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/audioparam-clamp-time-to-current-time.html
@@ -0,0 +1,237 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Test Clamping of AudioParam Time</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 = 24000;
+ var renderFrames = 1024;
+
+ var audit = Audit.createTaskRunner();
+
+ audit.defineTask("setValue", function (taskDone) {
+ var suspendFrame = 128;
+ createGraph({
+ suspendFrame: suspendFrame,
+ method: "setValueAtTime",
+ initialGain: 0,
+ arg0: 1,
+ })
+ .then(function (resultBuffer) {
+ // Just verify that the cosine wave actually started at
+ // suspendFrame.
+ var result = resultBuffer.getChannelData(0);
+ var success = true;
+
+ success = Should("Output[0-" + (suspendFrame - 1) + "]",
+ result.slice(0, suspendFrame))
+ .beConstantValueOf(0) && success;
+ success = Should("Output[" + suspendFrame + "-" + (
+ renderFrames - 1) + "]",
+ result.slice(suspendFrame))
+ .beConstantValueOf(1) && success;
+
+ Should("*** setValueAtTime in the past", success)
+ .summarize(
+ "correctly clamped to current time",
+ "was not correctly clamped to current time");
+ })
+ .then(taskDone);
+ });
+
+ audit.defineTask("linear", function (taskDone) {
+ var suspendFrame = 128;
+ createGraph({
+ suspendFrame: suspendFrame,
+ method: "linearRampToValueAtTime",
+ initialGain: 1,
+ arg0: 0.5
+ })
+ .then(function (resultBuffer) {
+ // Just verify that the cosine wave actually started at
+ // suspendFrame.
+ var result = resultBuffer.getChannelData(0);
+ var success = true;
+
+ success = Should("Output[0-" + (suspendFrame - 1) + "]",
+ result.slice(0, suspendFrame))
+ .beConstantValueOf(1) && success;
+ success = Should("Output[" + suspendFrame + "-" + (
+ renderFrames - 1) + "]",
+ result.slice(suspendFrame))
+ .beConstantValueOf(0.5) && success;
+
+ Should("*** linearRampToValueAtTime in the past", success)
+ .summarize(
+ "correctly clamped to current time",
+ "was not correctly clamped to current time");
+ })
+ .then(taskDone);
+ });
+
+ audit.defineTask("exponential", function (taskDone) {
+ var suspendFrame = 128;
+ createGraph({
+ suspendFrame: suspendFrame,
+ method: "exponentialRampToValueAtTime",
+ initialGain: 1,
+ arg0: 0.5
+ })
+ .then(function (resultBuffer) {
+ // Just verify that the cosine wave actually started at
+ // suspendFrame.
+ var result = resultBuffer.getChannelData(0);
+ var success = true;
+
+ success = Should("Output[0-" + (suspendFrame - 1) + "]",
+ result.slice(0, suspendFrame))
+ .beConstantValueOf(1) && success;
+ success = Should("Output[" + suspendFrame + "-" + (
+ renderFrames - 1) + "]",
+ result.slice(suspendFrame))
+ .beConstantValueOf(0.5) && success;
+
+ Should("*** exponentialRampToValueAtTime in the past",
+ success)
+ .summarize(
+ "correctly clamped to current time",
+ "was not correctly clamped to current time");
+ })
+ .then(taskDone);
+ });
+
+ audit.defineTask("setTarget", function (taskDone) {
+ var suspendFrame = 128;
+ createGraph({
+ suspendFrame: suspendFrame,
+ method: "setTargetAtTime",
+ initialGain: 1,
+ arg0: 0.5,
+ moreArgs: 0.1
+ })
+ .then(function (resultBuffer) {
+ // Just verify that the cosine wave actually started at
+ // suspendFrame.
+ var result = resultBuffer.getChannelData(0);
+ var success = true;
+
+ success = Should("Output[0-" + (suspendFrame - 1) + "]",
+ result.slice(0, suspendFrame))
+ .beConstantValueOf(1) && success;
+ // For the samples past the suspend time, we only care that first
+ // value is 1 and that the rest are not zero.
+ success = Should("Output[" + suspendFrame + "]",
+ result[suspendFrame]).beEqualTo(1) && success;
+
+ var positive = result.slice(suspendFrame + 1).every(x => x >
+ 0);
+ success = Should("Output[" + (suspendFrame + 1) + "-" +
+ (renderFrames - 1) + "] contains only positive values",
+ positive)
+ .beEqualTo(true) && success;
+
+ Should("*** setTargetAtTime in the past", success)
+ .summarize(
+ "correctly clamped to current time",
+ "was not correctly clamped to current time");
+ })
+ .then(taskDone);
+ });
+
+ audit.defineTask("setValueCurve", function (taskDone) {
+ var suspendFrame = 128;
+ createGraph({
+ suspendFrame: suspendFrame,
+ method: "setValueCurveAtTime",
+ initialGain: 1,
+ arg0: Float32Array.from([2, 3]),
+ moreArgs: 0.1
+ })
+ .then(function (resultBuffer) {
+ // Just verify that the cosine wave actually started at
+ // suspendFrame.
+ var result = resultBuffer.getChannelData(0);
+ var success = true;
+
+ success = Should("Output[0-" + (suspendFrame - 1) + "]",
+ result.slice(0, suspendFrame))
+ .beConstantValueOf(1) && success;
+
+ // The selected curve contains values greater than or equal to 2.
+ // Just verify that all values are greater than or equal to 2.
+ var biggerThan2 = result.slice(suspendFrame).every(x => x >=
+ 2);
+ success = Should("Output[" + suspendFrame + "-" + (
+ renderFrames - 1) + "]",
+ biggerThan2)
+ .beEqualTo(true) && success;
+
+ Should("*** setValueCurveAtTime in the past", success)
+ .summarize(
+ "correctly clamped to current time",
+ "was not correctly clamped to current time");
+ })
+ .then(taskDone);
+ });
+
+
+ // Create the test graph consisting of a constant source followed by a
+ // gain node. The gain node automations will be tested. |options|
+ // specifies the parameters for the test including
+ //
+ // suspendFrame: time at which we schedule the automation call
+ // method: the name of automation method to be tested
+ // initialGain: the initial gain at time 0 for the gain node
+ // arg0: the first argument to be supplied to the automation method.
+ // moreArgs: An array of any additional arguments for the automation method.
+ function createGraph(options) {
+ var context = new OfflineAudioContext(1, renderFrames, sampleRate);
+
+ var cosineWave = new PeriodicWave(context, {
+ real: [0, 1]
+ });
+
+ var src = new OscillatorNode(context, {
+ periodicWave: cosineWave,
+ frequency: 0
+ });
+
+ // The gain node whose automations we're testing.
+ var gain = new GainNode(context, {
+ gain: 0
+ });
+
+ src.connect(gain).connect(context.destination);
+
+ gain.gain.setValueAtTime(options.initialGain, 0);
+
+ // Suspend rendering so that we can call the automation method at the
+ // right time. |startTime| is the time for the automation method. It
+ // must be some time before the suspend time.
+ var suspendFrame = options.suspendFrame;
+ var startTime = (suspendFrame / 2) / context.sampleRate;
+ context.suspend(suspendFrame / context.sampleRate)
+ .then(function () {
+ // Call the appropriate automation method with the desired
+ // automation value, time, and any other arguments needed.
+ gain.gain[options.method](...[options.arg0, startTime, options.moreArgs]);
+ })
+ .then(context.resume.bind(context));
+
+ // Start the source and begin rendering, returning the promise from
+ // rendering.
+ src.start();
+
+ return context.startRendering();
+ }
+
+ audit.runTasks();
+ </script>
+ </body>
+</html>
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698