b=923301 skip reverb processing when input has been null long enough for output to be null r=roc
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 25 Oct 2013 12:12:13 +1300
changeset 166798 4690758bd1e704ec5d5d898c6f37f2feec19191e
parent 166797 ecf3f03f869cb3ed3027399492de01bba351245a
child 166799 b415b13afe3ac88a44d3cb6816b2cd8a60826eaa
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs923301
milestone27.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=923301 skip reverb processing when input has been null long enough for output to be null r=roc
content/media/webaudio/ConvolverNode.cpp
--- a/content/media/webaudio/ConvolverNode.cpp
+++ b/content/media/webaudio/ConvolverNode.cpp
@@ -28,17 +28,16 @@ class ConvolverNodeEngine : public Audio
 public:
   ConvolverNodeEngine(AudioNode* aNode, bool aNormalize)
     : AudioNodeEngine(aNode)
     , mBufferLength(0)
     , mLeftOverData(INT32_MIN)
     , mSampleRate(0.0f)
     , mUseBackgroundThreads(!aNode->Context()->IsOffline())
     , mNormalize(aNormalize)
-    , mSeenInput(false)
   {
   }
 
   enum Parameters {
     BUFFER_LENGTH,
     SAMPLE_RATE,
     NORMALIZE
   };
@@ -87,54 +86,51 @@ public:
     // If the reverb is single-threaded and processes entirely in the real-time audio thread,
     // it's important not to make this too high.  In this case 8192 is a good value.
     // But, the Reverb object is multi-threaded, so we want this as high as possible without losing too much accuracy.
     // Very large FFTs will have worse phase errors. Given these constraints 32768 is a good compromise.
     const size_t MaxFFTSize = 32768;
 
     if (!mBuffer || !mBufferLength || !mSampleRate) {
       mReverb = nullptr;
-      mSeenInput = false;
       mLeftOverData = INT32_MIN;
       return;
     }
 
     mReverb = new WebCore::Reverb(mBuffer, mBufferLength,
                                   WEBAUDIO_BLOCK_SIZE,
                                   MaxFFTSize, 2, mUseBackgroundThreads,
                                   mNormalize, mSampleRate);
   }
 
   virtual void ProduceAudioBlock(AudioNodeStream* aStream,
                                  const AudioChunk& aInput,
                                  AudioChunk* aOutput,
                                  bool* aFinished)
   {
-    if (!mSeenInput && aInput.IsNull()) {
-      aOutput->SetNull(WEBAUDIO_BLOCK_SIZE);
-      return;
-    }
     if (!mReverb) {
       *aOutput = aInput;
       return;
     }
 
-    mSeenInput = true;
     AudioChunk input = aInput;
     if (aInput.IsNull()) {
-      AllocateAudioBlock(1, &input);
-      WriteZeroesToAudioBlock(&input, 0, WEBAUDIO_BLOCK_SIZE);
-
       if (mLeftOverData > 0) {
         mLeftOverData -= WEBAUDIO_BLOCK_SIZE;
-      } else if (mLeftOverData != INT32_MIN) {
-        mLeftOverData = INT32_MIN;
-        nsRefPtr<PlayingRefChanged> refchanged =
-          new PlayingRefChanged(aStream, PlayingRefChanged::RELEASE);
-        NS_DispatchToMainThread(refchanged);
+        AllocateAudioBlock(1, &input);
+        WriteZeroesToAudioBlock(&input, 0, WEBAUDIO_BLOCK_SIZE);
+      } else {
+        if (mLeftOverData != INT32_MIN) {
+          mLeftOverData = INT32_MIN;
+          nsRefPtr<PlayingRefChanged> refchanged =
+            new PlayingRefChanged(aStream, PlayingRefChanged::RELEASE);
+          NS_DispatchToMainThread(refchanged);
+        }
+        aOutput->SetNull(WEBAUDIO_BLOCK_SIZE);
+        return;
       }
     } else {
       if (aInput.mVolume != 1.0f) {
         // Pre-multiply the input's volume
         uint32_t numChannels = aInput.mChannelData.Length();
         AllocateAudioBlock(numChannels, &input);
         for (uint32_t i = 0; i < numChannels; ++i) {
           const float* src = static_cast<const float*>(aInput.mChannelData[i]);
@@ -159,17 +155,16 @@ public:
 private:
   nsRefPtr<ThreadSharedFloatArrayBufferList> mBuffer;
   nsAutoPtr<WebCore::Reverb> mReverb;
   int32_t mBufferLength;
   int32_t mLeftOverData;
   float mSampleRate;
   bool mUseBackgroundThreads;
   bool mNormalize;
-  bool mSeenInput;
 };
 
 ConvolverNode::ConvolverNode(AudioContext* aContext)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Clamped_max,
               ChannelInterpretation::Speakers)
   , mNormalize(true)