Title: [108592] trunk
Revision
108592
Author
[email protected]
Date
2012-02-22 18:19:25 -0800 (Wed, 22 Feb 2012)

Log Message

exponentialRampToValue doesn't use starting value
https://bugs.webkit.org/show_bug.cgi?id=78035

Patch by Raymond Toy <[email protected]> on 2012-02-22
Reviewed by Chris Rogers.

Source/WebCore:

Test: webaudio/audioparam-exponentialRampToValueAtTime.html

* webaudio/AudioParamTimeline.cpp:
(WebCore::AudioParamTimeline::valuesForTimeRangeImpl): Set
starting value for exponential ramp.

LayoutTests:

* webaudio/audioparam-exponentialRampToValueAtTime-expected.txt: Added.
* webaudio/audioparam-exponentialRampToValueAtTime.html: Added.
* webaudio/resources/audioparam-testing.js: Added.
(createConstantBuffer):
(createExponentialRampArray):
(comparePartialSignals):
(verifyDiscontinuities):
(compareSignals):
(doAutomation):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (108591 => 108592)


--- trunk/LayoutTests/ChangeLog	2012-02-23 02:16:01 UTC (rev 108591)
+++ trunk/LayoutTests/ChangeLog	2012-02-23 02:19:25 UTC (rev 108592)
@@ -1,3 +1,20 @@
+2012-02-22  Raymond Toy  <[email protected]>
+
+        exponentialRampToValue doesn't use starting value
+        https://bugs.webkit.org/show_bug.cgi?id=78035
+
+        Reviewed by Chris Rogers.
+
+        * webaudio/audioparam-exponentialRampToValueAtTime-expected.txt: Added.
+        * webaudio/audioparam-exponentialRampToValueAtTime.html: Added.
+        * webaudio/resources/audioparam-testing.js: Added.
+        (createConstantBuffer):
+        (createExponentialRampArray):
+        (comparePartialSignals):
+        (verifyDiscontinuities):
+        (compareSignals):
+        (doAutomation):
+
 2012-02-22  Adrienne Walker  <[email protected]>
 
         [chromium] Unreviewed gardening. Rebaseline more svg tests.

Added: trunk/LayoutTests/webaudio/audioparam-exponentialRampToValueAtTime-expected.txt (0 => 108592)


--- trunk/LayoutTests/webaudio/audioparam-exponentialRampToValueAtTime-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webaudio/audioparam-exponentialRampToValueAtTime-expected.txt	2012-02-23 02:19:25 UTC (rev 108592)
@@ -0,0 +1,11 @@
+Test AudioParam exponentialRampToValueAtTime() functionality.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS All 100 tests started and ended at the correct time.
+PASS All 100 tests passed within an acceptable tolerance.
+PASS AudioParam exponentialRampToValueAtTime() test passed.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/webaudio/audioparam-exponentialRampToValueAtTime.html (0 => 108592)


