Bug 873553 - Part 7: Port DelayNode to use the stream's sampling rate; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 24 May 2013 13:10:44 -0400
changeset 132904 4c425085391c20885227445376d5e94ac9c4a1cc
parent 132903 d34c29fe4edaa9e948c184f2b79224e735638aa0
child 132905 a10e7a43eebfe766586fa03e32525431f4b64738
push id28511
push usereakhgari@mozilla.com
push dateFri, 24 May 2013 17:15:29 +0000
treeherdermozilla-inbound@670d867ff3ba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs873553
milestone24.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 873553 - Part 7: Port DelayNode to use the stream's sampling rate; r=roc
content/media/webaudio/DelayNode.cpp
--- a/content/media/webaudio/DelayNode.cpp
+++ b/content/media/webaudio/DelayNode.cpp
@@ -102,26 +102,26 @@ public:
   {
     switch (aIndex) {
     case MAX_DELAY: mMaxDelay = aValue; break;
     default:
       NS_ERROR("Bad DelayNodeEngine DoubleParameter");
     }
   }
 
-  bool EnsureBuffer(uint32_t aNumberOfChannels)
+  bool EnsureBuffer(uint32_t aNumberOfChannels, TrackRate aSampleRate)
   {
     if (aNumberOfChannels == 0) {
       return false;
     }
     if (mBuffer.Length() == 0) {
       if (!mBuffer.SetLength(aNumberOfChannels)) {
         return false;
       }
-      const int32_t numFrames = NS_lround(mMaxDelay) * IdealAudioRate();
+      const int32_t numFrames = NS_lround(mMaxDelay) * aSampleRate;
       for (uint32_t channel = 0; channel < aNumberOfChannels; ++channel) {
         if (!mBuffer[channel].SetLength(numFrames)) {
           return false;
         }
         memset(mBuffer[channel].Elements(), 0, numFrames * sizeof(float));
       }
     } else if (mBuffer.Length() != aNumberOfChannels) {
       // TODO: Handle changes in the channel count
@@ -141,17 +141,17 @@ public:
     const uint32_t numChannels = aInput.IsNull() ?
                                  mBuffer.Length() :
                                  aInput.mChannelData.Length();
 
     bool playedBackAllLeftOvers = false;
     if (!mBuffer.IsEmpty() &&
         mLeftOverData == INT32_MIN &&
         aStream->AllInputsFinished()) {
-      mLeftOverData = static_cast<int32_t>(mCurrentDelayTime * IdealAudioRate()) - WEBAUDIO_BLOCK_SIZE;
+      mLeftOverData = static_cast<int32_t>(mCurrentDelayTime * aStream->SampleRate()) - WEBAUDIO_BLOCK_SIZE;
 
       if (mLeftOverData > 0) {
         nsRefPtr<PlayingRefChanged> refchanged =
           new PlayingRefChanged(aStream, PlayingRefChanged::ADDREF);
         NS_DispatchToMainThread(refchanged);
       }
     } else if (mLeftOverData != INT32_MIN) {
       mLeftOverData -= WEBAUDIO_BLOCK_SIZE;
@@ -160,27 +160,27 @@ public:
         playedBackAllLeftOvers = true;
 
         nsRefPtr<PlayingRefChanged> refchanged =
           new PlayingRefChanged(aStream, PlayingRefChanged::RELEASE);
         NS_DispatchToMainThread(refchanged);
       }
     }
 
-    if (!EnsureBuffer(numChannels)) {
+    if (!EnsureBuffer(numChannels, aStream->SampleRate())) {
       aOutput->SetNull(0);
       return;
     }
 
     AllocateAudioBlock(numChannels, aOutput);
 
     double delayTime = 0;
     float computedDelay[WEBAUDIO_BLOCK_SIZE];
     // Use a smoothing range of 20ms
-    const double smoothingRate = WebAudioUtils::ComputeSmoothingRate(0.02, IdealAudioRate());
+    const double smoothingRate = WebAudioUtils::ComputeSmoothingRate(0.02, aStream->SampleRate());
 
     if (mDelay.HasSimpleValue()) {
       delayTime = std::max(0.0, std::min(mMaxDelay, double(mDelay.GetValue())));
       if (firstTime) {
         // Initialize this only the first time to make sure that mCurrentDelayTime
         // has a valid value when we try to change the delay time further below.
         mCurrentDelayTime = delayTime;
       }
@@ -214,17 +214,17 @@ public:
         if (input) {
           buffer[writeIndex] = input[i] * aInput.mVolume;
         }
 
         // Now, determine the correct read position.  We adjust the read position to be
         // from currentDelayTime seconds in the past.  We also interpolate the two input
         // frames in case the read position does not match an integer index.
         double readPosition = writeIndex + bufferLength -
-                              (currentDelayTime * IdealAudioRate());
+                              (currentDelayTime * aStream->SampleRate());
         if (readPosition >= bufferLength) {
           readPosition -= bufferLength;
         }
         MOZ_ASSERT(readPosition >= 0.0, "Why are we reading before the beginning of the buffer?");
 
         // Here is a the reason why readIndex1 and readIndex will never be out
         // of bounds.  The maximum value for bufferLength is 180 * 48000 (see
         // AudioContext::CreateDelay).  The maximum value for mCurrentDelay is