Remove the different block lengths in ns_core
This CL has bit-exact output. What it does: * Remove the blockLen10Ms, as it is hardcoded to be equal to blockLen. * This makes outLen to be always zero, so it can be removed too. * It also avoids the need to have an outBuf, because it is not used, so it is also removed * Replaced blockLen10Ms by blockLen everywhere, since they were hardcoded to be equal. * We don't need to check if outLen is zero, because it always is, so it was removed. * Of course, the outBuf needs no initial set or copying around, because it is not used. BUG=webrtc:3811 R=bjornv@webrtc.org, kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/30539004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7297 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -173,7 +173,8 @@ void NoiseSuppressionImpl::DestroyHandle(void* handle) const {
|
|||||||
int NoiseSuppressionImpl::InitializeHandle(void* handle) const {
|
int NoiseSuppressionImpl::InitializeHandle(void* handle) const {
|
||||||
#if defined(WEBRTC_NS_FLOAT)
|
#if defined(WEBRTC_NS_FLOAT)
|
||||||
return WebRtcNs_Init(static_cast<Handle*>(handle),
|
return WebRtcNs_Init(static_cast<Handle*>(handle),
|
||||||
apm_->proc_sample_rate_hz());
|
apm_->proc_sample_rate_hz(),
|
||||||
|
AudioProcessing::kChunkSizeMs);
|
||||||
#elif defined(WEBRTC_NS_FIXED)
|
#elif defined(WEBRTC_NS_FIXED)
|
||||||
return WebRtcNsx_Init(static_cast<Handle*>(handle),
|
return WebRtcNsx_Init(static_cast<Handle*>(handle),
|
||||||
apm_->proc_sample_rate_hz());
|
apm_->proc_sample_rate_hz());
|
||||||
|
@ -55,6 +55,7 @@ int WebRtcNs_Free(NsHandle* NS_inst);
|
|||||||
* Input:
|
* Input:
|
||||||
* - NS_inst : Instance that should be initialized
|
* - NS_inst : Instance that should be initialized
|
||||||
* - fs : sampling frequency
|
* - fs : sampling frequency
|
||||||
|
* - blockLenMs : block length in ms
|
||||||
*
|
*
|
||||||
* Output:
|
* Output:
|
||||||
* - NS_inst : Initialized instance
|
* - NS_inst : Initialized instance
|
||||||
@ -62,7 +63,7 @@ int WebRtcNs_Free(NsHandle* NS_inst);
|
|||||||
* Return value : 0 - Ok
|
* Return value : 0 - Ok
|
||||||
* -1 - Error
|
* -1 - Error
|
||||||
*/
|
*/
|
||||||
int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs);
|
int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs, int blockLenMs);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This changes the aggressiveness of the noise suppression method.
|
* This changes the aggressiveness of the noise suppression method.
|
||||||
|
@ -34,8 +34,8 @@ int WebRtcNs_Free(NsHandle* NS_inst) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs) {
|
int WebRtcNs_Init(NsHandle* NS_inst, uint32_t fs, int blockLenMs) {
|
||||||
return WebRtcNs_InitCore((NSinst_t*) NS_inst, fs);
|
return WebRtcNs_InitCore((NSinst_t*) NS_inst, fs, blockLenMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) {
|
int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) {
|
||||||
|
@ -71,7 +71,7 @@ void WebRtcNs_set_feature_extraction_parameters(NSinst_t* inst) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize state
|
// Initialize state
|
||||||
int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs) {
|
int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs, int blockLenMs) {
|
||||||
int i;
|
int i;
|
||||||
// We only support 10ms frames
|
// We only support 10ms frames
|
||||||
|
|
||||||
@ -89,27 +89,22 @@ int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs) {
|
|||||||
inst->windShift = 0;
|
inst->windShift = 0;
|
||||||
if (fs == 8000) {
|
if (fs == 8000) {
|
||||||
// We only support 10ms frames
|
// We only support 10ms frames
|
||||||
inst->blockLen = 80;
|
inst->blockLen = 8;
|
||||||
inst->blockLen10ms = 80;
|
|
||||||
inst->anaLen = 128;
|
inst->anaLen = 128;
|
||||||
inst->window = kBlocks80w128;
|
inst->window = kBlocks80w128;
|
||||||
inst->outLen = 0;
|
|
||||||
} else if (fs == 16000) {
|
} else if (fs == 16000) {
|
||||||
// We only support 10ms frames
|
// We only support 10ms frames
|
||||||
inst->blockLen = 160;
|
inst->blockLen = 16;
|
||||||
inst->blockLen10ms = 160;
|
|
||||||
inst->anaLen = 256;
|
inst->anaLen = 256;
|
||||||
inst->window = kBlocks160w256;
|
inst->window = kBlocks160w256;
|
||||||
inst->outLen = 0;
|
|
||||||
} else if (fs == 32000) {
|
} else if (fs == 32000) {
|
||||||
// We only support 10ms frames
|
// We only support 10ms frames
|
||||||
inst->blockLen = 160;
|
inst->blockLen = 16;
|
||||||
inst->blockLen10ms = 160;
|
|
||||||
inst->anaLen = 256;
|
inst->anaLen = 256;
|
||||||
inst->window = kBlocks160w256;
|
inst->window = kBlocks160w256;
|
||||||
inst->outLen = 0;
|
|
||||||
}
|
}
|
||||||
inst->magnLen = inst->anaLen / 2 + 1; // Number of frequency bins
|
inst->magnLen = inst->anaLen / 2 + 1; // Number of frequency bins
|
||||||
|
inst->blockLen *= blockLenMs;
|
||||||
|
|
||||||
// Initialize fft work arrays.
|
// Initialize fft work arrays.
|
||||||
inst->ip[0] = 0; // Setting this triggers initialization.
|
inst->ip[0] = 0; // Setting this triggers initialization.
|
||||||
@ -789,14 +784,12 @@ int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
|
|||||||
|
|
||||||
// update analysis buffer for L band
|
// update analysis buffer for L band
|
||||||
memcpy(inst->analyzeBuf,
|
memcpy(inst->analyzeBuf,
|
||||||
inst->analyzeBuf + inst->blockLen10ms,
|
inst->analyzeBuf + inst->blockLen,
|
||||||
sizeof(float) * (inst->anaLen - inst->blockLen10ms));
|
sizeof(float) * (inst->anaLen - inst->blockLen));
|
||||||
memcpy(inst->analyzeBuf + inst->anaLen - inst->blockLen10ms,
|
memcpy(inst->analyzeBuf + inst->anaLen - inst->blockLen,
|
||||||
speechFrame,
|
speechFrame,
|
||||||
sizeof(float) * inst->blockLen10ms);
|
sizeof(float) * inst->blockLen);
|
||||||
|
|
||||||
// check if processing needed
|
|
||||||
if (inst->outLen == 0) {
|
|
||||||
// windowing
|
// windowing
|
||||||
energy = 0.0;
|
energy = 0.0;
|
||||||
for (i = 0; i < inst->anaLen; i++) {
|
for (i = 0; i < inst->anaLen; i++) {
|
||||||
@ -1032,7 +1025,6 @@ int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
|
|||||||
for (i = 0; i < inst->magnLen; i++) {
|
for (i = 0; i < inst->magnLen; i++) {
|
||||||
inst->noisePrev[i] = noise[i];
|
inst->noisePrev[i] = noise[i];
|
||||||
}
|
}
|
||||||
} // end of if inst->outLen == 0
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1081,24 +1073,22 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
|
|||||||
|
|
||||||
// update analysis buffer for L band
|
// update analysis buffer for L band
|
||||||
memcpy(inst->dataBuf,
|
memcpy(inst->dataBuf,
|
||||||
inst->dataBuf + inst->blockLen10ms,
|
inst->dataBuf + inst->blockLen,
|
||||||
sizeof(float) * (inst->anaLen - inst->blockLen10ms));
|
sizeof(float) * (inst->anaLen - inst->blockLen));
|
||||||
memcpy(inst->dataBuf + inst->anaLen - inst->blockLen10ms,
|
memcpy(inst->dataBuf + inst->anaLen - inst->blockLen,
|
||||||
speechFrame,
|
speechFrame,
|
||||||
sizeof(float) * inst->blockLen10ms);
|
sizeof(float) * inst->blockLen);
|
||||||
|
|
||||||
if (flagHB == 1) {
|
if (flagHB == 1) {
|
||||||
// update analysis buffer for H band
|
// update analysis buffer for H band
|
||||||
memcpy(inst->dataBufHB,
|
memcpy(inst->dataBufHB,
|
||||||
inst->dataBufHB + inst->blockLen10ms,
|
inst->dataBufHB + inst->blockLen,
|
||||||
sizeof(float) * (inst->anaLen - inst->blockLen10ms));
|
sizeof(float) * (inst->anaLen - inst->blockLen));
|
||||||
memcpy(inst->dataBufHB + inst->anaLen - inst->blockLen10ms,
|
memcpy(inst->dataBufHB + inst->anaLen - inst->blockLen,
|
||||||
speechFrameHB,
|
speechFrameHB,
|
||||||
sizeof(float) * inst->blockLen10ms);
|
sizeof(float) * inst->blockLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if processing needed
|
|
||||||
if (inst->outLen == 0) {
|
|
||||||
// windowing
|
// windowing
|
||||||
energy1 = 0.0;
|
energy1 = 0.0;
|
||||||
for (i = 0; i < inst->anaLen; i++) {
|
for (i = 0; i < inst->anaLen; i++) {
|
||||||
@ -1119,20 +1109,13 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
|
|||||||
0,
|
0,
|
||||||
sizeof(float) * inst->blockLen);
|
sizeof(float) * inst->blockLen);
|
||||||
|
|
||||||
// out buffer
|
for (i = 0; i < inst->blockLen; ++i)
|
||||||
inst->outLen = inst->blockLen - inst->blockLen10ms;
|
|
||||||
if (inst->blockLen > inst->blockLen10ms) {
|
|
||||||
for (i = 0; i < inst->outLen; i++) {
|
|
||||||
inst->outBuf[i] = fout[i + inst->blockLen10ms];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (i = 0; i < inst->blockLen10ms; ++i)
|
|
||||||
outFrame[i] = WEBRTC_SPL_SAT(
|
outFrame[i] = WEBRTC_SPL_SAT(
|
||||||
WEBRTC_SPL_WORD16_MAX, fout[i], WEBRTC_SPL_WORD16_MIN);
|
WEBRTC_SPL_WORD16_MAX, fout[i], WEBRTC_SPL_WORD16_MIN);
|
||||||
|
|
||||||
// for time-domain gain of HB
|
// for time-domain gain of HB
|
||||||
if (flagHB == 1)
|
if (flagHB == 1)
|
||||||
for (i = 0; i < inst->blockLen10ms; ++i)
|
for (i = 0; i < inst->blockLen; ++i)
|
||||||
outFrameHB[i] = WEBRTC_SPL_SAT(
|
outFrameHB[i] = WEBRTC_SPL_SAT(
|
||||||
WEBRTC_SPL_WORD16_MAX, inst->dataBufHB[i], WEBRTC_SPL_WORD16_MIN);
|
WEBRTC_SPL_WORD16_MAX, inst->dataBufHB[i], WEBRTC_SPL_WORD16_MIN);
|
||||||
|
|
||||||
@ -1281,28 +1264,7 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
|
|||||||
0,
|
0,
|
||||||
sizeof(float) * inst->blockLen);
|
sizeof(float) * inst->blockLen);
|
||||||
|
|
||||||
// out buffer
|
for (i = 0; i < inst->blockLen; ++i)
|
||||||
inst->outLen = inst->blockLen - inst->blockLen10ms;
|
|
||||||
if (inst->blockLen > inst->blockLen10ms) {
|
|
||||||
for (i = 0; i < inst->outLen; i++) {
|
|
||||||
inst->outBuf[i] = fout[i + inst->blockLen10ms];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // end of if out.len==0
|
|
||||||
else {
|
|
||||||
for (i = 0; i < inst->blockLen10ms; i++) {
|
|
||||||
fout[i] = inst->outBuf[i];
|
|
||||||
}
|
|
||||||
memcpy(inst->outBuf,
|
|
||||||
inst->outBuf + inst->blockLen10ms,
|
|
||||||
sizeof(float) * (inst->outLen - inst->blockLen10ms));
|
|
||||||
memset(inst->outBuf + inst->outLen - inst->blockLen10ms,
|
|
||||||
0,
|
|
||||||
sizeof(float) * inst->blockLen10ms);
|
|
||||||
inst->outLen -= inst->blockLen10ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < inst->blockLen10ms; ++i)
|
|
||||||
outFrame[i] =
|
outFrame[i] =
|
||||||
WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, fout[i], WEBRTC_SPL_WORD16_MIN);
|
WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, fout[i], WEBRTC_SPL_WORD16_MIN);
|
||||||
|
|
||||||
@ -1343,7 +1305,7 @@ int WebRtcNs_ProcessCore(NSinst_t* inst,
|
|||||||
gainTimeDomainHB = 1.0;
|
gainTimeDomainHB = 1.0;
|
||||||
}
|
}
|
||||||
// apply gain
|
// apply gain
|
||||||
for (i = 0; i < inst->blockLen10ms; i++) {
|
for (i = 0; i < inst->blockLen; i++) {
|
||||||
float o = gainTimeDomainHB * inst->dataBufHB[i];
|
float o = gainTimeDomainHB * inst->dataBufHB[i];
|
||||||
outFrameHB[i] =
|
outFrameHB[i] =
|
||||||
WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, o, WEBRTC_SPL_WORD16_MIN);
|
WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, o, WEBRTC_SPL_WORD16_MIN);
|
||||||
|
@ -52,9 +52,7 @@ typedef struct NSParaExtract_t_ {
|
|||||||
typedef struct NSinst_t_ {
|
typedef struct NSinst_t_ {
|
||||||
uint32_t fs;
|
uint32_t fs;
|
||||||
int blockLen;
|
int blockLen;
|
||||||
int blockLen10ms;
|
|
||||||
int windShift;
|
int windShift;
|
||||||
int outLen;
|
|
||||||
int anaLen;
|
int anaLen;
|
||||||
int magnLen;
|
int magnLen;
|
||||||
int aggrMode;
|
int aggrMode;
|
||||||
@ -122,6 +120,7 @@ extern "C" {
|
|||||||
* Input:
|
* Input:
|
||||||
* - inst : Instance that should be initialized
|
* - inst : Instance that should be initialized
|
||||||
* - fs : Sampling frequency
|
* - fs : Sampling frequency
|
||||||
|
* - blockLenMs : Block length in ms
|
||||||
*
|
*
|
||||||
* Output:
|
* Output:
|
||||||
* - inst : Initialized instance
|
* - inst : Initialized instance
|
||||||
@ -129,7 +128,7 @@ extern "C" {
|
|||||||
* Return value : 0 - Ok
|
* Return value : 0 - Ok
|
||||||
* -1 - Error
|
* -1 - Error
|
||||||
*/
|
*/
|
||||||
int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs);
|
int WebRtcNs_InitCore(NSinst_t* inst, uint32_t fs, int blockLenMs);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* WebRtcNs_set_policy_core(...)
|
* WebRtcNs_set_policy_core(...)
|
||||||
|
Reference in New Issue
Block a user