Bug 1203616 - Properly scale the input buffer before processing it with the curve. r=karlt, a=sylvestre
authorPaul Adenot <paul@paul.cx>
Wed, 07 Oct 2015 10:55:26 +0200
changeset 296380 d77a1a7bc476beb2a42d8db7b9e53441338a0cd0
parent 296379 2fbc5d0584e4797a21b232a26f95f0fc3bceca04
child 296381 304c71a047eb93d95924e8df176f340055513ef9
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt, sylvestre
bugs1203616
milestone43.0a2
Bug 1203616 - Properly scale the input buffer before processing it with the curve. r=karlt, a=sylvestre
dom/media/webaudio/WaveShaperNode.cpp
--- a/dom/media/webaudio/WaveShaperNode.cpp
+++ b/dom/media/webaudio/WaveShaperNode.cpp
@@ -224,36 +224,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.0) {
+        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");
       }
     }
   }