- clang format + naming improved
This commit is contained in:
@@ -17,8 +17,7 @@ namespace Audio
|
||||
{
|
||||
|
||||
|
||||
SpeexResampler::SpeexResampler()
|
||||
{}
|
||||
SpeexResampler::SpeexResampler() {}
|
||||
|
||||
void SpeexResampler::start(int channels, int sourceRate, int destRate)
|
||||
{
|
||||
@@ -35,8 +34,8 @@ void SpeexResampler::start(int channels, int sourceRate, int destRate)
|
||||
if (sourceRate != destRate)
|
||||
{
|
||||
// Defer context creation until first request
|
||||
//mContext = speex_resampler_init(channels, sourceRate, destRate, AUDIO_RESAMPLER_QUALITY, &mErrorCode);
|
||||
//assert(mContext != NULL);
|
||||
// mContext = speex_resampler_init(channels, sourceRate, destRate, AUDIO_RESAMPLER_QUALITY, &mErrorCode);
|
||||
// assert(mContext != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +58,8 @@ SpeexResampler::~SpeexResampler()
|
||||
stop();
|
||||
}
|
||||
|
||||
size_t SpeexResampler::processBuffer(const void* src, size_t sourceLength, size_t& sourceProcessed,
|
||||
void* dest, size_t destCapacity)
|
||||
size_t SpeexResampler::processBuffer(const void* src, size_t sourceLength, size_t& sourceProcessed, void* dest,
|
||||
size_t destCapacity)
|
||||
{
|
||||
assert(mSourceRate != 0 && mDestRate != 0);
|
||||
|
||||
@@ -77,8 +76,7 @@ size_t SpeexResampler::processBuffer(const void* src, size_t sourceLength, size_
|
||||
|
||||
if (!mContext)
|
||||
{
|
||||
mContext = speex_resampler_init(mChannels, mSourceRate, mDestRate,
|
||||
AUDIO_RESAMPLER_QUALITY, &mErrorCode);
|
||||
mContext = speex_resampler_init(mChannels, mSourceRate, mDestRate, AUDIO_RESAMPLER_QUALITY, &mErrorCode);
|
||||
if (!mContext)
|
||||
return 0;
|
||||
}
|
||||
@@ -103,11 +101,9 @@ size_t SpeexResampler::processBuffer(const void* src, size_t sourceLength, size_
|
||||
unsigned inLen = sourceLength / (sizeof(short) * mChannels);
|
||||
outLen /= sizeof(short) * mChannels;
|
||||
assert(mContext != NULL);
|
||||
spx_uint32_t in_len = static_cast<spx_uint32_t>(inLen),
|
||||
out_len = static_cast<spx_uint32_t>(outLen);
|
||||
spx_uint32_t in_len = static_cast<spx_uint32_t>(inLen), out_len = static_cast<spx_uint32_t>(outLen);
|
||||
|
||||
int speexCode = speex_resampler_process_interleaved_int((SpeexResamplerState *)mContext,
|
||||
(spx_int16_t*)src, &in_len,
|
||||
int speexCode = speex_resampler_process_interleaved_int((SpeexResamplerState*)mContext, (spx_int16_t*)src, &in_len,
|
||||
(spx_int16_t*)dest, &out_len);
|
||||
assert(speexCode == RESAMPLER_ERR_SUCCESS);
|
||||
|
||||
@@ -147,27 +143,27 @@ size_t SpeexResampler::getSize() const
|
||||
}
|
||||
|
||||
// -------------------------- ChannelConverter --------------------
|
||||
int ChannelConverter::stereoToMono(const void *source, int sourceLength, void *dest, int destLength)
|
||||
int ChannelConverter::stereoToMono(const void* source, int sourceLength, void* dest, int destLength)
|
||||
{
|
||||
assert(destLength == sourceLength / 2);
|
||||
const short* input = (const short*)source;
|
||||
short* output = (short*)dest;
|
||||
for (int sampleIndex = 0; sampleIndex < destLength/2; sampleIndex++)
|
||||
short* output = (short*)dest;
|
||||
for (int sampleIndex = 0; sampleIndex < destLength / 2; sampleIndex++)
|
||||
{
|
||||
output[sampleIndex] = (input[sampleIndex*2] + input[sampleIndex*2+1]) >> 1;
|
||||
output[sampleIndex] = (input[sampleIndex * 2] + input[sampleIndex * 2 + 1]) >> 1;
|
||||
}
|
||||
return sourceLength / 2;
|
||||
}
|
||||
|
||||
int ChannelConverter::monoToStereo(const void *source, int sourceLength, void *dest, int destLength)
|
||||
int ChannelConverter::monoToStereo(const void* source, int sourceLength, void* dest, int destLength)
|
||||
{
|
||||
assert (destLength == sourceLength * 2);
|
||||
assert(destLength == sourceLength * 2);
|
||||
const short* input = (const short*)source;
|
||||
short* output = (short*)dest;
|
||||
short* output = (short*)dest;
|
||||
// Convert starting from the end of buffer to allow inplace conversion
|
||||
for (int sampleIndex = sourceLength/2 - 1; sampleIndex >= 0; sampleIndex--)
|
||||
for (int sampleIndex = sourceLength / 2 - 1; sampleIndex >= 0; sampleIndex--)
|
||||
{
|
||||
output[2*sampleIndex] = output[2*sampleIndex+1] = input[sampleIndex];
|
||||
output[2 * sampleIndex] = output[2 * sampleIndex + 1] = input[sampleIndex];
|
||||
}
|
||||
return sourceLength * 2;
|
||||
}
|
||||
@@ -184,13 +180,14 @@ Resampler48kTo16k::~Resampler48kTo16k()
|
||||
WebRtcSpl_ResetResample48khzTo16khz(&mContext);
|
||||
}
|
||||
|
||||
int Resampler48kTo16k::process(const void *source, int sourceLen, void *dest, int destLen)
|
||||
int Resampler48kTo16k::process(const void* source, int sourceLen, void* dest, int destLen)
|
||||
{
|
||||
const short* input = (const short*)source; int inputLen = sourceLen / 2;
|
||||
short* output = (short*)dest; //int outputCapacity = destLen / 2;
|
||||
const short* input = (const short*)source;
|
||||
int inputLen = sourceLen / 2;
|
||||
short* output = (short*)dest; // int outputCapacity = destLen / 2;
|
||||
assert(inputLen % 480 == 0);
|
||||
int frames = inputLen / 480;
|
||||
for (int i=0; i<frames; i++)
|
||||
for (int i = 0; i < frames; i++)
|
||||
WebRtcSpl_Resample48khzTo16khz(input + i * 480, output + i * 160, &mContext, mTemp);
|
||||
|
||||
return sourceLen / 3;
|
||||
@@ -207,13 +204,14 @@ Resampler16kto48k::~Resampler16kto48k()
|
||||
WebRtcSpl_ResetResample16khzTo48khz(&mContext);
|
||||
}
|
||||
|
||||
int Resampler16kto48k::process(const void *source, int sourceLen, void *dest, int destLen)
|
||||
int Resampler16kto48k::process(const void* source, int sourceLen, void* dest, int destLen)
|
||||
{
|
||||
const WebRtc_Word16* input = (const WebRtc_Word16*)source; int inputLen = sourceLen / 2;
|
||||
WebRtc_Word16* output = (WebRtc_Word16*)dest; //int outputCapacity = destLen / 2;
|
||||
const WebRtc_Word16* input = (const WebRtc_Word16*)source;
|
||||
int inputLen = sourceLen / 2;
|
||||
WebRtc_Word16* output = (WebRtc_Word16*)dest; // int outputCapacity = destLen / 2;
|
||||
assert(inputLen % 160 == 0);
|
||||
int frames = inputLen / 160;
|
||||
for (int i=0; i<frames; i++)
|
||||
for (int i = 0; i < frames; i++)
|
||||
WebRtcSpl_Resample16khzTo48khz(input + i * 160, output + i * 480, &mContext, mTemp);
|
||||
|
||||
return sourceLen * 3;
|
||||
@@ -222,18 +220,12 @@ int Resampler16kto48k::process(const void *source, int sourceLen, void *dest, in
|
||||
#endif
|
||||
|
||||
// ---------------- UniversalResampler -------------------
|
||||
UniversalResampler::UniversalResampler()
|
||||
{
|
||||
UniversalResampler::UniversalResampler() {}
|
||||
|
||||
}
|
||||
UniversalResampler::~UniversalResampler() {}
|
||||
|
||||
UniversalResampler::~UniversalResampler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
size_t UniversalResampler::resample(int sourceRate, const void *sourceBuffer, size_t sourceLength,
|
||||
size_t& sourceProcessed, int destRate, void *destBuffer, size_t destCapacity)
|
||||
size_t UniversalResampler::resample(int sourceRate, const void* sourceBuffer, size_t sourceLength,
|
||||
size_t& sourceProcessed, int destRate, void* destBuffer, size_t destCapacity)
|
||||
{
|
||||
assert(destBuffer && sourceBuffer);
|
||||
size_t result;
|
||||
@@ -252,10 +244,7 @@ size_t UniversalResampler::resample(int sourceRate, const void *sourceBuffer, si
|
||||
return result;
|
||||
}
|
||||
|
||||
void UniversalResampler::preload()
|
||||
{
|
||||
|
||||
}
|
||||
void UniversalResampler::preload() {}
|
||||
|
||||
size_t UniversalResampler::getDestLength(int sourceRate, int destRate, size_t sourceLength)
|
||||
{
|
||||
@@ -277,7 +266,7 @@ PResampler UniversalResampler::findResampler(int sourceRate, int destRate)
|
||||
{
|
||||
assert(sourceRate != destRate);
|
||||
ResamplerMap::iterator resamplerIter = mResamplerMap.find(RatePair(sourceRate, destRate));
|
||||
PResampler r;
|
||||
PResampler r;
|
||||
if (resamplerIter == mResamplerMap.end())
|
||||
{
|
||||
r = std::make_shared<Resampler>();
|
||||
@@ -289,4 +278,4 @@ PResampler UniversalResampler::findResampler(int sourceRate, int destRate)
|
||||
return r;
|
||||
}
|
||||
|
||||
} // end of namespace
|
||||
} // namespace Audio
|
||||
|
||||
Reference in New Issue
Block a user