From 5c66861bdfd8ca60728f9ecede21284452fc6491 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Mon, 2 Sep 2013 15:15:24 +0200 Subject: [PATCH] Bug 881959 - Clamp the DelayNode.delayTime to 128/AudioContext.sampleRate when in a cycle. r=ehsan --HG-- extra : rebase_source : 7cf8945371bb6ff169ad61a8ccdda0ece36b5e83 --- content/media/MediaStreamGraph.h | 3 +++ content/media/webaudio/DelayNode.cpp | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/content/media/MediaStreamGraph.h b/content/media/MediaStreamGraph.h index a2efa053485..82598370336 100644 --- a/content/media/MediaStreamGraph.h +++ b/content/media/MediaStreamGraph.h @@ -943,6 +943,9 @@ public: */ virtual void ForwardTrackEnabled(TrackID aOutputID, bool aEnabled) {}; + bool InCycle() const { return mInCycle; } + + protected: // This state is all accessed only on the media graph thread. diff --git a/content/media/webaudio/DelayNode.cpp b/content/media/webaudio/DelayNode.cpp index ddf93101deb..6fed03c9f37 100644 --- a/content/media/webaudio/DelayNode.cpp +++ b/content/media/webaudio/DelayNode.cpp @@ -128,18 +128,28 @@ public: float* const* outputChannels = reinterpret_cast (const_cast(aOutput->mChannelData.Elements())); + + bool inCycle = aStream->AsProcessedStream()->InCycle(); double sampleRate = aStream->SampleRate(); if (mDelay.HasSimpleValue()) { - double delayFrames = mDelay.GetValue() * sampleRate; - mProcessor.Process(delayFrames, inputChannels, outputChannels, + // If this DelayNode is in a cycle, make sure the delay value is at least + // one block. + float delayFrames = mDelay.GetValue() * sampleRate; + float delayFramesClamped = inCycle ? std::max(static_cast(WEBAUDIO_BLOCK_SIZE), delayFrames) : + delayFrames; + mProcessor.Process(delayFramesClamped, inputChannels, outputChannels, numChannels, WEBAUDIO_BLOCK_SIZE); } else { // Compute the delay values for the duration of the input AudioChunk + // If this DelayNode is in a cycle, make sure the delay value is at least + // one block. double computedDelay[WEBAUDIO_BLOCK_SIZE]; TrackTicks tick = aStream->GetCurrentPosition(); for (size_t counter = 0; counter < WEBAUDIO_BLOCK_SIZE; ++counter) { - computedDelay[counter] = - mDelay.GetValueAtTime(tick, counter) * sampleRate; + float delayAtTick = mDelay.GetValueAtTime(tick, counter) * sampleRate; + float delayAtTickClamped = inCycle ? std::max(static_cast(WEBAUDIO_BLOCK_SIZE), delayAtTick) : + delayAtTick; + computedDelay[counter] = delayAtTickClamped; } mProcessor.Process(computedDelay, inputChannels, outputChannels, numChannels, WEBAUDIO_BLOCK_SIZE);