Index: third_party/WebKit/LayoutTests/webaudio/audioparam-setTargetAtTime-sampling.html |
diff --git a/third_party/WebKit/LayoutTests/webaudio/audioparam-setTargetAtTime-sampling.html b/third_party/WebKit/LayoutTests/webaudio/audioparam-setTargetAtTime-sampling.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fbca12ad4d9c10264f290736171747ba6f159c5c |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/webaudio/audioparam-setTargetAtTime-sampling.html |
@@ -0,0 +1,105 @@ |
+<!doctype html> |
+<html> |
+ <head> |
+ <script src="resources/compatibility.js"></script> |
+ <script src="resources/audio-testing.js"></script> |
+ <script src="resources/audioparam-testing.js"></script> |
+ <script src="../resources/js-test.js"></script> |
+ <title>Test Sampling for SetTargetAtTime</title> |
+ </head> |
+ |
+ <body> |
+ <div id="description"></div> |
+ <div id="console"></div> |
hongchan
2015/10/01 20:20:52
Please remove two lines above. These divs are crea
Raymond Toy
2015/10/01 21:30:50
Done
|
+ |
+ <script> |
+ description("Test Sampling of SetTargetAtTime"); |
+ |
+ window.jsTestIsAsync = true; |
+ // Some slow sample rate, but otherwise arbitrary. |
+ var sampleRate = 12800; |
+ |
+ // Time constant for setTargetValue. Make it short, but is otherwise arbitrary. |
+ var timeConstant = 10 / sampleRate; |
+ |
+ // Defaut initial gain for test. Arbitrary, but we want it large so the changes look large, |
+ // even if the relative change isn't. |
+ var initialGain = 10000; |
+ |
+ var audit = Audit.createTaskRunner(); |
+ |
+ // Test sampling of setTargetAtTime that starts at |startFrame|. A gain node is used for |
+ // testing. |initializeGainFunction| initializes the gain value. |
+ function doTest(message, startFrame, threshold, initializeGainFunction) { |
+ var context = new OfflineAudioContext(1, 256, sampleRate); |
+ var source = context.createBufferSource(); |
+ var b = context.createBuffer(1, 1, sampleRate); |
+ b.getChannelData(0)[0] = 1; |
+ source.buffer = b; |
+ source.loop = true; |
+ |
+ var gain = context.createGain(); |
+ // Initialize the value of the gain node appropriately. |
+ initializeGainFunction(gain); |
+ gain.gain.setTargetAtTime(0, startFrame / sampleRate, timeConstant); |
+ |
+ source.connect(gain); |
+ gain.connect(context.destination); |
+ |
+ source.start(); |
+ |
+ return context.startRendering().then(function (resultBuffer) { |
+ // Verify that the sampling of the setTargetAtTime automation was done correctly. We just |
+ // look at the sample just past the start of the automation. |
+ var resultData = resultBuffer.getChannelData(0); |
+ // Compute the true result at the frame just past startFrame and verify that the actual |
+ // rendered result is within |threshold| of the expected value. |
+ var frame = Math.ceil(startFrame); |
+ var v = 10000 * Math.exp(-(frame / sampleRate - startFrame / sampleRate) / timeConstant); |
+ Should(message + ": Target value at frame " + frame, resultData[frame]).beCloseTo(v, threshold); |
+ }); |
+ } |
+ |
+ function initializeGainBySetter (g) { |
+ g.gain.value = initialGain; |
+ } |
+ |
+ function initializeGainBySetValue (g) { |
+ g.gain.setValueAtTime(initialGain, 0); |
+ } |
+ |
+ audit.defineTask("setValue;128.1", function (done) { |
+ doTest("Initialize by setValueAtTime", 128.1, 3.6029e-8, initializeGainBySetValue).then(done); |
+ }); |
+ |
+ audit.defineTask("setValue;0.1", function (done) { |
+ doTest("Initialize by setValueAtTime", 0.1, 3.6029e-8, initializeGainBySetValue).then(done); |
+ }); |
+ |
+ audit.defineTask("setValue;0.0", function (done) { |
+ doTest("Initialize by setValueAtTime", 0, 3.6029e-8, initializeGainBySetValue).then(done); |
+ }); |
+ |
+ audit.defineTask("setter;128.1", function (done) { |
+ doTest("Initialize by setter", 128.1, 3.6029e-8, initializeGainBySetter).then(done); |
+ }); |
+ |
+ audit.defineTask("setter;0.1", function (done) { |
+ doTest("Initialize by setter", 0.1, 3.6029e-8, initializeGainBySetter).then(done); |
+ }); |
+ |
+ audit.defineTask("setter;0.0", function (done) { |
+ doTest("Initialize by setter", 0, 0, initializeGainBySetter).then(done); |
+ }); |
+ |
+ |
+ audit.defineTask("finish", function (done) { |
+ finishJSTest(); |
+ done(); |
+ }); |
+ |
+ audit.runTasks(); |
+ successfullyParsed = true; |
+ </script> |
+ </body> |
+</html> |