--- trunk/LayoutTests/webaudio/audioparam-exponentialRampToValueAtTime.html	                        (rev 0)
+++ trunk/LayoutTests/webaudio/audioparam-exponentialRampToValueAtTime.html	2012-02-23 02:19:25 UTC (rev 108592)
@@ -0,0 +1,144 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+  <head>
+    <script src=""
+    <script src=""
+    <script src=""
+  </head>
+
+  <body>
+    <div id="description"></div>
+    <div id="console"></div>
+
+    <script>
+      description("Test AudioParam exponentialRampToValueAtTime() functionality.");
+
+      // Play a long DC signal out through an AudioGainNode, and call setValueAtTime() and
+      // exponentialRampToValueAtTime() at regular intervals to set the starting and ending values
+      // for an exponential ramp.  Each time interval has a ramp with a different starting and
+      // ending value so that there is a discontinuity at each time interval boundary.  The
+      // discontinuity is for testing timing.  Also, we alternate between an increasing and
+      // decreasing ramp for each interval.
+
+      // Max allowed difference between the rendered data and the expected result.
+      var maxAllowedError = 6.75e-4;
+
+      // Information about the starting and ending times and starting and ending values for each
+      // time interval.
+      var timeValueInfo;
+
+      // The AudioGainNode starts with this value instead of the default value.
+      var initialValue = 100;
+
+      // The difference between starting values between each time interval.
+      var startingValueDelta = initialValue / numberOfTests;
+      
+      // Each exponential ramp will increase or decrease by this much from the start to the end of
+      // the time interval.  We choose half of startingValueDelta so that the ending value of the
+      // ramp will be distinct from the starting value of the ramp for next time interval.  This
+      // allows us to detect where the ramp begins and ends.
+      var startEndValueChange = startingValueDelta / 2;
+
+      // Threshold to use for detecting discontinuities that should appear at each time interval.
+      var discontinuityThreshold = startEndValueChange / 2;
+
+      var gainNode;
+      
+      var constantBuffer;
+      var bufferSource;
+
+      // Return the difference between the starting value and the ending value for time interval
+      // |timeIntervalIndex|.  We alternate between an end value that is above or below the starting
+      // value.
+      function endValueDelta(timeIntervalIndex)
+      {
+          if (timeIntervalIndex & 1) {
+              return -startEndValueChange;
+          } else {
+              return startEndValueChange;
+          }
+      }
+
+      // Set the gain node value to the specified value at the specified time.
+      function setValue(value, time)
+      {
+          gainNode.gain.setValueAtTime(value, time);
+      }
+
+      // Generate an exponential ramp ending at time |endTime| with an ending value of |value|.
+      function generateRamp(value, startTime, endTime)
+      {
+          // |startTime| is ignored because the exponential ramp
+          // uses the value from the setValueAtTime() call above.
+          gainNode.gain.exponentialRampToValueAtTime(value, endTime)
+      }
+      
+      // Return the difference between the starting value at |timeIntervalIndex| and the starting
+      // value at the next time interval.  Since we started at a large initial value, we decrease
+      // the value at each time interval.
+      function valueUpdate(timeIntervalIndex)
+      {
+          return -startingValueDelta;
+      }
+
+      function checkResult(event)
+      {
+          var buffer = event.renderedBuffer;
+          renderedData = buffer.getChannelData(0);
+
+          compareSignals("exponentialRampToValueAtTime()", maxAllowedError, renderedData, createExponentialRampArray, timeValueInfo, discontinuityThreshold);
+
+          finishJSTest();
+      }
+      
+      function runTest()
+      {
+          if (window.layoutTestController) {
+              layoutTestController.dumpAsText();
+              layoutTestController.waitUntilDone();
+          }
+
+          window.jsTestIsAsync = true;
+
+          // Create offline audio context.
+          context = new webkitAudioContext(2, renderLength, sampleRate);
+          constantBuffer = createConstantBuffer(context, 1, renderLength);
+
+          // We use an AudioGainNode here simply as a convenient way to test the AudioParam
+          // automation, since it's easy to pass a constant value through the node, automate the
+          // .gain attribute and observe the resulting values.
+
+          gainNode = context.createGainNode();
+
+          bufferSource = context.createBufferSource();
+          bufferSource.buffer = constantBuffer;
+          bufferSource.connect(gainNode);
+          gainNode.connect(context.destination);
+
+          // At each time interval, we adjust the value by startingValueDelta.  However, the
+          // exponential ramp end value is the value +/- startEndValueChange.  (We alternately
+          // specify the end value to be greater or smaller than the starting value, to test the
+          // ramp going up and down.)
+          //
+          // By doing it this way, we get a discontinuity at each time interval which we can use to
+          // test if the ramp started and ended at the correct time.
+          timeValueInfo = doAutomation(initialValue,
+                                       endValueDelta,
+                                       setValue,
+                                       generateRamp,
+                                       valueUpdate);
+
+          bufferSource.noteOn(0);
+      
+          context._oncomplete_ = checkResult;
+          context.startRendering();
+      }
+
+      runTest();
+      successfullyParsed = true;
+      
+    </script>
+
+    <script src=""
+  </body>
+</html>

Added: trunk/LayoutTests/webaudio/resources/audioparam-testing.js (0 => 108592)


