From 1858803b03270ba2b4dae2e3e65e168483947ce6 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Thu, 8 Oct 2015 11:16:31 +0200 Subject: [PATCH] Bug 1203616 - Properly scale the input buffer of a WaveShaperNode before processing it with the curve. r=karlt, a=sylvestre --HG-- extra : source : a61652a27e8cc83682b24a9f920df0955b4720b4 extra : amend_source : 6960da7cbae1677685b8af431db301e818d4d4fe --- dom/media/webaudio/WaveShaperNode.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/dom/media/webaudio/WaveShaperNode.cpp b/dom/media/webaudio/WaveShaperNode.cpp index a2379fb10a23..f10a0cd34ed0 100644 --- a/dom/media/webaudio/WaveShaperNode.cpp +++ b/dom/media/webaudio/WaveShaperNode.cpp @@ -229,26 +229,34 @@ public: AllocateAudioBlock(channelCount, aOutput); for (uint32_t i = 0; i < channelCount; ++i) { - float* scaledSample = (float *)(aInput.mChannelData[i]); - AudioBlockInPlaceScale(scaledSample, aInput.mVolume); - const float* inputBuffer = static_cast(scaledSample); + const float* inputSamples; + float scaledInput[WEBAUDIO_BLOCK_SIZE]; + if (aInput.mVolume != 1.0f) { + AudioBlockCopyChannelWithScale( + static_cast(aInput.mChannelData[i]), + aInput.mVolume, + scaledInput); + inputSamples = scaledInput; + } else { + inputSamples = static_cast(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;