Bug 1203616 - Properly scale the input buffer of a WaveShaperNode before processing it with the curve. r=karlt
authorPaul Adenot <paul@paul.cx>
Thu, 08 Oct 2015 11:16:31 +0200
changeset 266840 a61652a27e8cc83682b24a9f920df0955b4720b4
parent 266839 02aa09bd9a826ce453d9e374371d9c1442525f1b
child 266841 240a3f4f4346e547802b4c264cf4ed1d1be8bf6c
push id29499
push userkwierso@gmail.com
push dateThu, 08 Oct 2015 21:29:10 +0000
treeherdermozilla-central@46da59584acb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1203616
milestone44.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 1203616 - Properly scale the input buffer of a WaveShaperNode before processing it with the curve. r=karlt
dom/media/webaudio/WaveShaperNode.cpp
--- a/dom/media/webaudio/WaveShaperNode.cpp
+++ b/dom/media/webaudio/WaveShaperNode.cpp
@@ -225,36 +225,44 @@ public:
       // Optimize the case where we don't have a curve buffer,
       // or the input is null.
       *aOutput = aInput;
       return;
     }
 
     aOutput->AllocateChannels(channelCount);
     for (uint32_t i = 0; i < channelCount; ++i) {
-      float* scaledSample = (float *)(aInput.mChannelData[i]);
-      AudioBlockInPlaceScale(scaledSample, aInput.mVolume);
-      const float* inputBuffer = static_cast<const float*>(scaledSample);
+      const float* inputSamples;
+      float scaledInput[WEBAUDIO_BLOCK_SIZE];
+      if (aInput.mVolume != 1.0f) {
+        AudioBlockCopyChannelWithScale(
+            static_cast<const float*>(aInput.mChannelData[i]),
+                                      aInput.mVolume,
+                                      scaledInput);
+        inputSamples = scaledInput;
+      } else {
+        inputSamples = static_cast<const float*>(aInput.mChannelData[i]);
+      }
       float* outputBuffer = aOutput->ChannelFloatsForWrite(i);
       float* sampleBuffer;
 
       switch (mType) {
       case OverSampleType::None:
         mResampler.Reset(channelCount, aStream->SampleRate(), OverSampleType::None);
-        ProcessCurve<1>(inputBuffer, outputBuffer);
+        ProcessCurve<1>(inputSamples, outputBuffer);
         break;
       case OverSampleType::_2x:
         mResampler.Reset(channelCount, aStream->SampleRate(), OverSampleType::_2x);
-        sampleBuffer = mResampler.UpSample(i, inputBuffer, 2);
+        sampleBuffer = mResampler.UpSample(i, inputSamples, 2);
         ProcessCurve<2>(sampleBuffer, sampleBuffer);
         mResampler.DownSample(i, outputBuffer, 2);
         break;
       case OverSampleType::_4x:
         mResampler.Reset(channelCount, aStream->SampleRate(), OverSampleType::_4x);
-        sampleBuffer = mResampler.UpSample(i, inputBuffer, 4);
+        sampleBuffer = mResampler.UpSample(i, inputSamples, 4);
         ProcessCurve<4>(sampleBuffer, sampleBuffer);
         mResampler.DownSample(i, outputBuffer, 4);
         break;
       default:
         NS_NOTREACHED("We should never reach here");
       }
     }
   }