From 12cd4437520588623d3e9840c0fd2c2ace9aae6b Mon Sep 17 00:00:00 2001 From: "kwiberg@webrtc.org" Date: Tue, 10 Jun 2014 11:13:09 +0000 Subject: [PATCH] Noise suppression: Change signature to work on floats instead of ints Internally, it already worked on floats. This patch just changes the signature of a bunch of functions so that floats can be passed directly from the new and improved AudioBuffer without converting the data to int and back again first. (The reference data to the ApmTest.Process test had to be modified slightly; this is because the noise suppressor comes immediately after the echo canceller, which also works on floats. If I truncate to integers between the two steps, ApmTest.Process doesn't complain, but of course that's exactly the sort of thing the float conversion is supposed to let us avoid...) BUG= R=aluebs@webrtc.org, bjornv@webrtc.org, tina.legrand@webrtc.org Review URL: https://webrtc-codereview.appspot.com/13519004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6385 4adac7df-926f-26a2-2b94-8c16560cd09d --- data/audio_processing/output_data_float.pb | Bin 1386 -> 1386 bytes .../noise_suppression_impl.cc | 8 +- .../ns/include/noise_suppression.h | 8 +- .../audio_processing/ns/noise_suppression.c | 4 +- webrtc/modules/audio_processing/ns/ns_core.c | 78 +++++------------- webrtc/modules/audio_processing/ns/ns_core.h | 8 +- 6 files changed, 36 insertions(+), 70 deletions(-) diff --git a/data/audio_processing/output_data_float.pb b/data/audio_processing/output_data_float.pb index ee9b6ccceb84477a3d42780fb3e0ba8042ccfe2c..ffc12d6b00a5543e99ad883804336c0071980309 100644 GIT binary patch delta 347 zcmaFG^@?kP2*){IhmTAiYnUhNvY1ZhW#*k2XC(EK@v0qHCI_PcqXeTuL#;t4qs2Qu zhnGwqFDI@FlwNZ0oE=vdO!gO}K^LRN3Vx9EC!n-U;m-?pT)m7yc_s-ag#&g59gG%7 z1woc<1XJJFY~SG|-B6MvLjf zAo)v^OPD-FYbt^AKs%VgE(F>Ebi#zm7n!O>H4DH7LnI(hf5|ub2(vFUTg}_a8<`WN z59Yjr>P5Kkfq=sYCXd~dby!NJ*2X;pIgJVIe2CLd2su0lNz1W%NOyz-wI{-)Ax@hw P43a+#l4s%h|HKXe5o~Hi delta 352 zcmaFG^@?kP2**WUhmTAi+nFcpvY1ZhW#*k2XC(Ff+ci6`Ob$i?MhQlRhFXJ8MvISp z4lkKJUQb*VC>`;zfjH2El_k(Bzft9D!oP&Ggs+88Y^3xSNdKUt8;L;6?b6+5m(m^9Fec1DXi!XWwc zlS`O9L@!LZ47P&_>_VU&KqpL`e37YIO61gakiifMh|{0*IXq|bI5_zvvj?+y$Lq-( znG>Yn+(handle(i)); #if defined(WEBRTC_NS_FLOAT) err = WebRtcNs_Process(static_cast(handle(i)), - audio->low_pass_split_data(i), - audio->high_pass_split_data(i), - audio->low_pass_split_data(i), - audio->high_pass_split_data(i)); + audio->low_pass_split_data_f(i), + audio->high_pass_split_data_f(i), + audio->low_pass_split_data_f(i), + audio->high_pass_split_data_f(i)); #elif defined(WEBRTC_NS_FIXED) err = WebRtcNsx_Process(static_cast(handle(i)), audio->low_pass_split_data(i), diff --git a/webrtc/modules/audio_processing/ns/include/noise_suppression.h b/webrtc/modules/audio_processing/ns/include/noise_suppression.h index 32b1803808..3cf889e2d0 100644 --- a/webrtc/modules/audio_processing/ns/include/noise_suppression.h +++ b/webrtc/modules/audio_processing/ns/include/noise_suppression.h @@ -99,10 +99,10 @@ int WebRtcNs_set_policy(NsHandle* NS_inst, int mode); * -1 - Error */ int WebRtcNs_Process(NsHandle* NS_inst, - short* spframe, - short* spframe_H, - short* outframe, - short* outframe_H); + float* spframe, + float* spframe_H, + float* outframe, + float* outframe_H); /* 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 diff --git a/webrtc/modules/audio_processing/ns/noise_suppression.c b/webrtc/modules/audio_processing/ns/noise_suppression.c index 848467f080..075ab88c1c 100644 --- a/webrtc/modules/audio_processing/ns/noise_suppression.c +++ b/webrtc/modules/audio_processing/ns/noise_suppression.c @@ -43,8 +43,8 @@ int WebRtcNs_set_policy(NsHandle* NS_inst, int mode) { } -int WebRtcNs_Process(NsHandle* NS_inst, short* spframe, short* spframe_H, - short* outframe, short* outframe_H) { +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); } diff --git a/webrtc/modules/audio_processing/ns/ns_core.c b/webrtc/modules/audio_processing/ns/ns_core.c index 124a66d8df..ec267ae0f6 100644 --- a/webrtc/modules/audio_processing/ns/ns_core.c +++ b/webrtc/modules/audio_processing/ns/ns_core.c @@ -715,10 +715,10 @@ void WebRtcNs_SpeechNoiseProb(NSinst_t* inst, float* probSpeechFinal, float* snr } int WebRtcNs_ProcessCore(NSinst_t* inst, - short* speechFrame, - short* speechFrameHB, - short* outFrame, - short* outFrameHB) { + float* speechFrame, + float* speechFrameHB, + float* outFrame, + float* outFrameHB) { // main routine for noise reduction int flagHB = 0; @@ -731,8 +731,8 @@ int WebRtcNs_ProcessCore(NSinst_t* inst, float snrPrior, currentEstimateStsa; float tmpFloat1, tmpFloat2, tmpFloat3, probSpeech, probNonSpeech; float gammaNoiseTmp, gammaNoiseOld; - float noiseUpdateTmp, fTmp, dTmp; - float fin[BLOCKL_MAX], fout[BLOCKL_MAX]; + float noiseUpdateTmp, fTmp; + float fout[BLOCKL_MAX]; float winData[ANAL_BLOCKL_MAX]; float magn[HALF_ANAL_BLOCKL], noise[HALF_ANAL_BLOCKL]; float theFilter[HALF_ANAL_BLOCKL], theFilterTmp[HALF_ANAL_BLOCKL]; @@ -775,26 +775,17 @@ int WebRtcNs_ProcessCore(NSinst_t* inst, updateParsFlag = inst->modelUpdatePars[0]; // - //for LB do all processing - // convert to float - for (i = 0; i < inst->blockLen10ms; i++) { - fin[i] = (float)speechFrame[i]; - } // update analysis buffer for L band memcpy(inst->dataBuf, inst->dataBuf + inst->blockLen10ms, sizeof(float) * (inst->anaLen - inst->blockLen10ms)); - memcpy(inst->dataBuf + inst->anaLen - inst->blockLen10ms, fin, + memcpy(inst->dataBuf + inst->anaLen - inst->blockLen10ms, speechFrame, sizeof(float) * inst->blockLen10ms); if (flagHB == 1) { - // convert to float - for (i = 0; i < inst->blockLen10ms; i++) { - fin[i] = (float)speechFrameHB[i]; - } // update analysis buffer for H band memcpy(inst->dataBufHB, inst->dataBufHB + inst->blockLen10ms, sizeof(float) * (inst->anaLen - inst->blockLen10ms)); - memcpy(inst->dataBufHB + inst->anaLen - inst->blockLen10ms, fin, + memcpy(inst->dataBufHB + inst->anaLen - inst->blockLen10ms, speechFrameHB, sizeof(float) * inst->blockLen10ms); } @@ -833,30 +824,16 @@ int WebRtcNs_ProcessCore(NSinst_t* inst, inst->outBuf[i] = fout[i + inst->blockLen10ms]; } } - // convert to short - for (i = 0; i < inst->blockLen10ms; i++) { - dTmp = fout[i]; - if (dTmp < WEBRTC_SPL_WORD16_MIN) { - dTmp = WEBRTC_SPL_WORD16_MIN; - } else if (dTmp > WEBRTC_SPL_WORD16_MAX) { - dTmp = WEBRTC_SPL_WORD16_MAX; - } - outFrame[i] = (short)dTmp; - } + for (i = 0; i < inst->blockLen10ms; ++i) + outFrame[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 < inst->blockLen10ms; i++) { - dTmp = inst->dataBufHB[i]; - if (dTmp < WEBRTC_SPL_WORD16_MIN) { - dTmp = WEBRTC_SPL_WORD16_MIN; - } else if (dTmp > WEBRTC_SPL_WORD16_MAX) { - dTmp = WEBRTC_SPL_WORD16_MAX; - } - outFrameHB[i] = (short)dTmp; - } - } // end of H band gain computation - // + if (flagHB == 1) + for (i = 0; i < inst->blockLen10ms; ++i) + outFrameHB[i] = WEBRTC_SPL_SAT( + WEBRTC_SPL_WORD16_MAX, inst->dataBufHB[i], WEBRTC_SPL_WORD16_MIN); + return 0; } @@ -1239,16 +1216,9 @@ int WebRtcNs_ProcessCore(NSinst_t* inst, inst->outLen -= inst->blockLen10ms; } - // convert to short - for (i = 0; i < inst->blockLen10ms; i++) { - dTmp = fout[i]; - if (dTmp < WEBRTC_SPL_WORD16_MIN) { - dTmp = WEBRTC_SPL_WORD16_MIN; - } else if (dTmp > WEBRTC_SPL_WORD16_MAX) { - dTmp = WEBRTC_SPL_WORD16_MAX; - } - outFrame[i] = (short)dTmp; - } + for (i = 0; i < inst->blockLen10ms; ++i) + outFrame[i] = WEBRTC_SPL_SAT( + WEBRTC_SPL_WORD16_MAX, fout[i], WEBRTC_SPL_WORD16_MIN); // for time-domain gain of HB if (flagHB == 1) { @@ -1289,13 +1259,9 @@ int WebRtcNs_ProcessCore(NSinst_t* inst, } //apply gain for (i = 0; i < inst->blockLen10ms; i++) { - dTmp = gainTimeDomainHB * inst->dataBufHB[i]; - if (dTmp < WEBRTC_SPL_WORD16_MIN) { - dTmp = WEBRTC_SPL_WORD16_MIN; - } else if (dTmp > WEBRTC_SPL_WORD16_MAX) { - dTmp = WEBRTC_SPL_WORD16_MAX; - } - outFrameHB[i] = (short)dTmp; + float o = gainTimeDomainHB * inst->dataBufHB[i]; + outFrameHB[i] = WEBRTC_SPL_SAT( + WEBRTC_SPL_WORD16_MAX, o, WEBRTC_SPL_WORD16_MIN); } } // end of H band gain computation // diff --git a/webrtc/modules/audio_processing/ns/ns_core.h b/webrtc/modules/audio_processing/ns/ns_core.h index 50daa137cf..785239ebda 100644 --- a/webrtc/modules/audio_processing/ns/ns_core.h +++ b/webrtc/modules/audio_processing/ns/ns_core.h @@ -167,10 +167,10 @@ int WebRtcNs_set_policy_core(NSinst_t* inst, int mode); int WebRtcNs_ProcessCore(NSinst_t* inst, - short* inFrameLow, - short* inFrameHigh, - short* outFrameLow, - short* outFrameHigh); + float* inFrameLow, + float* inFrameHigh, + float* outFrameLow, + float* outFrameHigh); #ifdef __cplusplus