From e1154a6a56aa1624e0febd4fa42e60560ada9c43 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 --HG-- extra : rebase_source : b2505272bf0b177dfb0c6215d0e232a591b6650a --- 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 a611d14c6828..d8dca2adede8 100644 --- a/dom/media/webaudio/WaveShaperNode.cpp +++ b/dom/media/webaudio/WaveShaperNode.cpp @@ -230,26 +230,34 @@ public: 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(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;