Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: webrtc/modules/audio_processing/aec/aec_core.c

Issue 1639773002: Moved buffering of farend into the EchoSubtraction method. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 float delay_quality = WebRtc_last_delay_quality(self->delay_estimator); 892 float delay_quality = WebRtc_last_delay_quality(self->delay_estimator);
893 delay_quality = (delay_quality > kDelayQualityThresholdMax ? 893 delay_quality = (delay_quality > kDelayQualityThresholdMax ?
894 kDelayQualityThresholdMax : delay_quality); 894 kDelayQualityThresholdMax : delay_quality);
895 self->delay_quality_threshold = 895 self->delay_quality_threshold =
896 (delay_quality > self->delay_quality_threshold ? delay_quality : 896 (delay_quality > self->delay_quality_threshold ? delay_quality :
897 self->delay_quality_threshold); 897 self->delay_quality_threshold);
898 } 898 }
899 return delay_correction; 899 return delay_correction;
900 } 900 }
901 901
902 static void EchoSubtraction( 902 static void EchoSubtraction(AecCore* aec,
903 AecCore* aec, 903 int num_partitions,
904 int num_partitions, 904 int metrics_mode,
minyue-webrtc 2016/01/26 15:15:26 I prefer the old line breaking. less lines and cle
peah-webrtc 2016/01/28 13:06:07 This breaking is according to (caused by) clang-fo
minyue-webrtc 2016/01/28 14:10:40 That is generally ok, although I prefer some manua
905 int x_fft_buf_block_pos, 905 int extended_filter_enabled,
906 int metrics_mode, 906 float normal_mu,
907 int extended_filter_enabled, 907 float normal_error_threshold,
908 float normal_mu, 908 float* xf,
minyue-webrtc 2016/01/26 15:15:26 would it better to change xf to something more mea
peah-webrtc 2016/01/28 13:06:07 That makes sense! I will change to x_fft, as that
909 float normal_error_threshold, 909 int* x_fft_buf_block_pos,
910 float x_fft_buf[2][kExtendedNumPartitions * PART_LEN1], 910 float x_fft_buf[2]
911 float* const y, 911 [kExtendedNumPartitions * PART_LEN1],
912 float x_pow[PART_LEN1], 912 float* const y,
913 float h_fft_buf[2][kExtendedNumPartitions * PART_LEN1], 913 float x_pow[PART_LEN1],
914 PowerLevel* linout_level, 914 float h_fft_buf[2]
915 float echo_subtractor_output[PART_LEN]) { 915 [kExtendedNumPartitions * PART_LEN1],
916 PowerLevel* linout_level,
917 float echo_subtractor_output[PART_LEN]) {
916 float s_fft[2][PART_LEN1]; 918 float s_fft[2][PART_LEN1];
917 float e_extended[PART_LEN2]; 919 float e_extended[PART_LEN2];
918 float s_extended[PART_LEN2]; 920 float s_extended[PART_LEN2];
919 float *s; 921 float *s;
920 float e[PART_LEN]; 922 float e[PART_LEN];
921 float e_fft[2][PART_LEN1]; 923 float e_fft[2][PART_LEN1];
922 int i; 924 int i;
925
926 // Update the x_fft_buf block position.
927 (*x_fft_buf_block_pos)--;
928 if ((*x_fft_buf_block_pos) == -1) {
929 *x_fft_buf_block_pos = num_partitions - 1;
930 }
931
932 // Buffer xf.
933 memcpy(x_fft_buf[0] + (*x_fft_buf_block_pos) * PART_LEN1, xf,
934 sizeof(float) * PART_LEN1);
935 memcpy(x_fft_buf[1] + (*x_fft_buf_block_pos) * PART_LEN1, &xf[PART_LEN1],
936 sizeof(float) * PART_LEN1);
937
923 memset(s_fft, 0, sizeof(s_fft)); 938 memset(s_fft, 0, sizeof(s_fft));
924 939
925 // Conditionally reset the echo subtraction filter if the filter has diverged 940 // Conditionally reset the echo subtraction filter if the filter has diverged
926 // significantly. 941 // significantly.
927 if (!aec->extended_filter_enabled && 942 if (!aec->extended_filter_enabled &&
928 aec->extreme_filter_divergence) { 943 aec->extreme_filter_divergence) {
929 memset(aec->wfBuf, 0, sizeof(aec->wfBuf)); 944 memset(aec->wfBuf, 0, sizeof(aec->wfBuf));
930 aec->extreme_filter_divergence = 0; 945 aec->extreme_filter_divergence = 0;
931 } 946 }
932 947
933 // Produce echo estimate s_fft. 948 // Produce echo estimate s_fft.
934 WebRtcAec_FilterFar(num_partitions, 949 WebRtcAec_FilterFar(num_partitions, *x_fft_buf_block_pos, x_fft_buf,
935 x_fft_buf_block_pos, 950 h_fft_buf, s_fft);
936 x_fft_buf,
937 h_fft_buf,
938 s_fft);
939 951
940 // Compute the time-domain echo estimate s. 952 // Compute the time-domain echo estimate s.
941 ScaledInverseFft(s_fft, s_extended, 2.0f, 0); 953 ScaledInverseFft(s_fft, s_extended, 2.0f, 0);
942 s = &s_extended[PART_LEN]; 954 s = &s_extended[PART_LEN];
943 955
944 // Compute the time-domain echo prediction error. 956 // Compute the time-domain echo prediction error.
945 for (i = 0; i < PART_LEN; ++i) { 957 for (i = 0; i < PART_LEN; ++i) {
946 e[i] = y[i] - s[i]; 958 e[i] = y[i] - s[i];
947 } 959 }
948 960
(...skipping 12 matching lines...) Expand all
961 // performed. That scaling is taken care of in UpdateMetrics() instead. 973 // performed. That scaling is taken care of in UpdateMetrics() instead.
962 UpdateLevel(linout_level, CalculatePower(e, PART_LEN) / 2.0f); 974 UpdateLevel(linout_level, CalculatePower(e, PART_LEN) / 2.0f);
963 } 975 }
964 976
965 // Scale error signal inversely with far power. 977 // Scale error signal inversely with far power.
966 WebRtcAec_ScaleErrorSignal(extended_filter_enabled, 978 WebRtcAec_ScaleErrorSignal(extended_filter_enabled,
967 normal_mu, 979 normal_mu,
968 normal_error_threshold, 980 normal_error_threshold,
969 x_pow, 981 x_pow,
970 e_fft); 982 e_fft);
971 WebRtcAec_FilterAdaptation(num_partitions, 983 WebRtcAec_FilterAdaptation(num_partitions, *x_fft_buf_block_pos, x_fft_buf,
972 x_fft_buf_block_pos, 984 e_fft, h_fft_buf);
973 x_fft_buf,
974 e_fft,
975 h_fft_buf);
976 memcpy(echo_subtractor_output, e, sizeof(float) * PART_LEN); 985 memcpy(echo_subtractor_output, e, sizeof(float) * PART_LEN);
977 } 986 }
978 987
979 988
980 static void EchoSuppression(AecCore* aec, 989 static void EchoSuppression(AecCore* aec,
981 float farend[PART_LEN2], 990 float farend[PART_LEN2],
982 float* echo_subtractor_output, 991 float* echo_subtractor_output,
983 float* output, 992 float* output,
984 float* const* outputH) { 993 float* const* outputH) {
985 float efw[2][PART_LEN1]; 994 float efw[2][PART_LEN1];
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 aec->delay_histogram[delay_estimate]++; 1358 aec->delay_histogram[delay_estimate]++;
1350 aec->num_delay_values++; 1359 aec->num_delay_values++;
1351 } 1360 }
1352 if (aec->delay_metrics_delivered == 1 && 1361 if (aec->delay_metrics_delivered == 1 &&
1353 aec->num_delay_values >= kDelayMetricsAggregationWindow) { 1362 aec->num_delay_values >= kDelayMetricsAggregationWindow) {
1354 UpdateDelayMetrics(aec); 1363 UpdateDelayMetrics(aec);
1355 } 1364 }
1356 } 1365 }
1357 } 1366 }
1358 1367
1359 // Update the xfBuf block position.
1360 aec->xfBufBlockPos--;
1361 if (aec->xfBufBlockPos == -1) {
1362 aec->xfBufBlockPos = aec->num_partitions - 1;
1363 }
1364
1365 // Buffer xf
1366 memcpy(aec->xfBuf[0] + aec->xfBufBlockPos * PART_LEN1,
1367 xf_ptr,
1368 sizeof(float) * PART_LEN1);
1369 memcpy(aec->xfBuf[1] + aec->xfBufBlockPos * PART_LEN1,
1370 &xf_ptr[PART_LEN1],
1371 sizeof(float) * PART_LEN1);
1372
1373 // Perform echo subtraction. 1368 // Perform echo subtraction.
1374 EchoSubtraction(aec, 1369 EchoSubtraction(aec, aec->num_partitions, aec->metricsMode,
1375 aec->num_partitions, 1370 aec->extended_filter_enabled, aec->normal_mu,
1376 aec->xfBufBlockPos, 1371 aec->normal_error_threshold, &xf[0][0], &aec->xfBufBlockPos,
minyue-webrtc 2016/01/26 15:15:26 if you like you can change xf here to something mo
peah-webrtc 2016/01/28 13:06:07 Done.
1377 aec->metricsMode, 1372 aec->xfBuf, nearend_ptr, aec->xPow, aec->wfBuf,
1378 aec->extended_filter_enabled, 1373 &aec->linoutlevel, echo_subtractor_output);
1379 aec->normal_mu,
1380 aec->normal_error_threshold,
1381 aec->xfBuf,
1382 nearend_ptr,
1383 aec->xPow,
1384 aec->wfBuf,
1385 &aec->linoutlevel,
1386 echo_subtractor_output);
1387 1374
1388 RTC_AEC_DEBUG_WAV_WRITE(aec->outLinearFile, echo_subtractor_output, PART_LEN); 1375 RTC_AEC_DEBUG_WAV_WRITE(aec->outLinearFile, echo_subtractor_output, PART_LEN);
1389 1376
1390 // Perform echo suppression. 1377 // Perform echo suppression.
1391 EchoSuppression(aec, farend_ptr, echo_subtractor_output, output, outputH_ptr); 1378 EchoSuppression(aec, farend_ptr, echo_subtractor_output, output, outputH_ptr);
1392 1379
1393 if (aec->metricsMode == 1) { 1380 if (aec->metricsMode == 1) {
1394 UpdateMetrics(aec); 1381 UpdateMetrics(aec);
1395 } 1382 }
1396 1383
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 int WebRtcAec_extended_filter_enabled(AecCore* self) { 1911 int WebRtcAec_extended_filter_enabled(AecCore* self) {
1925 return self->extended_filter_enabled; 1912 return self->extended_filter_enabled;
1926 } 1913 }
1927 1914
1928 int WebRtcAec_system_delay(AecCore* self) { return self->system_delay; } 1915 int WebRtcAec_system_delay(AecCore* self) { return self->system_delay; }
1929 1916
1930 void WebRtcAec_SetSystemDelay(AecCore* self, int delay) { 1917 void WebRtcAec_SetSystemDelay(AecCore* self, int delay) {
1931 assert(delay >= 0); 1918 assert(delay >= 0);
1932 self->system_delay = delay; 1919 self->system_delay = delay;
1933 } 1920 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698