--- trunk/LayoutTests/webaudio/resources/audioparam-testing.js	                        (rev 0)
+++ trunk/LayoutTests/webaudio/resources/audioparam-testing.js	2012-02-23 02:19:25 UTC (rev 108592)
@@ -0,0 +1,194 @@
+var sampleRate = 44100;
+
+// Number of tests to run.
+var numberOfTests = 100;
+
+// Time interval between value changes.  It is best if 1 / numberOfTests is not close to
+// timeInterval.
+var timeInterval = .03;
+
+// Make sure we render long enough to capture all of our test data.
+var renderTime = (numberOfTests + 1) * timeInterval;
+var renderLength = timeToSampleFrame(renderTime, sampleRate);
+
+var context;
+
+// Create a buffer containing the same constant value.
+function createConstantBuffer(context, constant, length) {
+    var buffer = context.createBuffer(1, length, context.sampleRate);
+    var n = buffer.length;
+    var data = ""
+
+    for (var k = 0; k < n; ++k) {
+        data[k] = constant;
+    }
+
+    return buffer;
+}
+
+// Create an exponential ramp starting at |startValue| and ending at |endValue|.  The ramp starts at
+// time |startTime| and ends at |endTime|.  (The start and end times are only used to compute how
+// many samples to return.)
+function createExponentialRampArray(startTime, endTime, startValue, endValue, sampleRate)
+{
+    var startFrame = timeToSampleFrame(startTime, sampleRate);
+    var endFrame = timeToSampleFrame(endTime, sampleRate);
+    var length = endFrame - startFrame;
+    var buffer = new Array(length);
+
+    var multiplier = Math.pow(endValue / startValue, 1 / length);
+    
+    for (var k = 0; k < length; ++k) {
+        buffer[k] = startValue * Math.pow(multiplier, k);
+    }
+
+    return buffer;
+}
+
+// Compare a section of the rendered data against our expected signal.
+function comparePartialSignals(rendered, expectedFunction, startTime, endTime, valueInfo, sampleRate)
+{
+    var startSample = timeToSampleFrame(startTime, sampleRate);
+    var expected = expectedFunction(startTime, endTime, valueInfo.startValue, valueInfo.endValue, sampleRate);
+
+    var n = expected.length;
+    var maxError = -1;
+    var maxErrorIndex = -1;
+    
+    for (var k = 0; k < n; ++k) {
+        var error = Math.abs(rendered[startSample + k] - expected[k]);
+        if (error > maxError) {
+            maxError = error;
+            maxErrorIndex = k;
+        }
+    }
+
+    return {maxError : maxError, index : maxErrorIndex};
+}
+
+// Find the discontinuities in the data and compare the locations of the discontinuities with the
+// times that define the time intervals. There is a discontinuity if the difference between
+// successive samples exceeds the threshold.
+function verifyDiscontinuities(values, times, threshold)
+{
+    var n = values.length;
+    var success = true;
+    var badLocations = 0;
+    var breaks = [];
+
+    // Find discontinuities.
+    for (var k = 1; k < n; ++k) {
+        if (Math.abs(values[k] - values[k - 1]) > threshold) {
+            breaks.push(k);
+        }
+    }
+
+    // Compare the location of each discontinuity with the end time of each interval. (There is no
+    // discontinuity at the start of the signal.)
+    for (var k = 0; k < breaks.length; ++k) {
+        var expectedSampleFrame = timeToSampleFrame(times[k + 1], sampleRate);
+        if (breaks[k] != expectedSampleFrame) {
+            success = false;
+            ++badLocations;
+            testFailed("Expected discontinuity at " + expectedSampleFrame + " but got " + breaks[k]);
+        }
+    }
+
+    if (badLocations) {
+        testFailed(badLocations + " discontinuities at incorrect locations");
+    } else {
+        testPassed("All " + (breaks.length + 1) + " tests started and ended at the correct time.");
+    }
+    
+    return success;
+}
+
+// Compare the rendered data with the expected data.
+//
+// testName - string describing the test
+//
+// maxError - maximum allowed difference between the rendered data and the expected data
+//
+// rendererdData - array containing the rendered (actual) data
+//
+// expectedFunction - function to compute the expected data
+//
+// timeValueInfo - array containing information about the start and end times and the start and end
+// values of each interval.
+//
+// breakThreshold - threshold to use for determining discontinuities.
+function compareSignals(testName, maxError, renderedData, expectedFunction, timeValueInfo, breakThreshold)
+{
+    var success = true;
+    var failedTestCount = 0;
+    var times = timeValueInfo.times;
+    var values = timeValueInfo.values;
+    var n = values.length;
+
+    success = verifyDiscontinuities(renderedData, times, breakThreshold);
+
+    for (var k = 0; k < n; ++k) {
+        var result = comparePartialSignals(renderedData, expectedFunction, times[k], times[k + 1], values[k], sampleRate);
+
+        if (result.maxError > maxError) {
+            testFailed("Incorrect gain for test " + k + ". Max error = " + result.maxError + " at offset " + (result.index + timeToSampleFrame(times[k], sampleRate)));
+            ++failedTestCount;
+        }
+    }
+
+    if (failedTestCount) {
+        testFailed(failedTestCount + " tests failed out of " + n);
+        success = false;
+    } else {
+        testPassed("All " + n + " tests passed within an acceptable tolerance.");
+    }
+      
+    if (success) {
+        testPassed("AudioParam " + testName + " test passed.");
+    } else {
+        testFailed("AudioParam " + testName + " test failed.");
+    }
+}
+
+// Run all the automation tests.
+//
+// initialValue - The initial value of the first time interval.
+//
+// endValueDeltaFunction - How much the end value differs from the value at the start of the
+// interval.
+//
+// setValueFunction - function that sets the specified value at the start of a time interval.
+//
+// automationFunction - function that sets the end value for the time interval.  It specifies how
+// the value approaches the end value.
+//
+// valueUpdateFunction - The starting value at time interval k is adjusted by valueUpdateFunction(k) to give the new starting value at time interval k + 1.
+//
+// An object is returned containing an array of start times for each time interval, and an array
+// giving the start and end values for the interval.
+function doAutomation(initialValue, endValueDeltaFunction, setValueFunction, automationFunction, valueUpdateFunction)
+{
+    var timeInfo = [0];
+    var valueInfo = [];
+    var value = initialValue;
+    
+    for (var k = 0; k < numberOfTests; ++k) {
+        var startTime = k * timeInterval;
+        var endTime = (k + 1) * timeInterval;
+        var endValue = value + endValueDeltaFunction(k);
+
+        // Set the value at the start of the time interval.
+        setValueFunction(value, startTime);
+
+        // Specify the target value, and how we should approach the target value.
+        automationFunction(endValue, startTime, endTime);
+
+        // Keep track of the start times, and the start and end values for each time interval.
+        timeInfo.push(endTime);
+        valueInfo.push({startValue: value, endValue : endValue});
+
+        value += valueUpdateFunction(k);
+    }
+
+    return {times : timeInfo, values : valueInfo};
+}

