Bug 921695 - Part 2: Modify callers. r=karlt

This commit is contained in:
JW Wang 2013-10-01 14:22:57 +08:00
parent 11b47d7a8d
commit 4ffa278343
4 changed files with 21 additions and 87 deletions

View File

@ -79,39 +79,6 @@ AudioNodeExternalInputStream::GetTrackMapEntry(const StreamBuffer::Track& aTrack
static const uint32_t SPEEX_RESAMPLER_PROCESS_MAX_OUTPUT = 1000;
template <typename T> static int
SpeexResamplerProcess(SpeexResamplerState* aResampler,
uint32_t aChannel,
const T* aInput, uint32_t* aIn,
float* aOutput, uint32_t* aOut);
template <> int
SpeexResamplerProcess<float>(SpeexResamplerState* aResampler,
uint32_t aChannel,
const float* aInput, uint32_t* aIn,
float* aOutput, uint32_t* aOut)
{
NS_ASSERTION(*aOut <= SPEEX_RESAMPLER_PROCESS_MAX_OUTPUT, "Bad aOut");
return speex_resampler_process_float(aResampler, aChannel, aInput, aIn, aOutput, aOut);
}
template <> int
SpeexResamplerProcess<int16_t>(SpeexResamplerState* aResampler,
uint32_t aChannel,
const int16_t* aInput, uint32_t* aIn,
float* aOutput, uint32_t* aOut)
{
NS_ASSERTION(*aOut <= SPEEX_RESAMPLER_PROCESS_MAX_OUTPUT, "Bad aOut");
int16_t tmp[SPEEX_RESAMPLER_PROCESS_MAX_OUTPUT];
int result = speex_resampler_process_int(aResampler, aChannel, aInput, aIn, tmp, aOut);
if (result == RESAMPLER_ERR_SUCCESS) {
for (uint32_t i = 0; i < *aOut; ++i) {
aOutput[i] = AudioSampleToFloat(tmp[i]);
}
}
return result;
}
template <typename T> static void
ResampleChannelBuffer(SpeexResamplerState* aResampler, uint32_t aChannel,
const T* aInput, uint32_t aInputDuration,
@ -131,9 +98,9 @@ ResampleChannelBuffer(SpeexResamplerState* aResampler, uint32_t aChannel,
float* output = aOutput->AppendElements(SPEEX_RESAMPLER_PROCESS_MAX_OUTPUT);
uint32_t in = aInputDuration - processed;
uint32_t out = aOutput->Length() - prevLength;
SpeexResamplerProcess(aResampler, aChannel,
aInput + processed, &in,
output, &out);
WebAudioUtils::SpeexResamplerProcess(aResampler, aChannel,
aInput + processed, &in,
output, &out);
processed += in;
aOutput->SetLength(prevLength + out);
}

View File

@ -223,9 +223,9 @@ public:
static_cast<float*>(const_cast<void*>(aOutput->mChannelData[i])) +
aBufferOffset;
speex_resampler_process_float(resampler, i,
inputData, &inSamples,
outputData, &outSamples);
WebAudioUtils::SpeexResamplerProcess(resampler, i,
inputData, &inSamples,
outputData, &outSamples);
aFramesRead = inSamples;
aFramesWritten = outSamples;

View File

@ -19,6 +19,7 @@
#include "nsIScriptError.h"
#include "nsMimeTypes.h"
#include "nsCxPusher.h"
#include "WebAudioUtils.h"
namespace mozilla {
@ -350,37 +351,21 @@ MediaDecodeTask::Decode()
static_cast<uint64_t>(audioData->mFrames) /
static_cast<uint64_t>(sampleRate)
);
#ifdef MOZ_SAMPLE_TYPE_S16
AudioDataValue* resampledBuffer = new(fallible) AudioDataValue[channelCount * expectedOutSamples];
#endif
for (uint32_t i = 0; i < audioData->mChannels; ++i) {
uint32_t inSamples = audioData->mFrames;
uint32_t outSamples = expectedOutSamples;
#ifdef MOZ_SAMPLE_TYPE_S16
speex_resampler_process_int(resampler, i, &bufferData[i * audioData->mFrames], &inSamples,
&resampledBuffer[i * expectedOutSamples],
&outSamples);
ConvertAudioSamples(&resampledBuffer[i * expectedOutSamples],
mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
outSamples);
#else
speex_resampler_process_float(resampler, i, &bufferData[i * audioData->mFrames], &inSamples,
mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
&outSamples);
#endif
WebAudioUtils::SpeexResamplerProcess(
resampler, i, &bufferData[i * audioData->mFrames], &inSamples,
mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
&outSamples);
if (i == audioData->mChannels - 1) {
mDecodeJob.mWriteIndex += outSamples;
MOZ_ASSERT(mDecodeJob.mWriteIndex <= resampledFrames);
}
}
#ifdef MOZ_SAMPLE_TYPE_S16
delete[] resampledBuffer;
#endif
} else {
for (uint32_t i = 0; i < audioData->mChannels; ++i) {
ConvertAudioSamples(&bufferData[i * audioData->mFrames],
@ -399,12 +384,7 @@ MediaDecodeTask::Decode()
int outputLatency = speex_resampler_get_output_latency(resampler);
AudioDataValue* zero = (AudioDataValue*)calloc(inputLatency, sizeof(AudioDataValue));
#ifdef MOZ_SAMPLE_TYPE_S16
AudioDataValue* resampledBuffer = new(fallible) AudioDataValue[channelCount * outputLatency];
if (!resampledBuffer || !zero) {
#else
if (!zero) {
#endif
// Out of memory!
ReportFailureOnMainThread(WebAudioDecodeJob::UnknownError);
return;
@ -414,19 +394,10 @@ MediaDecodeTask::Decode()
uint32_t inSamples = inputLatency;
uint32_t outSamples = outputLatency;
#ifdef MOZ_SAMPLE_TYPE_S16
speex_resampler_process_int(resampler, i, zero, &inSamples,
&resampledBuffer[i * outputLatency],
&outSamples);
ConvertAudioSamples(&resampledBuffer[i * outputLatency],
mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
outSamples);
#else
speex_resampler_process_float(resampler, i, zero, &inSamples,
mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
&outSamples);
#endif
WebAudioUtils::SpeexResamplerProcess(
resampler, i, zero, &inSamples,
mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
&outSamples);
if (i == channelCount - 1) {
mDecodeJob.mWriteIndex += outSamples;
@ -435,10 +406,6 @@ MediaDecodeTask::Decode()
}
free(zero);
#ifdef MOZ_SAMPLE_TYPE_S16
delete[] resampledBuffer;
#endif
}
mPhase = PhaseEnum::AllocateBuffer;

View File

@ -106,9 +106,9 @@ public:
MOZ_ASSERT(mBuffer.Length() == outSamples);
speex_resampler_process_float(mUpSampler, aChannel,
aInputData, &inSamples,
outputData, &outSamples);
WebAudioUtils::SpeexResamplerProcess(mUpSampler, aChannel,
aInputData, &inSamples,
outputData, &outSamples);
MOZ_ASSERT(inSamples == WEBAUDIO_BLOCK_SIZE && outSamples == WEBAUDIO_BLOCK_SIZE*aBlocks);
@ -123,9 +123,9 @@ public:
MOZ_ASSERT(mBuffer.Length() == inSamples);
speex_resampler_process_float(mDownSampler, aChannel,
inputData, &inSamples,
aOutputData, &outSamples);
WebAudioUtils::SpeexResamplerProcess(mDownSampler, aChannel,
inputData, &inSamples,
aOutputData, &outSamples);
MOZ_ASSERT(inSamples == WEBAUDIO_BLOCK_SIZE*aBlocks && outSamples == WEBAUDIO_BLOCK_SIZE);
}