OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 enum { kPrefBandSize = 24 }; | 134 enum { kPrefBandSize = 24 }; |
135 | 135 |
136 #ifdef WEBRTC_AEC_DEBUG_DUMP | 136 #ifdef WEBRTC_AEC_DEBUG_DUMP |
137 extern int webrtc_aec_instance_count; | 137 extern int webrtc_aec_instance_count; |
138 #endif | 138 #endif |
139 | 139 |
140 WebRtcAecFilterFar WebRtcAec_FilterFar; | 140 WebRtcAecFilterFar WebRtcAec_FilterFar; |
141 WebRtcAecScaleErrorSignal WebRtcAec_ScaleErrorSignal; | 141 WebRtcAecScaleErrorSignal WebRtcAec_ScaleErrorSignal; |
142 WebRtcAecFilterAdaptation WebRtcAec_FilterAdaptation; | 142 WebRtcAecFilterAdaptation WebRtcAec_FilterAdaptation; |
143 WebRtcAecOverdriveAndSuppress WebRtcAec_OverdriveAndSuppress; | 143 WebRtcAecOverdriveAndSuppress WebRtcAec_OverdriveAndSuppress; |
144 WebRtcAecSubBandCoherence WebRtcAec_SubbandCoherence; | 144 WebRtcAecComputeCoherence WebRtcAec_ComputeCoherence; |
145 WebRtcAecUpdateCoherenceSpectra WebRtcAec_UpdateCoherenceSpectra; | |
145 WebRtcAecStoreAsComplex WebRtcAec_StoreAsComplex; | 146 WebRtcAecStoreAsComplex WebRtcAec_StoreAsComplex; |
146 WebRtcAecPartitionDelay WebRtcAec_PartitionDelay; | 147 WebRtcAecPartitionDelay WebRtcAec_PartitionDelay; |
147 WebRtcAecWindowData WebRtcAec_WindowData; | 148 WebRtcAecWindowData WebRtcAec_WindowData; |
148 | 149 |
149 __inline static float MulRe(float aRe, float aIm, float bRe, float bIm) { | 150 __inline static float MulRe(float aRe, float aIm, float bRe, float bIm) { |
150 return aRe * bRe - aIm * bIm; | 151 return aRe * bRe - aIm * bIm; |
151 } | 152 } |
152 | 153 |
153 __inline static float MulIm(float aRe, float aIm, float bRe, float bIm) { | 154 __inline static float MulIm(float aRe, float aIm, float bRe, float bIm) { |
154 return aRe * bIm + aIm * bRe; | 155 return aRe * bIm + aIm * bRe; |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 // This is to protect overflow, which should almost never happen. | 396 // This is to protect overflow, which should almost never happen. |
396 RTC_CHECK_NE(0u, metric->hicounter); | 397 RTC_CHECK_NE(0u, metric->hicounter); |
397 metric->hisum += metric->instant; | 398 metric->hisum += metric->instant; |
398 metric->himean = metric->hisum / metric->hicounter; | 399 metric->himean = metric->hisum / metric->hicounter; |
399 } | 400 } |
400 } | 401 } |
401 | 402 |
402 // Threshold to protect against the ill-effects of a zero far-end. | 403 // Threshold to protect against the ill-effects of a zero far-end. |
403 const float WebRtcAec_kMinFarendPSD = 15; | 404 const float WebRtcAec_kMinFarendPSD = 15; |
404 | 405 |
405 // Updates the following smoothed Power Spectral Densities (PSD): | 406 // Updates the following smoothed Power Spectral Densities (PSD): |
minyue-webrtc
2016/05/03 07:29:06
nit: one extra space
peah-webrtc
2016/05/07 21:26:35
Good find!
Done.
| |
406 // - sd : near-end | 407 // - sd : near-end |
407 // - se : residual echo | 408 // - se : residual echo |
408 // - sx : far-end | 409 // - sx : far-end |
409 // - sde : cross-PSD of near-end and residual echo | 410 // - sde : cross-PSD of near-end and residual echo |
410 // - sxd : cross-PSD of near-end and far-end | 411 // - sxd : cross-PSD of near-end and far-end |
411 // | 412 // |
412 // In addition to updating the PSDs, also the filter diverge state is | 413 // In addition to updating the PSDs, also the filter diverge state is |
413 // determined. | 414 // determined. |
414 static void SmoothedPSD(int mult, | 415 static void UpdateCoherenceSpectra(int mult, |
415 bool extended_filter_enabled, | 416 bool extended_filter_enabled, |
416 float efw[2][PART_LEN1], | 417 float efw[2][PART_LEN1], |
417 float dfw[2][PART_LEN1], | 418 float dfw[2][PART_LEN1], |
418 float xfw[2][PART_LEN1], | 419 float xfw[2][PART_LEN1], |
419 CoherenceState* coherence_state, | 420 CoherenceState* coherence_state, |
420 short* filter_divergence_state, | 421 short* filter_divergence_state, |
421 int* extreme_filter_divergence) { | 422 int* extreme_filter_divergence) { |
422 // Power estimate smoothing coefficients. | 423 // Power estimate smoothing coefficients. |
423 const float* ptrGCoh = | 424 const float* ptrGCoh = |
424 extended_filter_enabled | 425 extended_filter_enabled |
425 ? WebRtcAec_kExtendedSmoothingCoefficients[mult - 1] | 426 ? WebRtcAec_kExtendedSmoothingCoefficients[mult - 1] |
426 : WebRtcAec_kNormalSmoothingCoefficients[mult - 1]; | 427 : WebRtcAec_kNormalSmoothingCoefficients[mult - 1]; |
427 int i; | 428 int i; |
428 float sdSum = 0, seSum = 0; | 429 float sdSum = 0, seSum = 0; |
429 | 430 |
430 for (i = 0; i < PART_LEN1; i++) { | 431 for (i = 0; i < PART_LEN1; i++) { |
431 coherence_state->sd[i] = | 432 coherence_state->sd[i] = |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 data_complex[0][0] = data[0]; | 489 data_complex[0][0] = data[0]; |
489 data_complex[1][0] = 0; | 490 data_complex[1][0] = 0; |
490 for (i = 1; i < PART_LEN; i++) { | 491 for (i = 1; i < PART_LEN; i++) { |
491 data_complex[0][i] = data[2 * i]; | 492 data_complex[0][i] = data[2 * i]; |
492 data_complex[1][i] = data[2 * i + 1]; | 493 data_complex[1][i] = data[2 * i + 1]; |
493 } | 494 } |
494 data_complex[0][PART_LEN] = data[1]; | 495 data_complex[0][PART_LEN] = data[1]; |
495 data_complex[1][PART_LEN] = 0; | 496 data_complex[1][PART_LEN] = 0; |
496 } | 497 } |
497 | 498 |
498 static void SubbandCoherence(int mult, | 499 static void ComputeCoherence(const CoherenceState* coherence_state, |
499 bool extended_filter_enabled, | |
500 float efw[2][PART_LEN1], | |
501 float dfw[2][PART_LEN1], | |
502 float xfw[2][PART_LEN1], | |
503 float* fft, | |
504 float* cohde, | 500 float* cohde, |
505 float* cohxd, | 501 float* cohxd) { |
506 CoherenceState* coherence_state, | |
507 short* filter_divergence_state, | |
508 int* extreme_filter_divergence) { | |
509 int i; | |
510 | |
511 SmoothedPSD(mult, extended_filter_enabled, efw, dfw, xfw, coherence_state, | |
512 filter_divergence_state, extreme_filter_divergence); | |
513 | |
514 // Subband coherence | 502 // Subband coherence |
515 for (i = 0; i < PART_LEN1; i++) { | 503 for (int i = 0; i < PART_LEN1; i++) { |
516 cohde[i] = (coherence_state->sde[i][0] * coherence_state->sde[i][0] + | 504 cohde[i] = (coherence_state->sde[i][0] * coherence_state->sde[i][0] + |
517 coherence_state->sde[i][1] * coherence_state->sde[i][1]) / | 505 coherence_state->sde[i][1] * coherence_state->sde[i][1]) / |
518 (coherence_state->sd[i] * coherence_state->se[i] + 1e-10f); | 506 (coherence_state->sd[i] * coherence_state->se[i] + 1e-10f); |
519 cohxd[i] = (coherence_state->sxd[i][0] * coherence_state->sxd[i][0] + | 507 cohxd[i] = (coherence_state->sxd[i][0] * coherence_state->sxd[i][0] + |
520 coherence_state->sxd[i][1] * coherence_state->sxd[i][1]) / | 508 coherence_state->sxd[i][1] * coherence_state->sxd[i][1]) / |
521 (coherence_state->sx[i] * coherence_state->sd[i] + 1e-10f); | 509 (coherence_state->sx[i] * coherence_state->sd[i] + 1e-10f); |
522 } | 510 } |
523 } | 511 } |
524 | 512 |
525 static void GetHighbandGain(const float* lambda, float* nlpGainHband) { | 513 static void GetHighbandGain(const float* lambda, float* nlpGainHband) { |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1061 aec->delayEstCtr++; | 1049 aec->delayEstCtr++; |
1062 if (aec->delayEstCtr == delayEstInterval) { | 1050 if (aec->delayEstCtr == delayEstInterval) { |
1063 aec->delayEstCtr = 0; | 1051 aec->delayEstCtr = 0; |
1064 aec->delayIdx = WebRtcAec_PartitionDelay(aec->num_partitions, aec->wfBuf); | 1052 aec->delayIdx = WebRtcAec_PartitionDelay(aec->num_partitions, aec->wfBuf); |
1065 } | 1053 } |
1066 | 1054 |
1067 // Use delayed far. | 1055 // Use delayed far. |
1068 memcpy(xfw, aec->xfwBuf + aec->delayIdx * PART_LEN1, | 1056 memcpy(xfw, aec->xfwBuf + aec->delayIdx * PART_LEN1, |
1069 sizeof(xfw[0][0]) * 2 * PART_LEN1); | 1057 sizeof(xfw[0][0]) * 2 * PART_LEN1); |
1070 | 1058 |
1071 WebRtcAec_SubbandCoherence(aec->mult, aec->extended_filter_enabled == 1, efw, | 1059 WebRtcAec_UpdateCoherenceSpectra(aec->mult, aec->extended_filter_enabled == 1, |
1072 dfw, xfw, fft, cohde, cohxd, &aec->coherence_state, | 1060 efw, dfw, xfw, &aec->coherence_state, |
1073 &aec->divergeState, | 1061 &aec->divergeState, |
1074 &aec->extreme_filter_divergence); | 1062 &aec->extreme_filter_divergence); |
1063 | |
1064 WebRtcAec_ComputeCoherence(&aec->coherence_state, cohde, cohxd); | |
1075 | 1065 |
1076 // Select the microphone signal as output if the filter is deemed to have | 1066 // Select the microphone signal as output if the filter is deemed to have |
1077 // diverged. | 1067 // diverged. |
1078 if (aec->divergeState) { | 1068 if (aec->divergeState) { |
1079 memcpy(efw, dfw, sizeof(efw[0][0]) * 2 * PART_LEN1); | 1069 memcpy(efw, dfw, sizeof(efw[0][0]) * 2 * PART_LEN1); |
1080 } | 1070 } |
1081 | 1071 |
1082 hNlXdAvg = 0; | 1072 hNlXdAvg = 0; |
1083 for (i = minPrefBand; i < prefBandSize + minPrefBand; i++) { | 1073 for (i = minPrefBand; i < prefBandSize + minPrefBand; i++) { |
1084 hNlXdAvg += cohxd[i]; | 1074 hNlXdAvg += cohxd[i]; |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1495 #endif | 1485 #endif |
1496 aec->extended_filter_enabled = 0; | 1486 aec->extended_filter_enabled = 0; |
1497 aec->aec3_enabled = 0; | 1487 aec->aec3_enabled = 0; |
1498 aec->refined_adaptive_filter_enabled = false; | 1488 aec->refined_adaptive_filter_enabled = false; |
1499 | 1489 |
1500 // Assembly optimization | 1490 // Assembly optimization |
1501 WebRtcAec_FilterFar = FilterFar; | 1491 WebRtcAec_FilterFar = FilterFar; |
1502 WebRtcAec_ScaleErrorSignal = ScaleErrorSignal; | 1492 WebRtcAec_ScaleErrorSignal = ScaleErrorSignal; |
1503 WebRtcAec_FilterAdaptation = FilterAdaptation; | 1493 WebRtcAec_FilterAdaptation = FilterAdaptation; |
1504 WebRtcAec_OverdriveAndSuppress = OverdriveAndSuppress; | 1494 WebRtcAec_OverdriveAndSuppress = OverdriveAndSuppress; |
1505 WebRtcAec_SubbandCoherence = SubbandCoherence; | 1495 WebRtcAec_ComputeCoherence = ComputeCoherence; |
1496 WebRtcAec_UpdateCoherenceSpectra = UpdateCoherenceSpectra; | |
1506 WebRtcAec_StoreAsComplex = StoreAsComplex; | 1497 WebRtcAec_StoreAsComplex = StoreAsComplex; |
1507 WebRtcAec_PartitionDelay = PartitionDelay; | 1498 WebRtcAec_PartitionDelay = PartitionDelay; |
1508 WebRtcAec_WindowData = WindowData; | 1499 WebRtcAec_WindowData = WindowData; |
1509 | 1500 |
1510 #if defined(WEBRTC_ARCH_X86_FAMILY) | 1501 #if defined(WEBRTC_ARCH_X86_FAMILY) |
1511 if (WebRtc_GetCPUInfo(kSSE2)) { | 1502 if (WebRtc_GetCPUInfo(kSSE2)) { |
1512 WebRtcAec_InitAec_SSE2(); | 1503 WebRtcAec_InitAec_SSE2(); |
1513 } | 1504 } |
1514 #endif | 1505 #endif |
1515 | 1506 |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2000 | 1991 |
2001 int WebRtcAec_system_delay(AecCore* self) { | 1992 int WebRtcAec_system_delay(AecCore* self) { |
2002 return self->system_delay; | 1993 return self->system_delay; |
2003 } | 1994 } |
2004 | 1995 |
2005 void WebRtcAec_SetSystemDelay(AecCore* self, int delay) { | 1996 void WebRtcAec_SetSystemDelay(AecCore* self, int delay) { |
2006 assert(delay >= 0); | 1997 assert(delay >= 0); |
2007 self->system_delay = delay; | 1998 self->system_delay = delay; |
2008 } | 1999 } |
2009 } // namespace webrtc | 2000 } // namespace webrtc |
OLD | NEW |