| 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 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 | 952 |
| 953 ++partition; | 953 ++partition; |
| 954 if (partition == num_partitions) { | 954 if (partition == num_partitions) { |
| 955 partition = 0; | 955 partition = 0; |
| 956 RTC_DCHECK_EQ(num_partitions * PART_LEN1, x_fft_buf_position); | 956 RTC_DCHECK_EQ(num_partitions * PART_LEN1, x_fft_buf_position); |
| 957 x_fft_buf_position = 0; | 957 x_fft_buf_position = 0; |
| 958 } | 958 } |
| 959 } | 959 } |
| 960 } | 960 } |
| 961 | 961 |
| 962 static void EchoSubtraction(AecCore* aec, | 962 static void EchoSubtraction(int num_partitions, |
| 963 int num_partitions, | |
| 964 int extended_filter_enabled, | 963 int extended_filter_enabled, |
| 964 int* extreme_filter_divergence, |
| 965 float filter_step_size, | 965 float filter_step_size, |
| 966 float error_threshold, | 966 float error_threshold, |
| 967 float* x_fft, | 967 float* x_fft, |
| 968 int* x_fft_buf_block_pos, | 968 int* x_fft_buf_block_pos, |
| 969 float x_fft_buf[2] | 969 float x_fft_buf[2] |
| 970 [kExtendedNumPartitions * PART_LEN1], | 970 [kExtendedNumPartitions * PART_LEN1], |
| 971 float* const y, | 971 float* const y, |
| 972 float x_pow[PART_LEN1], | 972 float x_pow[PART_LEN1], |
| 973 float h_fft_buf[2] | 973 float h_fft_buf[2] |
| 974 [kExtendedNumPartitions * PART_LEN1], | 974 [kExtendedNumPartitions * PART_LEN1], |
| (...skipping 15 matching lines...) Expand all Loading... |
| 990 // Buffer x_fft. | 990 // Buffer x_fft. |
| 991 memcpy(x_fft_buf[0] + (*x_fft_buf_block_pos) * PART_LEN1, x_fft, | 991 memcpy(x_fft_buf[0] + (*x_fft_buf_block_pos) * PART_LEN1, x_fft, |
| 992 sizeof(float) * PART_LEN1); | 992 sizeof(float) * PART_LEN1); |
| 993 memcpy(x_fft_buf[1] + (*x_fft_buf_block_pos) * PART_LEN1, &x_fft[PART_LEN1], | 993 memcpy(x_fft_buf[1] + (*x_fft_buf_block_pos) * PART_LEN1, &x_fft[PART_LEN1], |
| 994 sizeof(float) * PART_LEN1); | 994 sizeof(float) * PART_LEN1); |
| 995 | 995 |
| 996 memset(s_fft, 0, sizeof(s_fft)); | 996 memset(s_fft, 0, sizeof(s_fft)); |
| 997 | 997 |
| 998 // Conditionally reset the echo subtraction filter if the filter has diverged | 998 // Conditionally reset the echo subtraction filter if the filter has diverged |
| 999 // significantly. | 999 // significantly. |
| 1000 if (!aec->extended_filter_enabled && aec->extreme_filter_divergence) { | 1000 if (!extended_filter_enabled && *extreme_filter_divergence) { |
| 1001 memset(aec->wfBuf, 0, sizeof(aec->wfBuf)); | 1001 memset(h_fft_buf, 0, |
| 1002 aec->extreme_filter_divergence = 0; | 1002 2 * kExtendedNumPartitions * PART_LEN1 * sizeof(h_fft_buf[0][0])); |
| 1003 *extreme_filter_divergence = 0; |
| 1003 } | 1004 } |
| 1004 | 1005 |
| 1005 // Produce echo estimate s_fft. | 1006 // Produce echo estimate s_fft. |
| 1006 WebRtcAec_FilterFar(num_partitions, *x_fft_buf_block_pos, x_fft_buf, | 1007 WebRtcAec_FilterFar(num_partitions, *x_fft_buf_block_pos, x_fft_buf, |
| 1007 h_fft_buf, s_fft); | 1008 h_fft_buf, s_fft); |
| 1008 | 1009 |
| 1009 // Compute the time-domain echo estimate s. | 1010 // Compute the time-domain echo estimate s. |
| 1010 ScaledInverseFft(s_fft, s_extended, 2.0f, 0); | 1011 ScaledInverseFft(s_fft, s_extended, 2.0f, 0); |
| 1011 s = &s_extended[PART_LEN]; | 1012 s = &s_extended[PART_LEN]; |
| 1012 | 1013 |
| 1013 // Compute the time-domain echo prediction error. | 1014 // Compute the time-domain echo prediction error. |
| 1014 for (i = 0; i < PART_LEN; ++i) { | 1015 for (i = 0; i < PART_LEN; ++i) { |
| 1015 e[i] = y[i] - s[i]; | 1016 e[i] = y[i] - s[i]; |
| 1016 } | 1017 } |
| 1017 | 1018 |
| 1018 // Compute the frequency domain echo prediction error. | 1019 // Compute the frequency domain echo prediction error. |
| 1019 memset(e_extended, 0, sizeof(float) * PART_LEN); | 1020 memset(e_extended, 0, sizeof(float) * PART_LEN); |
| 1020 memcpy(e_extended + PART_LEN, e, sizeof(float) * PART_LEN); | 1021 memcpy(e_extended + PART_LEN, e, sizeof(float) * PART_LEN); |
| 1021 Fft(e_extended, e_fft); | 1022 Fft(e_extended, e_fft); |
| 1022 | 1023 |
| 1023 RTC_AEC_DEBUG_RAW_WRITE(aec->e_fft_file, &e_fft[0][0], | |
| 1024 sizeof(e_fft[0][0]) * PART_LEN1 * 2); | |
| 1025 | |
| 1026 // Scale error signal inversely with far power. | 1024 // Scale error signal inversely with far power. |
| 1027 WebRtcAec_ScaleErrorSignal(filter_step_size, error_threshold, x_pow, e_fft); | 1025 WebRtcAec_ScaleErrorSignal(filter_step_size, error_threshold, x_pow, e_fft); |
| 1028 WebRtcAec_FilterAdaptation(num_partitions, *x_fft_buf_block_pos, x_fft_buf, | 1026 WebRtcAec_FilterAdaptation(num_partitions, *x_fft_buf_block_pos, x_fft_buf, |
| 1029 e_fft, h_fft_buf); | 1027 e_fft, h_fft_buf); |
| 1030 memcpy(echo_subtractor_output, e, sizeof(float) * PART_LEN); | 1028 memcpy(echo_subtractor_output, e, sizeof(float) * PART_LEN); |
| 1031 } | 1029 } |
| 1032 | 1030 |
| 1033 static void EchoSuppression(AecCore* aec, | 1031 static void EchoSuppression(AecCore* aec, |
| 1034 float farend[PART_LEN2], | 1032 float farend[PART_LEN2], |
| 1035 float* echo_subtractor_output, | 1033 float* echo_subtractor_output, |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 aec->num_delay_values++; | 1404 aec->num_delay_values++; |
| 1407 } | 1405 } |
| 1408 if (aec->delay_metrics_delivered == 1 && | 1406 if (aec->delay_metrics_delivered == 1 && |
| 1409 aec->num_delay_values >= kDelayMetricsAggregationWindow) { | 1407 aec->num_delay_values >= kDelayMetricsAggregationWindow) { |
| 1410 UpdateDelayMetrics(aec); | 1408 UpdateDelayMetrics(aec); |
| 1411 } | 1409 } |
| 1412 } | 1410 } |
| 1413 } | 1411 } |
| 1414 | 1412 |
| 1415 // Perform echo subtraction. | 1413 // Perform echo subtraction. |
| 1416 EchoSubtraction(aec, aec->num_partitions, aec->extended_filter_enabled, | 1414 EchoSubtraction(aec->num_partitions, aec->extended_filter_enabled, |
| 1417 aec->filter_step_size, aec->error_threshold, &x_fft[0][0], | 1415 &aec->extreme_filter_divergence, aec->filter_step_size, |
| 1418 &aec->xfBufBlockPos, aec->xfBuf, nearend_ptr, aec->xPow, | 1416 aec->error_threshold, &x_fft[0][0], &aec->xfBufBlockPos, |
| 1419 aec->wfBuf, echo_subtractor_output); | 1417 aec->xfBuf, nearend_ptr, aec->xPow, aec->wfBuf, |
| 1418 echo_subtractor_output); |
| 1420 | 1419 |
| 1421 RTC_AEC_DEBUG_WAV_WRITE(aec->outLinearFile, echo_subtractor_output, PART_LEN); | 1420 RTC_AEC_DEBUG_WAV_WRITE(aec->outLinearFile, echo_subtractor_output, PART_LEN); |
| 1422 | 1421 |
| 1423 if (aec->metricsMode == 1) { | 1422 if (aec->metricsMode == 1) { |
| 1424 UpdateLevel(&aec->linoutlevel, | 1423 UpdateLevel(&aec->linoutlevel, |
| 1425 CalculatePower(echo_subtractor_output, PART_LEN)); | 1424 CalculatePower(echo_subtractor_output, PART_LEN)); |
| 1426 } | 1425 } |
| 1427 | 1426 |
| 1428 // Perform echo suppression. | 1427 // Perform echo suppression. |
| 1429 EchoSuppression(aec, farend_ptr, echo_subtractor_output, output, outputH_ptr); | 1428 EchoSuppression(aec, farend_ptr, echo_subtractor_output, output, outputH_ptr); |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2026 | 2025 |
| 2027 int WebRtcAec_system_delay(AecCore* self) { | 2026 int WebRtcAec_system_delay(AecCore* self) { |
| 2028 return self->system_delay; | 2027 return self->system_delay; |
| 2029 } | 2028 } |
| 2030 | 2029 |
| 2031 void WebRtcAec_SetSystemDelay(AecCore* self, int delay) { | 2030 void WebRtcAec_SetSystemDelay(AecCore* self, int delay) { |
| 2032 assert(delay >= 0); | 2031 assert(delay >= 0); |
| 2033 self->system_delay = delay; | 2032 self->system_delay = delay; |
| 2034 } | 2033 } |
| 2035 } // namespace webrtc | 2034 } // namespace webrtc |
| OLD | NEW |