Limit maximum delay of DelayNode.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jul 2012 19:06:11 +0000 (19:06 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jul 2012 19:06:11 +0000 (19:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=91675

Patch by Raymond Toy <rtoy@google.com> on 2012-07-19
Reviewed by Kenneth Russell.

Source/WebCore:

Clip the maximum delay of a DelayNode to a reasonable maximum.

Test: webaudio/delaynode-maxdelaylimit.html

* Modules/webaudio/DelayNode.cpp:
(WebCore): Add maximumAllowedDelayTime.
(WebCore::DelayNode::DelayNode): Clip max delay.

LayoutTests:

Test that a DelayNode limits the specified max delay to the
expected maximum allowed delay.

* webaudio/delaynode-maxdelaylimit-expected.txt: Added.
* webaudio/delaynode-maxdelaylimit.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@123131 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/webaudio/delaynode-maxdelaylimit-expected.txt [new file with mode: 0644]
LayoutTests/webaudio/delaynode-maxdelaylimit.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/webaudio/DelayNode.cpp

index 302b42c..1ec0b2d 100644 (file)
@@ -1,3 +1,16 @@
+2012-07-19  Raymond Toy  <rtoy@google.com>
+
+        Limit maximum delay of DelayNode.
+        https://bugs.webkit.org/show_bug.cgi?id=91675
+
+        Reviewed by Kenneth Russell.
+
+        Test that a DelayNode limits the specified max delay to the
+        expected maximum allowed delay.
+        
+        * webaudio/delaynode-maxdelaylimit-expected.txt: Added.
+        * webaudio/delaynode-maxdelaylimit.html: Added.
+
 2012-07-14  Robert Hogan  <robert@webkit.org>
 
         CSS 2.1 failure: text-indent-intrinsic-003 fails
diff --git a/LayoutTests/webaudio/delaynode-maxdelaylimit-expected.txt b/LayoutTests/webaudio/delaynode-maxdelaylimit-expected.txt
new file mode 100644 (file)
index 0000000..62e4abc
--- /dev/null
@@ -0,0 +1,12 @@
+Tests attribute and maximum allowed delay of DelayNode.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS delay.delayTime.maxValue === 300 is true
+PASS delay.delayTime.value === 0.0 is true
+PASS delay.delayTime.value === 0.5 is true
+PASS Test signal was correctly delayed by 0.5 sec.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/webaudio/delaynode-maxdelaylimit.html b/LayoutTests/webaudio/delaynode-maxdelaylimit.html
new file mode 100644 (file)
index 0000000..8fe06d5
--- /dev/null
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/audio-testing.js"></script>
+<script src="resources/delay-testing.js"></script>
+</head>
+
+<body>
+
+<div id="description"></div>
+<div id="console"></div>
+
+<script>
+description("Tests attribute and maximum allowed delay of DelayNode.");
+
+function runTest() {
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+    
+    window.jsTestIsAsync = true;
+        
+    // Create offline audio context.
+    var context = new webkitAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
+    var toneBuffer = createToneBuffer(context, 20, 20 * toneLengthSeconds, sampleRate); // 20Hz tone
+    
+    var bufferSource = context.createBufferSource();
+    bufferSource.buffer = toneBuffer;
+
+    // The delay node clips the maximum delay.  Create a node with a delay larger than the maximum
+    // allowed delay.
+    var delay = context.createDelayNode(1000);
+    
+    window.delay = delay;
+    shouldBeTrue("delay.delayTime.maxValue === 300");
+    shouldBeTrue("delay.delayTime.value === 0.0");
+
+    delay.delayTime.value = delayTimeSeconds;
+    shouldBeTrue("delay.delayTime.value === 0.5");
+
+    bufferSource.connect(delay);
+    delay.connect(context.destination);
+    bufferSource.noteOn(0);
+    
+    context.oncomplete = checkDelayedResult(toneBuffer);
+    context.startRendering();
+}
+
+runTest();
+
+</script>
+
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index 5461ebe..da585ea 100644 (file)
@@ -1,3 +1,18 @@
+2012-07-19  Raymond Toy  <rtoy@google.com>
+
+        Limit maximum delay of DelayNode.
+        https://bugs.webkit.org/show_bug.cgi?id=91675
+
+        Reviewed by Kenneth Russell.
+
+        Clip the maximum delay of a DelayNode to a reasonable maximum.
+        
+        Test: webaudio/delaynode-maxdelaylimit.html
+
+        * Modules/webaudio/DelayNode.cpp:
+        (WebCore): Add maximumAllowedDelayTime.
+        (WebCore::DelayNode::DelayNode): Clip max delay.
+
 2012-07-14  Robert Hogan  <robert@webkit.org>
 
         CSS 2.1 failure: text-indent-intrinsic-003 fails
index 51cc71e..680c29f 100644 (file)
 
 namespace WebCore {
 
+// FIXME: What should be the maximum allowed delay? Arbitrarily set to 300 sec (5 minutes).
+const double maximumAllowedDelayTime = 300;
+
 DelayNode::DelayNode(AudioContext* context, float sampleRate, double maxDelayTime)
     : AudioBasicProcessorNode(context, sampleRate)
 {
+    maxDelayTime = std::max(std::min(maxDelayTime, maximumAllowedDelayTime), 0.0);
     m_processor = adoptPtr(new DelayProcessor(context, sampleRate, 1, maxDelayTime));
     setNodeType(NodeTypeDelay);
 }