Index: third_party/WebKit/LayoutTests/webaudio/audioparam-setTarget-timeConstant-0.html |
diff --git a/third_party/WebKit/LayoutTests/webaudio/audioparam-setTarget-timeConstant-0.html b/third_party/WebKit/LayoutTests/webaudio/audioparam-setTarget-timeConstant-0.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..997607eb3a1c714373776ab98bf4222a4624b3a9 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/webaudio/audioparam-setTarget-timeConstant-0.html |
@@ -0,0 +1,88 @@ |
+<!doctype html> |
+<html> |
+ <head> |
+ <title>Test setTargetAtTime with timeConstant=0</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 number of frames, so choose a low |
+ // sample rate, and short rendering length. |
+ var sampleRate = 8000; |
+ var renderFrames = 128; |
+ |
+ // Array specifying parameters for setTargetAtTime. |frame| is the frame |
+ // (not necessarily an integer) at which setTargetAtTime starts, and |
+ // |value| is the target value. Non-integral values for |frame| tests |
hongchan
2016/10/31 20:50:42
intergral - typo?
|
+ // that we started the setTargetAtTime at the right time. |
+ var targetValueInfo = [{ |
+ frame: 10.1, |
+ value: 0 |
+ }, { |
+ frame: 20.3, |
+ value: 0.5 |
+ }, { |
+ frame: 100.5, |
+ value: 1 |
+ }]; |
+ |
+ var audit = Audit.createTaskRunner(); |
+ |
+ audit.defineTask("timeconstant-0", function (taskDone) { |
+ var context = new OfflineAudioContext(1, renderFrames, sampleRate); |
+ |
+ // Simple constant source for testing. |
+ |
+ var src = new ConstantSourceNode(context); |
+ |
+ // We're going to automate the gain node to test setTargetAtTime. |
+ var gain = new GainNode(context, { |
+ gain: 1 |
hongchan
2016/10/31 20:50:42
Do we need this? It's by default 1.
|
+ }); |
+ |
+ src.connect(gain).connect(context.destination); |
+ |
+ for (var k = 0; k < targetValueInfo.length; ++k) { |
+ gain.gain.setTargetAtTime( |
+ targetValueInfo[k].value, |
+ targetValueInfo[k].frame / context.sampleRate, |
+ 0); |
+ } |
+ |
+ src.start(); |
+ |
+ context.startRendering().then(function (resultBuffer) { |
+ var result = resultBuffer.getChannelData(0); |
+ var success = true; |
+ |
+ // Because the time constant is 0, the automation should instantly |
+ // jump to the target value at the start time. Verify that the output |
+ // has the expected value. |
+ for (var k = 0; k < targetValueInfo.length; ++k) { |
+ var startFrame = Math.ceil(targetValueInfo[k].frame); |
+ var endFrame = k < targetValueInfo.length - 1 ? |
+ Math.ceil(targetValueInfo[k + 1].frame) : renderFrames; |
+ var value = targetValueInfo[k].value; |
+ |
+ success = Should( |
+ "Output for frame [" + startFrame + ", " + endFrame + |
+ ")", |
+ result.slice(startFrame, endFrame)) |
+ .beConstantValueOf(value) && success; |
+ } |
+ |
+ Should("setTargetAtTime with timeConstant=0", success) |
+ .summarize( |
+ "handled correctly", |
+ "handled incorrectly"); |
+ |
+ }).then(taskDone); |
+ }); |
+ |
+ audit.runTasks(); |
+ </script> |
+ </body> |
+</html> |