Bug 880129 - Correctly handle AnalyserNodes with a buffer size smaller than 128; r=roc

This commit is contained in:
Ehsan Akhgari 2013-06-07 07:33:00 -04:00
parent 970bda8200
commit 1391c0772c
3 changed files with 20 additions and 4 deletions

View File

@ -0,0 +1,9 @@
<script>
try { o1 = new window.AudioContext(3, 2, 44100); } catch(e) { }
try { o6 = o1.createBufferSource(); } catch(e) { }
try { o15 = o1.createAnalyser(); } catch(e) { }
try { o15.fftSize = 32; } catch(e) { }
try { o6.connect(o15,0,0) } catch(e) { }
try { o27 = o1.createPanner(); } catch(e) { }
try { o6.buffer = function(){var buffer = o1.createBuffer(2, 1148, o1.sampleRate);for(var c=0; c<2; c++) {for(var i=0; i<1148; i++) {buffer.getChannelData(c)[i] = 0;}}return buffer;}() } catch(e) { }
</script>

View File

@ -38,4 +38,5 @@ load 878328.html
load 878407.html load 878407.html
load 878478.html load 878478.html
load 877527.html load 877527.html
load 880129.html
skip-if(B2G) load 880202.html # load failed, bug 833371 for B2G skip-if(B2G) load 880202.html # load failed, bug 833371 for B2G

View File

@ -9,6 +9,7 @@
#include "AudioNodeEngine.h" #include "AudioNodeEngine.h"
#include "AudioNodeStream.h" #include "AudioNodeStream.h"
#include "mozilla/Mutex.h" #include "mozilla/Mutex.h"
#include "mozilla/PodOperations.h"
#include "kiss_fft/kiss_fftr.h" #include "kiss_fft/kiss_fftr.h"
namespace mozilla { namespace mozilla {
@ -275,12 +276,17 @@ AnalyserNode::AppendChunk(const AudioChunk& aChunk)
{ {
const uint32_t bufferSize = mBuffer.Length(); const uint32_t bufferSize = mBuffer.Length();
const uint32_t channelCount = aChunk.mChannelData.Length(); const uint32_t channelCount = aChunk.mChannelData.Length();
const uint32_t chunkCount = aChunk.mDuration; uint32_t chunkDuration = aChunk.mDuration;
MOZ_ASSERT((bufferSize & (bufferSize - 1)) == 0); // Must be a power of two! MOZ_ASSERT((bufferSize & (bufferSize - 1)) == 0); // Must be a power of two!
MOZ_ASSERT(channelCount > 0); MOZ_ASSERT(channelCount > 0);
MOZ_ASSERT(chunkCount == WEBAUDIO_BLOCK_SIZE); MOZ_ASSERT(chunkDuration == WEBAUDIO_BLOCK_SIZE);
memcpy(mBuffer.Elements() + mWriteIndex, aChunk.mChannelData[0], sizeof(float) * chunkCount); if (chunkDuration > bufferSize) {
// Copy a maximum bufferSize samples.
chunkDuration = bufferSize;
}
PodCopy(mBuffer.Elements() + mWriteIndex, static_cast<const float*>(aChunk.mChannelData[0]), chunkDuration);
for (uint32_t i = 1; i < channelCount; ++i) { for (uint32_t i = 1; i < channelCount; ++i) {
AudioBlockAddChannelWithScale(static_cast<const float*>(aChunk.mChannelData[i]), 1.0f, AudioBlockAddChannelWithScale(static_cast<const float*>(aChunk.mChannelData[i]), 1.0f,
mBuffer.Elements() + mWriteIndex); mBuffer.Elements() + mWriteIndex);
@ -289,7 +295,7 @@ AnalyserNode::AppendChunk(const AudioChunk& aChunk)
AudioBlockInPlaceScale(mBuffer.Elements() + mWriteIndex, 1, AudioBlockInPlaceScale(mBuffer.Elements() + mWriteIndex, 1,
1.0f / aChunk.mChannelData.Length()); 1.0f / aChunk.mChannelData.Length());
} }
mWriteIndex += chunkCount; mWriteIndex += chunkDuration;
MOZ_ASSERT(mWriteIndex <= bufferSize); MOZ_ASSERT(mWriteIndex <= bufferSize);
if (mWriteIndex >= bufferSize) { if (mWriteIndex >= bufferSize) {
mWriteIndex = 0; mWriteIndex = 0;