Bug 1308634 - Implicit call to SetValueAtTime in SetCurveAtTime, tests, RangeError changed to NotSupportedError r?padenot draft
authorThéo Rabut <theo.rabut@etu.univ-lyon1.fr>
Fri, 01 Dec 2017 23:17:46 +0100
changeset 706545 2dc7b9d20ef04290d4b0621719bad93c44d0c08c
parent 704807 cb9092a90f6ef501e6de8eb5fc6ce19e2717193f
child 742683 c191105e26720596f5f28db1a8378fbf800e4c73
push id91828
push userbmo:theo.rabut@etu.univ-lyon1.fr
push dateSat, 02 Dec 2017 08:58:11 +0000
reviewerspadenot
bugs1308634
milestone59.0a1
Bug 1308634 - Implicit call to SetValueAtTime in SetCurveAtTime, tests, RangeError changed to NotSupportedError r?padenot MozReview-Commit-ID: 1QpwqMXNgbL
dom/media/webaudio/AudioEventTimeline.h
dom/media/webaudio/AudioParam.h
dom/media/webaudio/test/mochitest.ini
dom/media/webaudio/test/test_audioParamSetCurveAtTimeTwice.html
dom/media/webaudio/test/test_bug1308436.html
--- a/dom/media/webaudio/AudioEventTimeline.h
+++ b/dom/media/webaudio/AudioEventTimeline.h
@@ -170,34 +170,35 @@ public:
 
     // Make sure that non-curve events don't fall within the duration of a
     // curve event.
     for (unsigned i = 0; i < mEvents.Length(); ++i) {
       if (mEvents[i].mType == AudioTimelineEvent::SetValueCurve &&
           !(aEvent.mType == AudioTimelineEvent::SetValueCurve &&
             TimeOf(aEvent) == TimeOf(mEvents[i])) &&
           TimeOf(mEvents[i]) <= TimeOf(aEvent) &&
-          TimeOf(mEvents[i]) + mEvents[i].mDuration >= TimeOf(aEvent)) {
-        aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
+          TimeOf(mEvents[i]) + mEvents[i].mDuration > TimeOf(aEvent)) {
+        aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
         return false;
       }
     }
 
     // Make sure that curve events don't fall in a range which includes other
     // events.
     if (aEvent.mType == AudioTimelineEvent::SetValueCurve) {
       for (unsigned i = 0; i < mEvents.Length(); ++i) {
         // In case we have two curve at the same time
         if (mEvents[i].mType == AudioTimelineEvent::SetValueCurve &&
             TimeOf(mEvents[i]) == TimeOf(aEvent)) {
-          continue;
+          aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
+          return false;
         }
         if (TimeOf(mEvents[i]) > TimeOf(aEvent) &&
             TimeOf(mEvents[i]) < TimeOf(aEvent) + aEvent.mDuration) {
-          aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
+          aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
           return false;
         }
       }
     }
 
     // Make sure that invalid values are not used for exponential curves
     if (aEvent.mType == AudioTimelineEvent::ExponentialRamp) {
       if (aEvent.mValue <= 0.f) {
--- a/dom/media/webaudio/AudioParam.h
+++ b/dom/media/webaudio/AudioParam.h
@@ -55,16 +55,24 @@ public:
       return this;
     }
     aValues.ComputeLengthAndData();
 
     aStartTime = std::max(aStartTime, GetParentObject()->CurrentTime());
     EventInsertionHelper(aRv, AudioTimelineEvent::SetValueCurve,
                          aStartTime, 0.0f, 0.0f, aDuration, aValues.Data(),
                          aValues.Length());
+
+    if (aDuration > 0) {
+      float sTimeOfLastValue = std::max(aStartTime + aDuration,
+                                        GetParentObject()->CurrentTime());
+      EventInsertionHelper(aRv, AudioTimelineEvent::SetValueAtTime,
+                           sTimeOfLastValue,
+                           aValues.Data()[aValues.Length() - 1]);
+    }
     return this;
   }
 
   void SetValue(float aValue)
   {
     AudioTimelineEvent event(AudioTimelineEvent::SetValue, 0.0f, aValue);
 
     ErrorResult rv;
--- a/dom/media/webaudio/test/mochitest.ini
+++ b/dom/media/webaudio/test/mochitest.ini
@@ -101,16 +101,17 @@ tags=capturestream
 [test_bug972678.html]
 [test_bug1113634.html]
 [test_bug1118372.html]
 [test_bug1027864.html]
 [test_bug1056032.html]
 skip-if = toolkit == 'android' # bug 1056706
 [test_bug1255618.html]
 [test_bug1267579.html]
+[test_bug1308436.html]
 [test_bug1355798.html]
 [test_channelMergerNode.html]
 [test_channelMergerNodeWithVolume.html]
 [test_channelSplitterNode.html]
 [test_channelSplitterNodeWithVolume.html]
 skip-if = (android_version == '18' && debug) # bug 1158417
 [test_convolverNode.html]
 [test_convolverNode_mono_mono.html]
--- a/dom/media/webaudio/test/test_audioParamSetCurveAtTimeTwice.html
+++ b/dom/media/webaudio/test/test_audioParamSetCurveAtTimeTwice.html
@@ -6,63 +6,33 @@
   <script type="text/javascript" src="webaudio.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 
-function linearInterpolate(t0, v0, t1, v1, t)
-{
-  return v0 + (v1 - v0) * ((t - t0) / (t1 - t0));
+var context = new AudioContext();
+var source = new ConstantSourceNode(context);
+
+var curveToSet = new Float32Array(100);
+for (var i = 0; i < 100; i++) {
+  curveToSet[i] = Math.sin(220 * 6 * Math.PI * i / context.sampleRate);
 }
 
-var T0 = 0;
-
-var gTest = {
-  length: 2048,
-  numberOfChannels: 1,
-  createGraph: function(context) {
-    var curve2 = new Float32Array(100);
-    for (var i = 0; i < 100; ++i) {
-      curve2[i] = Math.sin(220 * 6 * Math.PI * i / context.sampleRate);
-    }
-
-    var source = context.createConstantSource();
-
-    var gain = context.createGain();
-    gain.gain.setValueCurveAtTime(curve2, T0, this.duration/2);
-    //Set a different curve from the first one
-    gain.gain.setValueCurveAtTime(this.curve, T0, this.duration);
-
-    source.connect(gain);
+var gain = context.createGain();
+gain.gain.setValueCurveAtTime(curveToSet, 0, 10);
+var threw = false;
 
-    source.start(0);
-    return gain;
-  },
-  createExpectedBuffers: function(context) {
-    this.duration = 1024 / context.sampleRate;
-    this.curve = new Float32Array(100);
-    for (var i = 0; i < 100; ++i) {
-      this.curve[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
-    }
-    var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
-    for (var i = 0; i < 2048; ++i) {
-      step = 1024.0/99.0;
-      var current = Math.floor(i / step);
-      var next = current + 1;
-      if (next < this.curve.length) {
-        expectedBuffer.getChannelData(0)[i] = linearInterpolate(current*step, this.curve[current], next*step, this.curve[next], i);
-      } else {
-        expectedBuffer.getChannelData(0)[i] = this.curve[99];
-      }
-    }
-    return expectedBuffer;
-  },
-};
-
-runTest();
+try {
+  gain.gain.setValueCurveAtTime(curveToSet, 0, 10);
+  ok(threw, "Expected 'NOT_SUPPORTED_ERR'");
+} catch(ex) {
+  threw = true;
+  ok(ex instanceof DOMException, "Expect a DOM exception");
+  is(ex.code, 9, "Expect the correct exception code");
+}
 
 </script>
 </pre>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_bug1308436.html
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test AudioParam.setValueCurveAtTime.LinearRampToValue</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="webaudio.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+
+function linearInterpolate(t0, v0, t1, v1, t)
+{
+  return v0 + (v1 - v0) * ((t - t0) / (t1 - t0));
+}
+
+var LinearRampTo = 3;
+var T0 = 0;
+
+var gTest = {
+  length: 4096,
+  numberOfChannels: 1,
+  createGraph: function(context) {
+    var curveToSet = new Float32Array(100);
+    for (var i = 0; i < 100; i++) {
+      curveToSet[i] = Math.sin(220 * 6 * Math.PI * i / context.sampleRate) ;
+    }
+    var source = context.createConstantSource();
+    var gain = context.createGain();
+    gain.gain.setValueCurveAtTime(curveToSet, T0, this.duration);
+    gain.gain.linearRampToValueAtTime(LinearRampTo, this.duration * 2);
+    source.connect(gain);
+    source.start(0);
+    return gain;
+  },
+  createExpectedBuffers: function(context) {
+    this.duration = 1024 / context.sampleRate;
+    this.curve = new Float32Array(100);
+    for (var k = 0; k < 100; k++) {
+      this.curve[k] = Math.sin(220 * 6 * Math.PI * k / context.sampleRate);
+    }
+    var expectedBuffer = context.createBuffer(1, 4096, context.sampleRate);
+    var step = 1024.0/99.0;
+    for (var j = 0; j < 4; j++) {
+      for (var i = 0; i < 1024; i++) {
+        var currentValue = Math.floor(i / step);
+        var nextValue = currentValue + 1;
+        var currentTimeBuffer = currentValue * step + j * 1024;
+        var nextTimeBuffer = nextValue * step + j * 1024;
+        if (j == 0) {
+          expectedBuffer.getChannelData(0)[i + (j * 1024)] = linearInterpolate(currentTimeBuffer, this.curve[currentValue],
+                                                                      nextTimeBuffer,this.curve[nextValue], i + (j * 1024));
+        } else if (j == 1) {
+          expectedBuffer.getChannelData(0)[i + (j * 1024)] = linearInterpolate(1024, this.curve[99], 2047,
+                                                                      LinearRampTo, i + (j * 1024))
+        } else {
+          expectedBuffer.getChannelData(0)[i + (j * 1024)] = LinearRampTo;
+        }
+      }
+    }
+    return expectedBuffer;
+  },
+};
+
+runTest();
+
+</script>
+</pre>
+</body>
+</html>
\ No newline at end of file