Bug 997870 - Optimize OscillatorNodeEngine::ComputeCustom a little. r=karlt
authorPaul Adenot <paul@paul.cx>
Wed, 10 Dec 2014 15:34:14 +0100
changeset 222764 894be64b069b8223f41af5154621fa8f0762c04e
parent 222763 ffab1d2bd4ce20632fe12e66429ac0f43c2ebac5
child 222765 186c02fdb2218b2d15d583dca7c8f5e6fd7c2088
push id10716
push userkwierso@gmail.com
push dateFri, 09 Jan 2015 01:17:28 +0000
treeherderfx-team@0f98d51a4a49 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs997870
milestone37.0a1
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();
 
+    UpdateParametersIfNeeded(ticks, aStart);
+
+    bool parametersMayNeedUpdate = ParametersMayNeedUpdate();
+    mPeriodicWave->waveDataForFundamentalFrequency(mFinalFrequency,
+                                                   lowerWaveData,
+                                                   higherWaveData,
+                                                   tableInterpolationFactor);
+
     for (uint32_t i = aStart; i < aEnd; ++i) {
-      UpdateParametersIfNeeded(ticks, i);
-      mPeriodicWave->waveDataForFundamentalFrequency(mFinalFrequency,
-                                                     lowerWaveData,
-                                                     higherWaveData,
-                                                     tableInterpolationFactor);
+      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;