Break out WebRtcNs_Windowing function in ns_core
This is done in order to make the code more readible and maintainable.
This introduces only +1 and -1 errors.
BUG=webrtc:3811
R=bjornv@webrtc.org, kwiberg@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/29809004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7488 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_processing/ns/ns_core.c b/webrtc/modules/audio_processing/ns/ns_core.c
index 64af5e9..e8bd033 100644
--- a/webrtc/modules/audio_processing/ns/ns_core.c
+++ b/webrtc/modules/audio_processing/ns/ns_core.c
@@ -827,6 +827,24 @@
return energy;
}
+// Windows a buffer.
+// Inputs:
+// * |window| is the window by which to multiply.
+// * |data| is the data without windowing.
+// * |length| is the length of the window and data.
+// Output:
+// * |data_windowed| is the windowed data.
+static void Windowing(const float* window,
+ const float* data,
+ int length,
+ float* data_windowed) {
+ int i;
+
+ for (i = 0; i < length; ++i) {
+ data_windowed[i] = window[i] * data[i];
+ }
+}
+
int WebRtcNs_AnalyzeCore(NSinst_t* inst, float* speechFrame) {
int i;
const int kStartBand = 5; // Skip first frequency bins during estimation.
@@ -861,9 +879,7 @@
UpdateBuffer(speechFrame, inst->blockLen, inst->anaLen, inst->analyzeBuf);
// windowing
- for (i = 0; i < inst->anaLen; i++) {
- winData[i] = inst->window[i] * inst->analyzeBuf[i];
- }
+ Windowing(inst->window, inst->analyzeBuf, inst->anaLen, winData);
energy = Energy(winData, inst->anaLen);
if (energy == 0.0) {
// we want to avoid updating statistics in this case:
@@ -1144,9 +1160,7 @@
}
// windowing
- for (i = 0; i < inst->anaLen; i++) {
- winData[i] = inst->window[i] * inst->dataBuf[i];
- }
+ Windowing(inst->window, inst->dataBuf, inst->anaLen, winData);
energy1 = Energy(winData, inst->anaLen);
if (energy1 == 0.0) {
// synthesize the special case of zero input
@@ -1283,9 +1297,11 @@
(1.f - inst->priorSpeechProb) * factor2;
} // out of inst->gainmap==1
+ Windowing(inst->window, winData, inst->anaLen, winData);
+
// synthesis
for (i = 0; i < inst->anaLen; i++) {
- inst->syntBuf[i] += factor * inst->window[i] * winData[i];
+ inst->syntBuf[i] += factor * winData[i];
}
// read out fully processed segment
for (i = inst->windShift; i < inst->blockLen + inst->windShift; i++) {