From 23fe293fd511809285bc616fa9589fc19a24547a Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Sun, 10 Mar 2013 18:38:57 -0400 Subject: [PATCH] Bug 849713 - Part 4: Refactor the logic for borrowing the output buffer from the input buffer; r=roc --- .../media/webaudio/AudioBufferSourceNode.cpp | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/content/media/webaudio/AudioBufferSourceNode.cpp b/content/media/webaudio/AudioBufferSourceNode.cpp index dbe438a85703..a34ed946f498 100644 --- a/content/media/webaudio/AudioBufferSourceNode.cpp +++ b/content/media/webaudio/AudioBufferSourceNode.cpp @@ -74,6 +74,20 @@ public: mBuffer = aBuffer; } + void BorrowFromInputBuffer(AudioChunk* aOutput, + uint32_t aChannels, + uintptr_t aBufferOffset) + { + aOutput->mDuration = WEBAUDIO_BLOCK_SIZE; + aOutput->mBuffer = mBuffer; + aOutput->mChannelData.SetLength(aChannels); + for (uint32_t i = 0; i < aChannels; ++i) { + aOutput->mChannelData[i] = mBuffer->GetData(i) + aBufferOffset; + } + aOutput->mVolume = 1.0f; + aOutput->mBufferFormat = AUDIO_FORMAT_FLOAT32; + } + virtual void ProduceAudioBlock(AudioNodeStream* aStream, const AudioChunk& aInput, AudioChunk* aOutput, @@ -106,15 +120,8 @@ public: if (currentPosition >= mStart && currentPosition + WEBAUDIO_BLOCK_SIZE <= endTime) { // Data is entirely within the buffer. Avoid copying it. - aOutput->mDuration = WEBAUDIO_BLOCK_SIZE; - aOutput->mBuffer = mBuffer; - aOutput->mChannelData.SetLength(channels); - for (uint32_t i = 0; i < channels; ++i) { - aOutput->mChannelData[i] = - mBuffer->GetData(i) + uintptr_t(currentPosition - mStart + mOffset); - } - aOutput->mVolume = 1.0f; - aOutput->mBufferFormat = AUDIO_FORMAT_FLOAT32; + BorrowFromInputBuffer(aOutput, channels, + uintptr_t(currentPosition - mStart + mOffset)); return; }