bug 1024182 remove buffer copy for short impulse responses and so correct normalization scale r=padenot draft
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 09 Aug 2017 16:52:01 +1200
changeset 645137 7f323e9a911b8c348b235196c2a59084d0569620
parent 643064 ca36766642d3b3063467f3eaf2201b119453a9ca
child 645138 a99ad58944734f8e9381516a9d7ea3c92a4ef608
child 647107 830c59ce6a136c7cfb7872e6fac0bb12c80196ac
child 647108 4510964fe006a8453fd6af8a4ce0a24b93069754
child 649733 b04b6cbcdd201d65abcbcf5fc1185ec0d780da01
push id73678
push userktomlinson@mozilla.com
push dateFri, 11 Aug 2017 22:19:56 +0000
reviewerspadenot
bugs1024182
milestone57.0a1
bug 1024182 remove buffer copy for short impulse responses and so correct normalization scale r=padenot Despite the comment, this was necessary only for a direct convolver stage, which has been removed: https://hg.mozilla.org/mozilla-central/rev/e66105937eef190dec073f1b9859e07a0272706b#l4.29 FFT convolver stages pad the buffer to the necessary length in FFTBlock::PadAndMakeScaledDFT(). Trailing zeros in the impulse change the scale used in normalization and so padding the buffer before calculating the scale led to the wrong scale being used. https://github.com/WebAudio/web-audio-api/issues/481 MozReview-Commit-ID: LqP1x1hmLOM
dom/media/webaudio/ConvolverNode.cpp
--- a/dom/media/webaudio/ConvolverNode.cpp
+++ b/dom/media/webaudio/ConvolverNode.cpp
@@ -267,33 +267,16 @@ ConvolverNode::SetBuffer(JSContext* aCx,
 
   // Send the buffer to the stream
   AudioNodeStream* ns = mStream;
   MOZ_ASSERT(ns, "Why don't we have a stream here?");
   if (mBuffer) {
     uint32_t length = mBuffer->Length();
     RefPtr<ThreadSharedFloatArrayBufferList> data =
       mBuffer->GetThreadSharedChannelsForRate(aCx);
-    if (data && length < WEBAUDIO_BLOCK_SIZE) {
-      // For very small impulse response buffers, we need to pad the
-      // buffer with 0 to make sure that the Reverb implementation
-      // has enough data to compute FFTs from.
-      length = WEBAUDIO_BLOCK_SIZE;
-      RefPtr<ThreadSharedFloatArrayBufferList> paddedBuffer =
-        new ThreadSharedFloatArrayBufferList(data->GetChannels());
-      void* channelData = malloc(sizeof(float) * length * data->GetChannels() + 15);
-      float* alignedChannelData = ALIGNED16(channelData);
-      ASSERT_ALIGNED16(alignedChannelData);
-      for (uint32_t i = 0; i < data->GetChannels(); ++i) {
-        PodCopy(alignedChannelData + length * i, data->GetData(i), mBuffer->Length());
-        PodZero(alignedChannelData + length * i + mBuffer->Length(), WEBAUDIO_BLOCK_SIZE - mBuffer->Length());
-        paddedBuffer->SetData(i, (i == 0) ? channelData : nullptr, free, alignedChannelData);
-      }
-      data = paddedBuffer;
-    }
     SendInt32ParameterToStream(ConvolverNodeEngine::BUFFER_LENGTH, length);
     SendDoubleParameterToStream(ConvolverNodeEngine::SAMPLE_RATE,
                                 mBuffer->SampleRate());
     ns->SetBuffer(data.forget());
   } else {
     ns->SetBuffer(nullptr);
   }
 }