mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 17:23:59 +00:00
Bug 921695 - Part 2: Modify callers. r=karlt
This commit is contained in:
parent
11b47d7a8d
commit
4ffa278343
@ -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,7 +98,7 @@ 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,
|
||||
WebAudioUtils::SpeexResamplerProcess(aResampler, aChannel,
|
||||
aInput + processed, &in,
|
||||
output, &out);
|
||||
processed += in;
|
||||
|
@ -223,7 +223,7 @@ public:
|
||||
static_cast<float*>(const_cast<void*>(aOutput->mChannelData[i])) +
|
||||
aBufferOffset;
|
||||
|
||||
speex_resampler_process_float(resampler, i,
|
||||
WebAudioUtils::SpeexResamplerProcess(resampler, i,
|
||||
inputData, &inSamples,
|
||||
outputData, &outSamples);
|
||||
|
||||
|
@ -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,
|
||||
WebAudioUtils::SpeexResamplerProcess(
|
||||
resampler, i, &bufferData[i * audioData->mFrames], &inSamples,
|
||||
mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
|
||||
&outSamples);
|
||||
#endif
|
||||
|
||||
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,
|
||||
WebAudioUtils::SpeexResamplerProcess(
|
||||
resampler, i, zero, &inSamples,
|
||||
mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
|
||||
&outSamples);
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
@ -106,7 +106,7 @@ public:
|
||||
|
||||
MOZ_ASSERT(mBuffer.Length() == outSamples);
|
||||
|
||||
speex_resampler_process_float(mUpSampler, aChannel,
|
||||
WebAudioUtils::SpeexResamplerProcess(mUpSampler, aChannel,
|
||||
aInputData, &inSamples,
|
||||
outputData, &outSamples);
|
||||
|
||||
@ -123,7 +123,7 @@ public:
|
||||
|
||||
MOZ_ASSERT(mBuffer.Length() == inSamples);
|
||||
|
||||
speex_resampler_process_float(mDownSampler, aChannel,
|
||||
WebAudioUtils::SpeexResamplerProcess(mDownSampler, aChannel,
|
||||
inputData, &inSamples,
|
||||
aOutputData, &outSamples);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user