Bug 1074765 - Move const periodicWaveSize multiplier out of loop. r=rillian, a=abillings
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 30 Sep 2014 17:13:27 +1300
changeset 216905 67ba7d820ddf
parent 216904 dfbd36a37290
child 216906 aaa0553c45c6
push id3962
push userryanvm@gmail.com
push date2014-10-02 13:26 +0000
treeherdermozilla-beta@abc995cad178 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, abillings
bugs1074765
milestone33.0
Bug 1074765 - Move const periodicWaveSize multiplier out of loop. r=rillian, a=abillings
content/media/webaudio/OscillatorNode.cpp
--- a/content/media/webaudio/OscillatorNode.cpp
+++ b/content/media/webaudio/OscillatorNode.cpp
@@ -371,26 +371,28 @@ public:
                      uint32_t aEnd)
   {
     MOZ_ASSERT(mPeriodicWave, "No custom waveform data");
 
     uint32_t periodicWaveSize = mPeriodicWave->periodicWaveSize();
     float* higherWaveData = nullptr;
     float* lowerWaveData = nullptr;
     float tableInterpolationFactor;
-    float rate = 1.0 / mSource->SampleRate();
- 
+    // Phase increment at frequency of 1 Hz.
+    // mPhase runs [0,periodicWaveSize) here instead of [0,2*M_PI).
+    float basePhaseIncrement =
+      static_cast<float>(periodicWaveSize) / mSource->SampleRate();
+
     for (uint32_t i = aStart; i < aEnd; ++i) {
       UpdateParametersIfNeeded(ticks, i);
       mPeriodicWave->waveDataForFundamentalFrequency(mFinalFrequency,
                                                      lowerWaveData,
                                                      higherWaveData,
                                                      tableInterpolationFactor);
-      // mPhase runs 0..periodicWaveSize here instead of 0..2*M_PI.
-      mPhase += periodicWaveSize * mFinalFrequency * rate;
+      mPhase += basePhaseIncrement * mFinalFrequency;
       mPhase = fmod(mPhase, periodicWaveSize);
       // Bilinear interpolation between adjacent samples in each table.
       uint32_t j1 = floor(mPhase);
       uint32_t j2 = j1 + 1;
       if (j2 >= periodicWaveSize) {
         j2 -= periodicWaveSize;
       }
       float sampleInterpolationFactor = mPhase - j1;