Support 48kHz in Noise Suppression

Doing the same for the 16-24kHz band than was done in the 8-16kHz.
Results look and sound as nice.

BUG=webrtc:3146
R=andrew@webrtc.org, bjornv@webrtc.org, kwiberg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/29139004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7865 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
aluebs@webrtc.org
2014-12-10 19:30:57 +00:00
parent d8ca723de7
commit c5ebbd98f5
17 changed files with 240 additions and 219 deletions

View File

@ -14,6 +14,7 @@
#define BLOCKL_MAX 160 // max processing block length: 160
#define ANAL_BLOCKL_MAX 256 // max analysis block length: 256
#define HALF_ANAL_BLOCKL 129 // half max analysis block length + 1
#define NUM_HIGH_BANDS_MAX 2 // max number of high bands: 2
#define QUANTILE (float)0.25

View File

@ -89,11 +89,8 @@ int WebRtcNs_set_policy(NsHandle* NS_inst, int mode);
*
* Output:
* - NS_inst : Updated NS instance
*
* Return value : 0 - OK
* -1 - Error
*/
int WebRtcNs_Analyze(NsHandle* NS_inst, float* spframe);
void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe);
/*
* This functions does Noise Suppression for the inserted speech frame. The
@ -101,23 +98,17 @@ int WebRtcNs_Analyze(NsHandle* NS_inst, float* spframe);
*
* Input
* - NS_inst : Noise suppression instance.
* - spframe : Pointer to speech frame buffer for L band
* - spframe_H : Pointer to speech frame buffer for H band
* - fs : sampling frequency
* - spframe : Pointer to speech frame buffer for each band
* - num_bands : Number of bands
*
* Output:
* - NS_inst : Updated NS instance
* - outframe : Pointer to output frame for L band
* - outframe_H : Pointer to output frame for H band
*
* Return value : 0 - OK
* -1 - Error
* - outframe : Pointer to output frame for each band
*/
int WebRtcNs_Process(NsHandle* NS_inst,
float* spframe,
float* spframe_H,
float* outframe,
float* outframe_H);
void WebRtcNs_Process(NsHandle* NS_inst,
const float* const* spframe,
int num_bands,
float* const* outframe);
/* Returns the internally used prior speech probability of the current frame.
* There is a frequency bin based one as well, with which this should not be

View File

@ -84,23 +84,17 @@ int WebRtcNsx_set_policy(NsxHandle* nsxInst, int mode);
*
* Input
* - nsxInst : NSx instance. Needs to be initiated before call.
* - speechFrame : Pointer to speech frame buffer for L band
* - speechFrameHB : Pointer to speech frame buffer for H band
* - fs : sampling frequency
* - speechFrame : Pointer to speech frame buffer for each band
* - num_bands : Number of bands
*
* Output:
* - nsxInst : Updated NSx instance
* - outFrame : Pointer to output frame for L band
* - outFrameHB : Pointer to output frame for H band
*
* Return value : 0 - OK
* -1 - Error
* - outFrame : Pointer to output frame for each band
*/
int WebRtcNsx_Process(NsxHandle* nsxInst,
short* speechFrame,
short* speechFrameHB,
short* outFrame,
short* outFrameHB);
void WebRtcNsx_Process(NsxHandle* nsxInst,
const short* const* speechFrame,
int num_bands,
short* const* outFrame);
#ifdef __cplusplus
}

View File