Modified: trunk/Source/WebCore/ChangeLog (108591 => 108592)


--- trunk/Source/WebCore/ChangeLog	2012-02-23 02:16:01 UTC (rev 108591)
+++ trunk/Source/WebCore/ChangeLog	2012-02-23 02:19:25 UTC (rev 108592)
@@ -1,3 +1,16 @@
+2012-02-22  Raymond Toy  <[email protected]>
+
+        exponentialRampToValue doesn't use starting value
+        https://bugs.webkit.org/show_bug.cgi?id=78035
+
+        Reviewed by Chris Rogers.
+
+        Test: webaudio/audioparam-exponentialRampToValueAtTime.html
+
+        * webaudio/AudioParamTimeline.cpp:
+        (WebCore::AudioParamTimeline::valuesForTimeRangeImpl): Set
+        starting value for exponential ramp.
+
 2012-02-22  Andreas Kling  <[email protected]>
 
         Make parsing color presentation attributes do less pointless work.

Modified: trunk/Source/WebCore/webaudio/AudioParamTimeline.cpp (108591 => 108592)


--- trunk/Source/WebCore/webaudio/AudioParamTimeline.cpp	2012-02-23 02:16:01 UTC (rev 108591)
+++ trunk/Source/WebCore/webaudio/AudioParamTimeline.cpp	2012-02-23 02:19:25 UTC (rev 108592)
@@ -242,6 +242,13 @@
                 // The value goes exponentially from value1 to value2 in a duration of deltaTime seconds (corresponding to numSampleFrames).
                 // Compute the per-sample multiplier.
                 float multiplier = powf(value2 / value1, 1 / numSampleFrames);
+
+                // Set the starting value of the exponential ramp. This is the same as multiplier ^
+                // AudioUtilities::timeToSampleFrame(currentTime - time1, sampleRate), but is more
+                // accurate, especially if multiplier is close to 1.
+                value = value1 * powf(value2 / value1,
+                                      AudioUtilities::timeToSampleFrame(currentTime - time1, sampleRate) / numSampleFrames);
+
                 for (; writeIndex < fillToFrame; ++writeIndex) {
                     values[writeIndex] = value;
                     value *= multiplier;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to