mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 14:30:43 +00:00
b=966636 rename resampling copy variables consistently and test remaining input better r=padenot
--HG-- extra : rebase_source : 7d2c34865aeb21d67207e0d4e7b2fd3e8956d54c
This commit is contained in:
parent
75840f794d
commit
3ecf8b2128
@ -185,32 +185,33 @@ public:
|
||||
void CopyFromInputBufferWithResampling(AudioNodeStream* aStream,
|
||||
AudioChunk* aOutput,
|
||||
uint32_t aChannels,
|
||||
uintptr_t aSourceOffset,
|
||||
uintptr_t aBufferOffset,
|
||||
uint32_t aAvailableInInputBuffer,
|
||||
uint32_t& aFramesWritten) {
|
||||
uint32_t aOffsetWithinBlock,
|
||||
uint32_t& aFramesWritten,
|
||||
uint32_t aBufferOffset,
|
||||
uint32_t aBufferMax) {
|
||||
// TODO: adjust for mStop (see bug 913854 comment 9).
|
||||
uint32_t availableInOutputBuffer = WEBAUDIO_BLOCK_SIZE - aBufferOffset;
|
||||
uint32_t availableInOutputBuffer = WEBAUDIO_BLOCK_SIZE - aOffsetWithinBlock;
|
||||
SpeexResamplerState* resampler = Resampler(aStream, aChannels);
|
||||
MOZ_ASSERT(aChannels > 0);
|
||||
|
||||
if (aAvailableInInputBuffer) {
|
||||
if (aBufferOffset < aBufferMax) {
|
||||
uint32_t availableInInputBuffer = aBufferMax - aBufferOffset;
|
||||
// Limit the number of input samples copied and possibly
|
||||
// format-converted for resampling by estimating how many will be used.
|
||||
// This may be a little small when filling the resampler with initial
|
||||
// data, but we'll get called again and it will work out.
|
||||
uint32_t num, den;
|
||||
speex_resampler_get_ratio(resampler, &num, &den);
|
||||
uint32_t inputLimit = std::min(aAvailableInInputBuffer,
|
||||
uint32_t inputLimit = std::min(availableInInputBuffer,
|
||||
availableInOutputBuffer * den / num + 10);
|
||||
for (uint32_t i = 0; true; ) {
|
||||
uint32_t inSamples = inputLimit;
|
||||
const float* inputData = mBuffer->GetData(i) + aSourceOffset;
|
||||
const float* inputData = mBuffer->GetData(i) + aBufferOffset;
|
||||
|
||||
uint32_t outSamples = availableInOutputBuffer;
|
||||
float* outputData =
|
||||
static_cast<float*>(const_cast<void*>(aOutput->mChannelData[i])) +
|
||||
aBufferOffset;
|
||||
aOffsetWithinBlock;
|
||||
|
||||
WebAudioUtils::SpeexResamplerProcess(resampler, i,
|
||||
inputData, &inSamples,
|
||||
@ -219,7 +220,7 @@ public:
|
||||
mPosition += inSamples;
|
||||
MOZ_ASSERT(mPosition <= mDuration || mLoop);
|
||||
aFramesWritten = outSamples;
|
||||
if (inSamples == aAvailableInInputBuffer && !mLoop) {
|
||||
if (inSamples == availableInInputBuffer && !mLoop) {
|
||||
// If the available output space were unbounded then the input
|
||||
// latency would always be the correct amount of extra input to
|
||||
// provide in order to advance the output position to align with
|
||||
@ -242,7 +243,7 @@ public:
|
||||
uint32_t outSamples = availableInOutputBuffer;
|
||||
float* outputData =
|
||||
static_cast<float*>(const_cast<void*>(aOutput->mChannelData[i])) +
|
||||
aBufferOffset;
|
||||
aOffsetWithinBlock;
|
||||
|
||||
// AudioDataValue* for aIn selects the function that does not try to
|
||||
// copy and format-convert input data.
|
||||
@ -312,6 +313,7 @@ public:
|
||||
aBufferMax - aBufferOffset),
|
||||
mStop - *aCurrentPosition);
|
||||
if (numFrames == WEBAUDIO_BLOCK_SIZE && !ShouldResample(aStream->SampleRate())) {
|
||||
MOZ_ASSERT(aBufferOffset < aBufferMax);
|
||||
BorrowFromInputBuffer(aOutput, aChannels, aBufferOffset);
|
||||
*aOffsetWithinBlock += numFrames;
|
||||
*aCurrentPosition += numFrames;
|
||||
@ -321,16 +323,14 @@ public:
|
||||
AllocateAudioBlock(aChannels, aOutput);
|
||||
}
|
||||
if (!ShouldResample(aStream->SampleRate())) {
|
||||
MOZ_ASSERT(aBufferOffset < aBufferMax);
|
||||
CopyFromInputBuffer(aOutput, aChannels, aBufferOffset, *aOffsetWithinBlock, numFrames);
|
||||
*aOffsetWithinBlock += numFrames;
|
||||
*aCurrentPosition += numFrames;
|
||||
mPosition += numFrames;
|
||||
} else {
|
||||
uint32_t framesWritten, availableInInputBuffer;
|
||||
|
||||
availableInInputBuffer = aBufferMax - aBufferOffset;
|
||||
|
||||
CopyFromInputBufferWithResampling(aStream, aOutput, aChannels, aBufferOffset, *aOffsetWithinBlock, availableInInputBuffer, framesWritten);
|
||||
uint32_t framesWritten;
|
||||
CopyFromInputBufferWithResampling(aStream, aOutput, aChannels, *aOffsetWithinBlock, framesWritten, aBufferOffset, aBufferMax);
|
||||
*aOffsetWithinBlock += framesWritten;
|
||||
*aCurrentPosition += framesWritten;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user