Bug 997870 - Optimize OscillatorNodeEngine::ComputeCustom a little. r=karlt
☠☠ backed out by 7978b241bf5e ☠ ☠
authorPaul Adenot <paul@paul.cx>
Wed, 10 Dec 2014 15:34:14 +0100
changeset 247837 187fa323cec69d9406514e11ebe1c1f3b9a18661
parent 247836 3ae2161027a62bad6a2bbf8c2017aa5ad5ba9806
child 247838 99d7aacbdd3b5cd96585ae4062f49c4d5e3f82be
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs997870
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 997870 - Optimize OscillatorNodeEngine::ComputeCustom a little. r=karlt
dom/media/webaudio/OscillatorNode.cpp
--- a/dom/media/webaudio/OscillatorNode.cpp
+++ b/dom/media/webaudio/OscillatorNode.cpp
@@ -146,25 +146,25 @@ public:
       mPhase -= mPhaseWrap;
     }
   }
 
   void UpdateParametersIfNeeded(StreamTime ticks, size_t count)
   {
     double frequency, detune;
 
+    // Shortcut if frequency-related AudioParam are not automated, and we
+    // already have computed the frequency information and related parameters.
+    if (!ParametersMayNeedUpdate()) {
+      return;
+    }
+
     bool simpleFrequency = mFrequency.HasSimpleValue();
     bool simpleDetune = mDetune.HasSimpleValue();
 
-    // Shortcut if frequency-related AudioParam are not automated, and we
-    // already have computed the frequency information and related parameters.
-    if (simpleFrequency && simpleDetune && !mRecomputeParameters) {
-      return;
-    }
-
     if (simpleFrequency) {
       frequency = mFrequency.GetValue();
     } else {
       frequency = mFrequency.GetValueAtTime(ticks, count);
     }
     if (simpleDetune) {
       detune = mDetune.GetValue();
     } else {
@@ -207,16 +207,23 @@ public:
       UpdateParametersIfNeeded(ticks, i);
 
       aOutput[i] = sin(mPhase);
 
       IncrementPhase();
     }
   }
 
+  bool ParametersMayNeedUpdate()
+  {
+    return mDetune.HasSimpleValue() ||
+           mFrequency.HasSimpleValue() ||
+           mRecomputeParameters;
+  }
+
   void ComputeCustom(float* aOutput,
                      StreamTime ticks,
                      uint32_t aStart,
                      uint32_t aEnd)
   {
     MOZ_ASSERT(mPeriodicWave, "No custom waveform data");
 
     uint32_t periodicWaveSize = mPeriodicWave->periodicWaveSize();
@@ -226,22 +233,32 @@ public:
                "periodicWaveSize must be power of 2");
     float* higherWaveData = nullptr;
     float* lowerWaveData = nullptr;
     float tableInterpolationFactor;
     // Phase increment at frequency of 1 Hz.
     // mPhase runs [0,periodicWaveSize) here instead of [0,2*M_PI).
     float basePhaseIncrement = mPeriodicWave->rateScale();
 
-    for (uint32_t i = aStart; i < aEnd; ++i) {
-      UpdateParametersIfNeeded(ticks, i);
+    bool parametersMayNeedUpdate = ParametersMayNeedUpdate();
+    if (!parametersMayNeedUpdate) {
       mPeriodicWave->waveDataForFundamentalFrequency(mFinalFrequency,
                                                      lowerWaveData,
                                                      higherWaveData,
                                                      tableInterpolationFactor);
+    }
+
+    for (uint32_t i = aStart; i < aEnd; ++i) {
+      if (parametersMayNeedUpdate) {
+        mPeriodicWave->waveDataForFundamentalFrequency(mFinalFrequency,
+                                                       lowerWaveData,
+                                                       higherWaveData,
+                                                       tableInterpolationFactor);
+        UpdateParametersIfNeeded(ticks, i);
+      }
       // Bilinear interpolation between adjacent samples in each table.
       float floorPhase = floorf(mPhase);
       uint32_t j1 = floorPhase;
       j1 &= indexMask;
       uint32_t j2 = j1 + 1;
       j2 &= indexMask;
 
       float sampleInterpolationFactor = mPhase - floorPhase;