Bug 1618225 - Use llround function instead of + 0.5 r=karlt
authorCorentin Arnould <koalab1999@gmail.com>
Tue, 27 Oct 2020 22:10:56 +0000
changeset 554883 0c7b5d5a230791e949919eeed02d5c8b12570206
parent 554882 97ecf4557cf41812748b55e46f94c30b7a20d993
child 554884 a8f931d434cceba6a1988d97170026526922836c
push id37899
push usermalexandru@mozilla.com
push dateWed, 28 Oct 2020 21:47:27 +0000
treeherdermozilla-central@9b78e4ae32ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1618225
milestone84.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 1618225 - Use llround function instead of + 0.5 r=karlt Depends on D84481 Differential Revision: https://phabricator.services.mozilla.com/D85583
dom/media/webaudio/AudioBufferSourceNode.cpp
--- a/dom/media/webaudio/AudioBufferSourceNode.cpp
+++ b/dom/media/webaudio/AudioBufferSourceNode.cpp
@@ -94,17 +94,17 @@ class AudioBufferSourceNodeEngine final 
     }
   }
   void SetDoubleParameter(uint32_t aIndex, double aParam) override {
     switch (aIndex) {
       case AudioBufferSourceNode::START:
         MOZ_ASSERT(!mStart, "Another START?");
         mStart = aParam * mDestination->mSampleRate;
         // Round to nearest
-        mBeginProcessing = mStart + 0.5;
+        mBeginProcessing = llround(mStart);
         break;
       case AudioBufferSourceNode::DURATION:
         MOZ_ASSERT(aParam >= 0);
         mRemainingFrames = llround(aParam * mBufferSampleRate);
         break;
       default:
         NS_ERROR("Bad AudioBufferSourceNodeEngine double parameter.");
     };
@@ -147,17 +147,17 @@ class AudioBufferSourceNodeEngine final 
          // If the resampler has begun, then it will have moved
          // mBufferPosition to after the samples it has read, but it hasn't
          // output its buffered samples.  Keep using the resampler, even if
          // the rates now match, so that this latent segment is output.
          (aOutRate == mBufferSampleRate && !BegunResampling()))) {
       speex_resampler_destroy(mResampler);
       mResampler = nullptr;
       mRemainingResamplerTail = 0;
-      mBeginProcessing = mStart + 0.5;
+      mBeginProcessing = llround(mStart);
     }
 
     if (aChannels == 0 || (aOutRate == mBufferSampleRate && !mResampler)) {
       mResamplerOutRate = aOutRate;
       return;
     }
 
     if (!mResampler) {
@@ -181,17 +181,17 @@ class AudioBufferSourceNodeEngine final 
       // Low pass filter effects from the resampler mean that samples before
       // the start time are influenced by resampling the buffer.  The input
       // latency indicates half the filter width.
       int64_t inputLatency = speex_resampler_get_input_latency(mResampler);
       uint32_t ratioNum, ratioDen;
       speex_resampler_get_ratio(mResampler, &ratioNum, &ratioDen);
       // The output subsample resolution supported in aligning the resampler
       // is ratioNum.  First round the start time to the nearest subsample.
-      int64_t subsample = mStart * ratioNum + 0.5;
+      int64_t subsample = llround(mStart * ratioNum);
       // Now include the leading effects of the filter, and round *up* to the
       // next whole tick, because there is no effect on samples outside the
       // filter width.
       mBeginProcessing =
           (subsample - inputLatency * ratioDen + ratioNum - 1) / ratioNum;
     }
   }
 
@@ -257,17 +257,17 @@ class AudioBufferSourceNodeEngine final 
         // buffer, but correct for input latency.  If starting before mStart,
         // then align the resampler so that the time corresponding to the
         // first input sample is mStart.
         int64_t skipFracNum = static_cast<int64_t>(inputLatency) * ratioDen;
         double leadTicks = mStart - *aCurrentPosition;
         if (leadTicks > 0.0) {
           // Round to nearest output subsample supported by the resampler at
           // these rates.
-          int64_t leadSubsamples = leadTicks * ratioNum + 0.5;
+          int64_t leadSubsamples = llround(leadTicks * ratioNum);
           MOZ_ASSERT(leadSubsamples <= skipFracNum,
                      "mBeginProcessing is wrong?");
           skipFracNum -= leadSubsamples;
         }
         speex_resampler_set_skip_frac_num(
             resampler, std::min<int64_t>(skipFracNum, UINT32_MAX));
 
         mBeginProcessing = -TRACK_TIME_MAX;