Index: webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc |
diff --git a/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc b/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc |
index 3ae8f879efb4bf8b5d4f0011e079da8ecd56d70c..035b24c38540e3edd715b25c196a7b2014034b11 100644 |
--- a/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc |
+++ b/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc |
@@ -9,29 +9,70 @@ |
*/ |
#include "webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h" |
-#include "webrtc/base/checks.h" |
hlundin-webrtc
2017/02/01 08:30:02
You are still using checks. Don't delete this.
peah-webrtc
2017/02/02 14:04:47
Done.
|
+#include <algorithm> |
+ |
#include "webrtc/modules/audio_processing/aec3/aec3_constants.h" |
-#include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" |
+#include "webrtc/modules/audio_processing/include/audio_processing.h" |
namespace webrtc { |
-// TODO(peah): Add functionality. |
+namespace { |
+ |
+constexpr size_t kNumCorrelatorAlignmentShifts = 3; |
+constexpr size_t kCorrelatorWindowSizeSubBlocks = 32; |
+constexpr size_t kCorrelatorAlignmentShiftSizeSubBlocks = |
+ kCorrelatorWindowSizeSubBlocks * 3 / 4; |
+ |
+} // namespace |
+ |
EchoPathDelayEstimator::EchoPathDelayEstimator(ApmDataDumper* data_dumper, |
- int sample_rate_hz) { |
+ int sample_rate_hz) |
+ : data_dumper_(data_dumper), |
+ render_down_sampler_(sample_rate_hz), |
+ capture_down_sampler_(sample_rate_hz), |
+ down_sampling_factor_(capture_down_sampler_.GetDownSamplingFactor()), |
hlundin-webrtc
2017/02/01 08:30:02
Can't you call capture_down_sampler_.GetDownSampli
peah-webrtc
2017/02/02 14:04:47
I refactored it a bit. PTAL
|
+ correlator_(data_dumper_, |
+ kCorrelatorWindowSizeSubBlocks, |
+ kNumCorrelatorAlignmentShifts, |
+ kCorrelatorAlignmentShiftSizeSubBlocks), |
+ correlator_lag_aggregator_(data_dumper_, correlator_.NumLagEstimates()) { |
RTC_DCHECK(data_dumper); |
- RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 || |
- sample_rate_hz == 32000 || sample_rate_hz == 48000); |
+ RTC_DCHECK(ValidFullBandRate(sample_rate_hz)); |
} |
EchoPathDelayEstimator::~EchoPathDelayEstimator() = default; |
-// TODO(peah): Add functionality. |
rtc::Optional<size_t> EchoPathDelayEstimator::EstimateDelay( |
rtc::ArrayView<const float> render, |
rtc::ArrayView<const float> capture) { |
- RTC_DCHECK_EQ(render.size(), kBlockSize); |
- RTC_DCHECK_EQ(capture.size(), kBlockSize); |
- return rtc::Optional<size_t>(); |
+ RTC_DCHECK_EQ(kBlockSize, capture.size()); |
+ RTC_DCHECK_EQ(render.size(), capture.size()); |
+ |
+ float downsampled_render[kSubBlockSize]; |
+ float downsampled_capture[kSubBlockSize]; |
+ |
+ render_down_sampler_.DownSample(render, downsampled_render); |
+ capture_down_sampler_.DownSample(capture, downsampled_capture); |
+ |
+ correlator_.Update(downsampled_render, downsampled_capture); |
+ |
+ rtc::Optional<size_t> aggregated_correlator_lag = |
+ correlator_lag_aggregator_.Aggregate(correlator_.GetLagEstimates()); |
+ |
+ // TODO(peah): Move this logging outside of this class once EchoCanceller3 |
+ // development is done. |
+ data_dumper_->DumpRaw( |
+ "aec3_echo_path_delay_estimator_delay", |
+ aggregated_correlator_lag |
+ ? static_cast<int>(*aggregated_correlator_lag * down_sampling_factor_) |
+ : -1); |
+ |
+ // Return the detected delay in samples as the aggregated correlator lag |
+ // compensated by the down sampling factor for the signal being correlated. |
+ return aggregated_correlator_lag |
+ ? rtc::Optional<size_t>(*aggregated_correlator_lag * |
+ down_sampling_factor_) |
+ : rtc::Optional<size_t>(); |
} |
} // namespace webrtc |