@ -42,14 +42,15 @@ int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) {
return WebRtcNs_set_policy_core((NSinst_t*) NS_inst, mode);
}
int WebRtcNs_Analyze(NsHandle* NS_inst, float* spframe) {
return WebRtcNs_AnalyzeCore((NSinst_t*) NS_inst, spframe);
void WebRtcNs_Analyze(NsHandle* NS_inst, const float* spframe) {
WebRtcNs_AnalyzeCore((NSinst_t*) NS_inst, spframe);
}
int WebRtcNs_Process(NsHandle* NS_inst, float* spframe, float* spframe_H,
float* outframe, float* outframe_H) {
return WebRtcNs_ProcessCore(
(NSinst_t*) NS_inst, spframe, spframe_H, outframe, outframe_H);
void WebRtcNs_Process(NsHandle* NS_inst,
const float* const* spframe,
int num_bands,
float* const* outframe) {
WebRtcNs_ProcessCore((NSinst_t*)NS_inst, spframe, num_bands, outframe);
}
float WebRtcNs_prior_speech_probability(NsHandle* handle) {

View File

@ -45,9 +45,9 @@ int WebRtcNsx_set_policy(NsxHandle* nsxInst, int mode) {
return WebRtcNsx_set_policy_core((NsxInst_t*)nsxInst, mode);
}
int WebRtcNsx_Process(NsxHandle* nsxInst, short* speechFrame,
short* speechFrameHB, short* outFrame,
short* outFrameHB) {
return WebRtcNsx_ProcessCore(
(NsxInst_t*)nsxInst, speechFrame, speechFrameHB, outFrame, outFrameHB);
void WebRtcNsx_Process(NsxHandle* nsxInst,
const short* const* speechFrame,
int num_bands,
short* const* outFrame) {
WebRtcNsx_ProcessCore((NsxInst_t*)nsxInst, speechFrame, num_bands, outFrame);
}

View File

@ -79,24 +79,18 @@ int WebRtcNs_InitCore(NSinst_t* self, uint32_t fs) {
}
// Initialization of struct.
if (fs == 8000 || fs == 16000 || fs == 32000) {
if (fs == 8000 || fs == 16000 || fs == 32000 || fs == 48000) {
self->fs = fs;
} else {
return -1;
}
self->windShift = 0;
// We only support 10ms frames.
if (fs == 8000) {
// We only support 10ms frames.
self->blockLen = 80;
self->anaLen = 128;
self->window = kBlocks80w128;
} else if (fs == 16000) {
// We only support 10ms frames.
self->blockLen = 160;
self->anaLen = 256;
self->window = kBlocks160w256;
} else if (fs == 32000) {
// We only support 10ms frames.
} else {
self->blockLen = 160;
self->anaLen = 256;
self->window = kBlocks160w256;
@ -113,7 +107,9 @@ int WebRtcNs_InitCore(NSinst_t* self, uint32_t fs) {
memset(self->syntBuf, 0, sizeof(float) * ANAL_BLOCKL_MAX);
// For HB processing.
memset(self->dataBufHB, 0, sizeof(float) * ANAL_BLOCKL_MAX);
memset(self->dataBufHB,
0,
sizeof(float) * NUM_HIGH_BANDS_MAX * ANAL_BLOCKL_MAX);
// For quantile noise estimation.
memset(self->quantile, 0, sizeof(float) * HALF_ANAL_BLOCKL);
@ -1041,7 +1037,7 @@ int WebRtcNs_set_policy_core(NSinst_t* self, int mode) {
return 0;
}
int WebRtcNs_AnalyzeCore(NSinst_t* self, float* speechFrame) {
void WebRtcNs_AnalyzeCore(NSinst_t* self, const float* speechFrame) {
int i;
const int kStartBand = 5; // Skip first frequency bins during estimation.
int updateParsFlag;
@ -1062,9 +1058,7 @@ int WebRtcNs_AnalyzeCore(NSinst_t* self, float* speechFrame) {
float parametric_num = 0.0;
// Check that initiation has been done.
if (self->initFlag != 1) {
return (-1);
}
assert(self->initFlag == 1);
updateParsFlag = self->modelUpdatePars[0];
// Update analysis buffer for L band.
@ -1081,7 +1075,7 @@ int WebRtcNs_AnalyzeCore(NSinst_t* self, float* speechFrame) {
// Depending on the duration of the inactive signal it takes a
// considerable amount of time for the system to learn what is noise and
// what is speech.
return 0;
return;
}
self->blockInd++; // Update the block index only when we process a block.
@ -1181,18 +1175,15 @@ int WebRtcNs_AnalyzeCore(NSinst_t* self, float* speechFrame) {
// Keep track of noise spectrum for next frame.
memcpy(self->noise, noise, sizeof(*noise) * self->magnLen);
memcpy(self->magnPrevAnalyze, magn, sizeof(*magn) * self->magnLen);
return 0;
}
int WebRtcNs_ProcessCore(NSinst_t* self,
float* speechFrame,
float* speechFrameHB,
float* outFrame,
float* outFrameHB) {
void WebRtcNs_ProcessCore(NSinst_t* self,
const float* const* speechFrame,
int num_bands,
float* const* outFrame) {
// Main routine for noise reduction.
int flagHB = 0;
int i;
int i, j;
float energy1, energy2, gain, factor, factor1, factor2;
float fout[BLOCKL_MAX];
@ -1211,14 +1202,16 @@ int WebRtcNs_ProcessCore(NSinst_t* self,
float sumMagnAnalyze, sumMagnProcess;
// Check that initiation has been done.
if (self->initFlag != 1) {
return (-1);
}
// Check for valid pointers based on sampling rate.
if (self->fs == 32000) {
if (speechFrameHB == NULL) {
return -1;
}
assert(self->initFlag == 1);
assert((num_bands - 1) <= NUM_HIGH_BANDS_MAX);
const float* const* speechFrameHB = NULL;
float* const* outFrameHB = NULL;
int num_high_bands = 0;
if (num_bands > 1) {
speechFrameHB = &speechFrame[1];
outFrameHB = &outFrame[1];
num_high_bands = num_bands - 1;
flagHB = 1;
// Range for averaging low band quantities for H band gain.
deltaBweHB = (int)self->magnLen / 4;
@ -1226,11 +1219,16 @@ int WebRtcNs_ProcessCore(NSinst_t* self,
}
// Update analysis buffer for L band.
UpdateBuffer(speechFrame, self->blockLen, self->anaLen, self->dataBuf);
UpdateBuffer(speechFrame[0], self->blockLen, self->anaLen, self->dataBuf);
if (flagHB == 1) {
// Update analysis buffer for H band.
UpdateBuffer(speechFrameHB, self->blockLen, self->anaLen, self->dataBufHB);
// Update analysis buffer for H bands.
for (i = 0; i < num_high_bands; ++i) {
UpdateBuffer(speechFrameHB[i],
self->blockLen,
self->anaLen,
self->dataBufHB[i]);
}
}
Windowing(self->window, self->dataBuf, self->anaLen, winData);
@ -1245,16 +1243,21 @@ int WebRtcNs_ProcessCore(NSinst_t* self,
UpdateBuffer(NULL, self->blockLen, self->anaLen, self->syntBuf);
for (i = 0; i < self->blockLen; ++i)
outFrame[i] =
outFrame[0][i] =
WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, fout[i], WEBRTC_SPL_WORD16_MIN);
// For time-domain gain of HB.
if (flagHB == 1)
for (i = 0; i < self->blockLen; ++i)
outFrameHB[i] = WEBRTC_SPL_SAT(
WEBRTC_SPL_WORD16_MAX, self->dataBufHB[i], WEBRTC_SPL_WORD16_MIN);
if (flagHB == 1) {
for (i = 0; i < num_high_bands; ++i) {
for (j = 0; j < self->blockLen; ++j) {
outFrameHB[i][j] = WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX,
self->dataBufHB[i][j],
WEBRTC_SPL_WORD16_MIN);
}
}
}
return 0;
return;
}
FFT(self, winData, self->anaLen, self->magnLen, real, imag, magn);
@ -1349,7 +1352,7 @@ int WebRtcNs_ProcessCore(NSinst_t* self,
UpdateBuffer(NULL, self->blockLen, self->anaLen, self->syntBuf);
for (i = 0; i < self->blockLen; ++i)
outFrame[i] =
outFrame[0][i] =
WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, fout[i], WEBRTC_SPL_WORD16_MIN);
// For time-domain gain of HB.
@ -1397,12 +1400,13 @@ int WebRtcNs_ProcessCore(NSinst_t* self,
gainTimeDomainHB = 1.f;
}
// Apply gain.
for (i = 0; i < self->blockLen; i++) {
float o = gainTimeDomainHB * self->dataBufHB[i];
outFrameHB[i] =
WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX, o, WEBRTC_SPL_WORD16_MIN);
for (i = 0; i < num_high_bands; ++i) {
for (j = 0; j < self->blockLen; j++) {
outFrameHB[i][j] =
WEBRTC_SPL_SAT(WEBRTC_SPL_WORD16_MAX,
gainTimeDomainHB * self->dataBufHB[i][j],
WEBRTC_SPL_WORD16_MIN);
}
}
} // End of H band gain computation.
return 0;
}

View File

@ -108,7 +108,8 @@ typedef struct NSinst_t_ {
int histSpecDiff[HIST_PAR_EST];
// Quantities for high band estimate.
float speechProb[HALF_ANAL_BLOCKL]; // Final speech/noise prob: prior + LRT.
float dataBufHB[ANAL_BLOCKL_MAX]; // Buffering data for HB.
// Buffering data for HB.
float dataBufHB[NUM_HIGH_BANDS_MAX][ANAL_BLOCKL_MAX];
} NSinst_t;
@ -161,11 +162,8 @@ int WebRtcNs_set_policy_core(NSinst_t* self, int mode);
*
* Output:
* - self : Updated instance
*
* Return value : 0 - OK
* -1 - Error
*/
int WebRtcNs_AnalyzeCore(NSinst_t* self, float* speechFrame);
void WebRtcNs_AnalyzeCore(NSinst_t* self, const float* speechFrame);
/****************************************************************************
* WebRtcNs_ProcessCore
@ -174,22 +172,17 @@ int WebRtcNs_AnalyzeCore(NSinst_t* self, float* speechFrame);
*
* Input:
* - self : Instance that should be initialized
* - inFrameLow : Input speech frame for lower band
* - inFrameHigh : Input speech frame for higher band
* - inFrame : Input speech frame for each band
* - num_bands : Number of bands
*
* Output:
* - self : Updated instance
* - outFrameLow : Output speech frame for lower band
* - outFrameHigh : Output speech frame for higher band
*
* Return value : 0 - OK
* -1 - Error
* - outFrame : Output speech frame for each band
*/
int WebRtcNs_ProcessCore(NSinst_t* self,
float* inFrameLow,
float* inFrameHigh,
float* outFrameLow,
float* outFrameHigh);
void WebRtcNs_ProcessCore(NSinst_t* self,
const float* const* inFrame,
int num_bands,
float* const* outFrame);
#ifdef __cplusplus
}

View File

@ -637,7 +637,7 @@ int32_t WebRtcNsx_InitCore(NsxInst_t* inst, uint32_t fs) {
//
// Initialization of struct
if (fs == 8000 || fs == 16000 || fs == 32000) {
if (fs == 8000 || fs == 16000 || fs == 32000 || fs == 48000) {
inst->fs = fs;
} else {
return -1;
@ -651,15 +651,7 @@ int32_t WebRtcNsx_InitCore(NsxInst_t* inst, uint32_t fs) {
inst->thresholdLogLrt = 131072; //default threshold for LRT feature
inst->maxLrt = 0x0040000;
inst->minLrt = 52429;
} else if (fs == 16000) {
inst->blockLen10ms = 160;
inst->anaLen = 256;
inst->stages = 8;
inst->window = kBlocks160w256x;
inst->thresholdLogLrt = 212644; //default threshold for LRT feature
inst->maxLrt = 0x0080000;
inst->minLrt = 104858;
} else if (fs == 32000) {
} else {
inst->blockLen10ms = 160;
inst->anaLen = 256;
inst->stages = 8;
@ -683,7 +675,8 @@ int32_t WebRtcNsx_InitCore(NsxInst_t* inst, uint32_t fs) {
WebRtcSpl_ZerosArrayW16(inst->synthesisBuffer, ANAL_BLOCKL_MAX);
// for HB processing
WebRtcSpl_ZerosArrayW16(inst->dataBufHBFX, ANAL_BLOCKL_MAX);
WebRtcSpl_ZerosArrayW16(inst->dataBufHBFX[0],
NUM_HIGH_BANDS_MAX * ANAL_BLOCKL_MAX);
// for quantile noise estimation
WebRtcSpl_ZerosArrayW16(inst->noiseEstQuantile, HALF_ANAL_BLOCKL);
for (i = 0; i < SIMULT * HALF_ANAL_BLOCKL; i++) {
@ -1502,8 +1495,10 @@ void WebRtcNsx_DataSynthesis(NsxInst_t* inst, short* outFrame) {
WebRtcNsx_SynthesisUpdate(inst, outFrame, gainFactor);
}
int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFrameHB,
short* outFrame, short* outFrameHB) {
void WebRtcNsx_ProcessCore(NsxInst_t* inst,
const short* const* speechFrame,
int num_bands,
short* const* outFrame) {
// main routine for noise suppression
uint32_t tmpU32no1, tmpU32no2, tmpU32no3;
@ -1535,7 +1530,7 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
int16_t avgProbSpeechHB, gainModHB, avgFilterGainHB, gainTimeDomainHB;
int16_t pink_noise_exp_avg = 0;
int i;
int i, j;
int nShifts, postShifts;
int norm32no1, norm32no2;
int flag, sign;
@ -1553,37 +1548,46 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
#ifdef NS_FILEDEBUG
if (fwrite(spframe, sizeof(short),
inst->blockLen10ms, inst->infile) != inst->blockLen10ms) {
return -1;
assert(false);
}
#endif
// Check that initialization has been done
if (inst->initFlag != 1) {
return -1;
}
// Check for valid pointers based on sampling rate
if ((inst->fs == 32000) && (speechFrameHB == NULL)) {
return -1;
assert(inst->initFlag == 1);
assert((num_bands - 1) <= NUM_HIGH_BANDS_MAX);
const short* const* speechFrameHB = NULL;
short* const* outFrameHB = NULL;
int num_high_bands = 0;
if (num_bands > 1) {
speechFrameHB = &speechFrame[1];
outFrameHB = &outFrame[1];
num_high_bands = num_bands - 1;
}
// Store speechFrame and transform to frequency domain
WebRtcNsx_DataAnalysis(inst, speechFrame, magnU16);
WebRtcNsx_DataAnalysis(inst, (short*)speechFrame[0], magnU16);
if (inst->zeroInputSignal) {
WebRtcNsx_DataSynthesis(inst, outFrame);
WebRtcNsx_DataSynthesis(inst, outFrame[0]);
if (inst->fs == 32000) {
if (num_bands > 1) {
// update analysis buffer for H band
// append new data to buffer FX
WEBRTC_SPL_MEMCPY_W16(inst->dataBufHBFX, inst->dataBufHBFX + inst->blockLen10ms,
inst->anaLen - inst->blockLen10ms);
WEBRTC_SPL_MEMCPY_W16(inst->dataBufHBFX + inst->anaLen - inst->blockLen10ms,
speechFrameHB, inst->blockLen10ms);
for (i = 0; i < inst->blockLen10ms; i++) {
outFrameHB[i] = inst->dataBufHBFX[i]; // Q0
for (i = 0; i < num_high_bands; ++i) {
WEBRTC_SPL_MEMCPY_W16(inst->dataBufHBFX[i],
inst->dataBufHBFX[i] + inst->blockLen10ms,
inst->anaLen - inst->blockLen10ms);
WEBRTC_SPL_MEMCPY_W16(
inst->dataBufHBFX[i] + inst->anaLen - inst->blockLen10ms,
speechFrameHB[i],
inst->blockLen10ms);
for (j = 0; j < inst->blockLen10ms; j++) {
outFrameHB[i][j] = inst->dataBufHBFX[i][j]; // Q0
}
}
} // end of H band gain computation
return 0;
return;
}
// Update block index when we have something to process
@ -2022,21 +2026,28 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
}
}
WebRtcNsx_DataSynthesis(inst, outFrame);
WebRtcNsx_DataSynthesis(inst, outFrame[0]);
#ifdef NS_FILEDEBUG
if (fwrite(outframe, sizeof(short),
inst->blockLen10ms, inst->outfile) != inst->blockLen10ms) {
return -1;
assert(false);
}
#endif
//for H band:
// only update data buffer, then apply time-domain gain is applied derived from L band
if (inst->fs == 32000) {
if (num_bands > 1) {
// update analysis buffer for H band
// append new data to buffer FX
WEBRTC_SPL_MEMCPY_W16(inst->dataBufHBFX, inst->dataBufHBFX + inst->blockLen10ms, inst->anaLen - inst->blockLen10ms);
WEBRTC_SPL_MEMCPY_W16(inst->dataBufHBFX + inst->anaLen - inst->blockLen10ms, speechFrameHB, inst->blockLen10ms);
for (i = 0; i < num_high_bands; ++i) {
WEBRTC_SPL_MEMCPY_W16(inst->dataBufHBFX[i],
inst->dataBufHBFX[i] + inst->blockLen10ms,
inst->anaLen - inst->blockLen10ms);
WEBRTC_SPL_MEMCPY_W16(
inst->dataBufHBFX[i] + inst->anaLen - inst->blockLen10ms,
speechFrameHB[i],
inst->blockLen10ms);
}
// range for averaging low band quantities for H band gain
gainTimeDomainHB = 16384; // 16384 = Q14(1.0)
@ -2094,11 +2105,13 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
//apply gain
for (i = 0; i < inst->blockLen10ms; i++) {
outFrameHB[i]
= (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(gainTimeDomainHB, inst->dataBufHBFX[i], 14); // Q0
for (i = 0; i < num_high_bands; ++i) {
for (j = 0; j < inst->blockLen10ms; j++) {
outFrameHB[i][j] = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(
gainTimeDomainHB,
inst->dataBufHBFX[i][j],
14); // Q0
}
}
} // end of H band gain computation
return 0;
}

View File

@ -93,7 +93,7 @@ typedef struct NsxInst_t_ {
int16_t histSpecDiff[HIST_PAR_EST];
// Quantities for high band estimate.
int16_t dataBufHBFX[ANAL_BLOCKL_MAX]; // Q0
int16_t dataBufHBFX[NUM_HIGH_BANDS_MAX][ANAL_BLOCKL_MAX];
int qNoise;
int prevQNoise;
@ -155,25 +155,20 @@ int WebRtcNsx_set_policy_core(NsxInst_t* inst, int mode);
*
* Input:
* - inst : Instance that should be initialized
* - inFrameLow : Input speech frame for lower band
* - inFrameHigh : Input speech frame for higher band
* - inFrame : Input speech frame for each band
* - num_bands : Number of bands
*
* Output:
* - inst : Updated instance
* - outFrameLow : Output speech frame for lower band
* - outFrameHigh : Output speech frame for higher band
*
* Return value : 0 - OK
* -1 - Error
* - outFrame : Output speech frame for each band
*/
int WebRtcNsx_ProcessCore(NsxInst_t* inst,
short* inFrameLow,
short* inFrameHigh,
short* outFrameLow,
short* outFrameHigh);
void WebRtcNsx_ProcessCore(NsxInst_t* inst,
const short* const* inFrame,
int num_bands,
short* const* outFrame);
/****************************************************************************
* Some function pointers, for internal functions shared by ARM NEON and
* Some function pointers, for internal functions shared by ARM NEON and
* generic C code.
*/
// Noise Estimation.

View File

@ -13,6 +13,7 @@
#define ANAL_BLOCKL_MAX 256 /* Max analysis block length */
#define HALF_ANAL_BLOCKL 129 /* Half max analysis block length + 1 */
#define NUM_HIGH_BANDS_MAX 2 /* Max number of high bands */
#define SIMULT 3
#define END_STARTUP_LONG 200
#define END_STARTUP_SHORT 50