Bug 1074765 - Increment phase after sampling to begin PeriodicWave at phase = 0. r=rillian, a=abillings
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 30 Sep 2014 17:26:26 +1300
changeset 216906 aaa0553c45c6
parent 216905 67ba7d820ddf
child 216907 560bb9f18e5a
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 - Increment phase after sampling to begin PeriodicWave at phase = 0. r=rillian, a=abillings This makes phase consistent with the sine OscillatorType and with Blink's custom OscillatorType.
content/media/webaudio/OscillatorNode.cpp
--- a/content/media/webaudio/OscillatorNode.cpp
+++ b/content/media/webaudio/OscillatorNode.cpp
@@ -382,31 +382,32 @@ public:
       static_cast<float>(periodicWaveSize) / mSource->SampleRate();
 
     for (uint32_t i = aStart; i < aEnd; ++i) {
       UpdateParametersIfNeeded(ticks, i);
       mPeriodicWave->waveDataForFundamentalFrequency(mFinalFrequency,
                                                      lowerWaveData,
                                                      higherWaveData,
                                                      tableInterpolationFactor);
-      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;
       float lower = sampleInterpolationFactor * lowerWaveData[j1] +
                     (1 - sampleInterpolationFactor) * lowerWaveData[j2];
       float higher = sampleInterpolationFactor * higherWaveData[j1] +
                     (1 - sampleInterpolationFactor) * higherWaveData[j2];
       aOutput[i] = tableInterpolationFactor * lower +
                    (1 - tableInterpolationFactor) * higher;
+
+      mPhase += basePhaseIncrement * mFinalFrequency;
     }
   }
 
   void ComputeSilence(AudioChunk *aOutput)
   {
     aOutput->SetNull(WEBAUDIO_BLOCK_SIZE);
   }