b=937475 change DURATION from end-offset to duration and compare buffer length using integer sample count r=ehsan
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 03 Dec 2013 12:07:17 +1300
changeset 174182 27c02b405be01be306166fb6d26a62ac638a814a
parent 174181 6c904838825ab0eac1f63317eef9ae6b22c0bf43
child 174183 2e2cdd1826e1a19c7a66a1d6212f551f3ec19c38
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs937475
milestone28.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
b=937475 change DURATION from end-offset to duration and compare buffer length using integer sample count r=ehsan
content/media/webaudio/AudioBufferSourceNode.cpp
--- a/content/media/webaudio/AudioBufferSourceNode.cpp
+++ b/content/media/webaudio/AudioBufferSourceNode.cpp
@@ -401,28 +401,28 @@ public:
       if (mLoop) {
         if (mOffset + t < mLoopEnd) {
           CopyFromBuffer(aStream, aOutput, channels, &written, &currentPosition, mOffset + t, mLoopEnd);
         } else {
           uint32_t offsetInLoop = (mOffset + t - mLoopEnd) % (mLoopEnd - mLoopStart);
           CopyFromBuffer(aStream, aOutput, channels, &written, &currentPosition, mLoopStart + offsetInLoop, mLoopEnd);
         }
       } else {
-        if (mOffset + t < mDuration) {
-          CopyFromBuffer(aStream, aOutput, channels, &written, &currentPosition, mOffset + t, mDuration);
+        if (t < mDuration) {
+          CopyFromBuffer(aStream, aOutput, channels, &written, &currentPosition, mOffset + t, mOffset + mDuration);
         } else {
           FillWithZeroes(aOutput, channels, &written, &currentPosition, TRACK_TICKS_MAX);
         }
       }
     }
 
     // We've finished if we've gone past mStop, or if we're past mDuration when
     // looping is disabled.
     if (currentPosition >= mStop ||
-        (!mLoop && currentPosition - mStart + mOffset >= mDuration)) {
+        (!mLoop && currentPosition - mStart >= mDuration)) {
       *aFinished = true;
     }
   }
 
   TrackTicks mStart;
   TrackTicks mStop;
   nsRefPtr<ThreadSharedFloatArrayBufferList> mBuffer;
   SpeexResamplerState* mResampler;
@@ -545,39 +545,39 @@ void
 AudioBufferSourceNode::SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream,
                                                                double aOffset,
                                                                double aDuration)
 {
   NS_ASSERTION(mBuffer && mStartCalled,
                "Only call this when we have a buffer and start() has been called");
 
   float rate = mBuffer->SampleRate();
-  int32_t lengthSamples = mBuffer->Length();
-  double length = double(lengthSamples) / rate;
-  double offset = std::max(0.0, aOffset);
-  double endOffset = aDuration == std::numeric_limits<double>::min() ?
-                     length : std::min(aOffset + aDuration, length);
+  int32_t bufferLength = mBuffer->Length();
+  int32_t offsetSamples = std::max(0, NS_lround(aOffset * rate));
 
-  if (offset >= endOffset) {
+  if (offsetSamples >= bufferLength) {
     // The offset falls past the end of the buffer.  In this case, we need to
     // stop the playback immediately if it's in progress.
     // Note that we can't call Stop() here since that might be overridden if
     // web content calls Stop() too, so we just null out the buffer.
     if (mStartCalled) {
       aStream->SetBuffer(nullptr);
     }
     return;
   }
+  // Don't set parameter unnecessarily
+  if (offsetSamples > 0) {
+    aStream->SetInt32Parameter(OFFSET, offsetSamples);
+  }
 
-  int32_t offsetTicks = NS_lround(offset*rate);
-  // Don't set parameter unnecessarily
-  if (offsetTicks > 0) {
-    aStream->SetInt32Parameter(OFFSET, offsetTicks);
+  int32_t playingLength = bufferLength - offsetSamples;
+  if (aDuration != std::numeric_limits<double>::min()) {
+    playingLength = std::min(NS_lround(aDuration * rate), playingLength);
   }
-  aStream->SetInt32Parameter(DURATION, NS_lround(endOffset*rate));
+  aStream->SetInt32Parameter(DURATION, playingLength);
 }
 
 void
 AudioBufferSourceNode::Stop(double aWhen, ErrorResult& aRv)
 {
   if (!WebAudioUtils::IsTimeValid(aWhen)) {
     aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
     return;