2013-03-21 21:01:28 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebAudioUtils.h"
|
|
|
|
#include "AudioNodeStream.h"
|
2013-08-15 12:44:14 -07:00
|
|
|
#include "AudioParamTimeline.h"
|
2013-08-08 15:07:42 -07:00
|
|
|
#include "blink/HRTFDatabaseLoader.h"
|
2013-03-21 21:01:28 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
struct ConvertTimeToTickHelper
|
|
|
|
{
|
|
|
|
AudioNodeStream* mSourceStream;
|
|
|
|
AudioNodeStream* mDestinationStream;
|
|
|
|
|
|
|
|
static int64_t Convert(double aTime, void* aClosure)
|
|
|
|
{
|
|
|
|
ConvertTimeToTickHelper* This = static_cast<ConvertTimeToTickHelper*> (aClosure);
|
2013-07-12 02:23:21 -07:00
|
|
|
MOZ_ASSERT(This->mSourceStream->SampleRate() == This->mDestinationStream->SampleRate());
|
2014-02-16 12:46:56 -08:00
|
|
|
return This->mSourceStream->
|
|
|
|
TicksFromDestinationTime(This->mDestinationStream, aTime);
|
2013-03-21 21:01:28 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
WebAudioUtils::ConvertAudioParamToTicks(AudioParamTimeline& aParam,
|
|
|
|
AudioNodeStream* aSource,
|
|
|
|
AudioNodeStream* aDest)
|
|
|
|
{
|
2013-05-24 10:11:18 -07:00
|
|
|
MOZ_ASSERT(!aSource || aSource->SampleRate() == aDest->SampleRate());
|
2013-03-21 21:01:28 -07:00
|
|
|
ConvertTimeToTickHelper ctth;
|
|
|
|
ctth.mSourceStream = aSource;
|
|
|
|
ctth.mDestinationStream = aDest;
|
2013-05-24 10:11:18 -07:00
|
|
|
aParam.ConvertEventTimesToTicks(ConvertTimeToTickHelper::Convert, &ctth, aDest->SampleRate());
|
2013-03-21 21:01:28 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 15:07:42 -07:00
|
|
|
void
|
|
|
|
WebAudioUtils::Shutdown()
|
|
|
|
{
|
|
|
|
WebCore::HRTFDatabaseLoader::shutdown();
|
|
|
|
}
|
|
|
|
|
2013-09-30 23:22:54 -07:00
|
|
|
int
|
|
|
|
WebAudioUtils::SpeexResamplerProcess(SpeexResamplerState* aResampler,
|
|
|
|
uint32_t aChannel,
|
|
|
|
const float* aIn, uint32_t* aInLen,
|
|
|
|
float* aOut, uint32_t* aOutLen)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_SAMPLE_TYPE_S16
|
|
|
|
nsAutoTArray<AudioDataValue, WEBAUDIO_BLOCK_SIZE*4> tmp1;
|
|
|
|
nsAutoTArray<AudioDataValue, WEBAUDIO_BLOCK_SIZE*4> tmp2;
|
|
|
|
tmp1.SetLength(*aInLen);
|
|
|
|
tmp2.SetLength(*aOutLen);
|
|
|
|
ConvertAudioSamples(aIn, tmp1.Elements(), *aInLen);
|
|
|
|
int result = speex_resampler_process_int(aResampler, aChannel, tmp1.Elements(), aInLen, tmp2.Elements(), aOutLen);
|
|
|
|
ConvertAudioSamples(tmp2.Elements(), aOut, *aOutLen);
|
|
|
|
return result;
|
|
|
|
#else
|
|
|
|
return speex_resampler_process_float(aResampler, aChannel, aIn, aInLen, aOut, aOutLen);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
WebAudioUtils::SpeexResamplerProcess(SpeexResamplerState* aResampler,
|
|
|
|
uint32_t aChannel,
|
|
|
|
const int16_t* aIn, uint32_t* aInLen,
|
|
|
|
float* aOut, uint32_t* aOutLen)
|
|
|
|
{
|
|
|
|
nsAutoTArray<AudioDataValue, WEBAUDIO_BLOCK_SIZE*4> tmp;
|
|
|
|
#ifdef MOZ_SAMPLE_TYPE_S16
|
|
|
|
tmp.SetLength(*aOutLen);
|
|
|
|
int result = speex_resampler_process_int(aResampler, aChannel, aIn, aInLen, tmp.Elements(), aOutLen);
|
|
|
|
ConvertAudioSamples(tmp.Elements(), aOut, *aOutLen);
|
|
|
|
return result;
|
|
|
|
#else
|
|
|
|
tmp.SetLength(*aInLen);
|
|
|
|
ConvertAudioSamples(aIn, tmp.Elements(), *aInLen);
|
|
|
|
int result = speex_resampler_process_float(aResampler, aChannel, tmp.Elements(), aInLen, aOut, aOutLen);
|
|
|
|
return result;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-24 03:06:05 -07:00
|
|
|
int
|
|
|
|
WebAudioUtils::SpeexResamplerProcess(SpeexResamplerState* aResampler,
|
|
|
|
uint32_t aChannel,
|
|
|
|
const int16_t* aIn, uint32_t* aInLen,
|
|
|
|
int16_t* aOut, uint32_t* aOutLen)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_SAMPLE_TYPE_S16
|
|
|
|
return speex_resampler_process_int(aResampler, aChannel, aIn, aInLen, aOut, aOutLen);
|
|
|
|
#else
|
|
|
|
nsAutoTArray<AudioDataValue, WEBAUDIO_BLOCK_SIZE*4> tmp1;
|
|
|
|
nsAutoTArray<AudioDataValue, WEBAUDIO_BLOCK_SIZE*4> tmp2;
|
|
|
|
tmp1.SetLength(*aInLen);
|
|
|
|
tmp2.SetLength(*aOutLen);
|
|
|
|
ConvertAudioSamples(aIn, tmp1.Elements(), *aInLen);
|
|
|
|
int result = speex_resampler_process_float(aResampler, aChannel, tmp1.Elements(), aInLen, tmp2.Elements(), aOutLen);
|
|
|
|
ConvertAudioSamples(tmp2.Elements(), aOut, *aOutLen);
|
|
|
|
return result;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-03-21 21:01:28 -07:00
|
|
|
}
|
|
|
|
}
|