diff --git a/content/media/webaudio/AudioBufferSourceNode.cpp b/content/media/webaudio/AudioBufferSourceNode.cpp index ca809ba39769..adf1505ca930 100644 --- a/content/media/webaudio/AudioBufferSourceNode.cpp +++ b/content/media/webaudio/AudioBufferSourceNode.cpp @@ -472,8 +472,7 @@ AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* aContext) ChannelInterpretation::Speakers) , mLoopStart(0.0) , mLoopEnd(0.0) - , mOffset(0.0) - , mDuration(std::numeric_limits::min()) + // mOffset and mDuration are initialized in Start(). , mPlaybackRate(new AudioParam(MOZ_THIS_IN_INITIALIZER_LIST(), SendPlaybackRateToStream, 1.0f)) , mLoop(false) @@ -521,19 +520,14 @@ AudioBufferSourceNode::Start(double aWhen, double aOffset, return; } + // Remember our arguments so that we can use them when we get a new buffer. + mOffset = aOffset; + mDuration = aDuration.WasPassed() ? aDuration.Value() + : std::numeric_limits::min(); + // We can't send these parameters without a buffer because we don't know the + // buffer's sample rate or length. if (mBuffer) { - double duration = aDuration.WasPassed() ? - aDuration.Value() : - std::numeric_limits::min(); - SendOffsetAndDurationParametersToStream(ns, aOffset, duration); - } else { - // Remember our arguments so that we can use them once we have a buffer. - // We can't send these parameters now because we don't know the buffer - // sample rate. - mOffset = aOffset; - mDuration = aDuration.WasPassed() ? - aDuration.Value() : - std::numeric_limits::min(); + SendOffsetAndDurationParametersToStream(ns); } // Don't set parameter unnecessarily @@ -558,7 +552,7 @@ AudioBufferSourceNode::SendBufferParameterToStream(JSContext* aCx) ns->SetInt32Parameter(SAMPLE_RATE, rate); if (mStartCalled) { - SendOffsetAndDurationParametersToStream(ns, mOffset, mDuration); + SendOffsetAndDurationParametersToStream(ns); } } else { ns->SetBuffer(nullptr); @@ -566,16 +560,14 @@ AudioBufferSourceNode::SendBufferParameterToStream(JSContext* aCx) } void -AudioBufferSourceNode::SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream, - double aOffset, - double aDuration) +AudioBufferSourceNode::SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream) { NS_ASSERTION(mBuffer && mStartCalled, "Only call this when we have a buffer and start() has been called"); float rate = mBuffer->SampleRate(); int32_t bufferLength = mBuffer->Length(); - int32_t offsetSamples = std::max(0, NS_lround(aOffset * rate)); + int32_t offsetSamples = std::max(0, NS_lround(mOffset * rate)); if (offsetSamples >= bufferLength) { // The offset falls past the end of the buffer. In this case, we need to @@ -593,8 +585,8 @@ AudioBufferSourceNode::SendOffsetAndDurationParametersToStream(AudioNodeStream* } int32_t playingLength = bufferLength - offsetSamples; - if (aDuration != std::numeric_limits::min()) { - playingLength = std::min(NS_lround(aDuration * rate), playingLength); + if (mDuration != std::numeric_limits::min()) { + playingLength = std::min(NS_lround(mDuration * rate), playingLength); } aStream->SetInt32Parameter(DURATION, playingLength); } diff --git a/content/media/webaudio/AudioBufferSourceNode.h b/content/media/webaudio/AudioBufferSourceNode.h index a53097afdba2..93d5e9cdd0c9 100644 --- a/content/media/webaudio/AudioBufferSourceNode.h +++ b/content/media/webaudio/AudioBufferSourceNode.h @@ -111,9 +111,10 @@ public: private: friend class AudioBufferSourceNodeEngine; - // START, OFFSET and DURATION are always set by start() (along with setting - // mBuffer to something non-null). - // STOP is set by stop(). + // START is sent during Start(). + // STOP is sent during Stop(). + // OFFSET and DURATION are sent when SetBuffer() and Start() have + // been called (along with sending the buffer). enum EngineParameters { SAMPLE_RATE, START, @@ -129,9 +130,7 @@ private: void SendLoopParametersToStream(); void SendBufferParameterToStream(JSContext* aCx); - void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream, - double aOffset, - double aDuration); + void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream); static void SendPlaybackRateToStream(AudioNode* aNode); private: