Bug 881959 - Clamp the DelayNode.delayTime to 128/AudioContext.sampleRate when in a cycle. r=ehsan

--HG--
extra : rebase_source : 7cf8945371bb6ff169ad61a8ccdda0ece36b5e83
This commit is contained in:
Paul Adenot 2013-09-02 15:15:24 +02:00
parent d72b8f68e2
commit 5c66861bdf
2 changed files with 17 additions and 4 deletions

View File

@ -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.

View File

@ -128,18 +128,28 @@ public:
float* const* outputChannels = reinterpret_cast<float* const*>
(const_cast<void* const*>(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<float>(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<float>(WEBAUDIO_BLOCK_SIZE), delayAtTick) :
delayAtTick;
computedDelay[counter] = delayAtTickClamped;
}
mProcessor.Process(computedDelay, inputChannels, outputChannels,
numChannels, WEBAUDIO_BLOCK_SIZE);