diff --git a/content/media/webaudio/OscillatorNode.cpp b/content/media/webaudio/OscillatorNode.cpp index adf3292c8b1b..9444c66b9426 100644 --- a/content/media/webaudio/OscillatorNode.cpp +++ b/content/media/webaudio/OscillatorNode.cpp @@ -376,16 +376,18 @@ public: 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(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);