| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2  *  Copyright (c) 2017 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 #include "webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h" | 10 #include "webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h" | 
| 11 | 11 | 
| 12 #include <algorithm> | 12 #include <algorithm> | 
| 13 #include <array> | 13 #include <array> | 
| 14 | 14 | 
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" | 
| 16 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" | 16 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" | 
| 17 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 17 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 
| 18 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | 18 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | 
| 19 | 19 | 
| 20 namespace webrtc { | 20 namespace webrtc { | 
| 21 | 21 | 
| 22 namespace { | 22 namespace { | 
| 23 | 23 | 
| 24 constexpr size_t kNumMatchedFilters = 4; |  | 
| 25 constexpr size_t kMatchedFilterWindowSizeSubBlocks = 32; |  | 
| 26 constexpr size_t kMatchedFilterAlignmentShiftSizeSubBlocks = |  | 
| 27     kMatchedFilterWindowSizeSubBlocks * 3 / 4; |  | 
| 28 |  | 
| 29 constexpr int kDownSamplingFactor = 4; | 24 constexpr int kDownSamplingFactor = 4; | 
| 30 }  // namespace | 25 }  // namespace | 
| 31 | 26 | 
| 32 EchoPathDelayEstimator::EchoPathDelayEstimator(ApmDataDumper* data_dumper) | 27 EchoPathDelayEstimator::EchoPathDelayEstimator(ApmDataDumper* data_dumper) | 
| 33     : data_dumper_(data_dumper), | 28     : data_dumper_(data_dumper), | 
| 34       matched_filter_(data_dumper_, | 29       matched_filter_(data_dumper_, | 
| 35                       DetectOptimization(), | 30                       DetectOptimization(), | 
| 36                       kMatchedFilterWindowSizeSubBlocks, | 31                       kMatchedFilterWindowSizeSubBlocks, | 
| 37                       kNumMatchedFilters, | 32                       kNumMatchedFilters, | 
| 38                       kMatchedFilterAlignmentShiftSizeSubBlocks), | 33                       kMatchedFilterAlignmentShiftSizeSubBlocks), | 
| 39       matched_filter_lag_aggregator_(data_dumper_, | 34       matched_filter_lag_aggregator_(data_dumper_, | 
| 40                                      matched_filter_.NumLagEstimates()) { | 35                                      matched_filter_.NumLagEstimates()) { | 
| 41   RTC_DCHECK(data_dumper); | 36   RTC_DCHECK(data_dumper); | 
| 42 } | 37 } | 
| 43 | 38 | 
| 44 EchoPathDelayEstimator::~EchoPathDelayEstimator() = default; | 39 EchoPathDelayEstimator::~EchoPathDelayEstimator() = default; | 
| 45 | 40 | 
|  | 41 void EchoPathDelayEstimator::Reset() { | 
|  | 42   matched_filter_lag_aggregator_.Reset(); | 
|  | 43   matched_filter_.Reset(); | 
|  | 44 } | 
|  | 45 | 
| 46 rtc::Optional<size_t> EchoPathDelayEstimator::EstimateDelay( | 46 rtc::Optional<size_t> EchoPathDelayEstimator::EstimateDelay( | 
| 47     rtc::ArrayView<const float> render, | 47     const DownsampledRenderBuffer& render_buffer, | 
| 48     rtc::ArrayView<const float> capture) { | 48     rtc::ArrayView<const float> capture) { | 
| 49   RTC_DCHECK_EQ(kBlockSize, capture.size()); | 49   RTC_DCHECK_EQ(kBlockSize, capture.size()); | 
| 50   RTC_DCHECK_EQ(render.size(), capture.size()); |  | 
| 51 | 50 | 
| 52   std::array<float, kSubBlockSize> downsampled_render; |  | 
| 53   std::array<float, kSubBlockSize> downsampled_capture; | 51   std::array<float, kSubBlockSize> downsampled_capture; | 
| 54 | 52   capture_decimator_.Decimate(capture, downsampled_capture); | 
| 55   render_decimator_.Decimate(render, &downsampled_render); | 53   matched_filter_.Update(render_buffer, downsampled_capture); | 
| 56   capture_decimator_.Decimate(capture, &downsampled_capture); |  | 
| 57 |  | 
| 58   matched_filter_.Update(downsampled_render, downsampled_capture); |  | 
| 59 | 54 | 
| 60   rtc::Optional<size_t> aggregated_matched_filter_lag = | 55   rtc::Optional<size_t> aggregated_matched_filter_lag = | 
| 61       matched_filter_lag_aggregator_.Aggregate( | 56       matched_filter_lag_aggregator_.Aggregate( | 
| 62           matched_filter_.GetLagEstimates()); | 57           matched_filter_.GetLagEstimates()); | 
| 63 | 58 | 
| 64   // TODO(peah): Move this logging outside of this class once EchoCanceller3 | 59   // TODO(peah): Move this logging outside of this class once EchoCanceller3 | 
| 65   // development is done. | 60   // development is done. | 
| 66   data_dumper_->DumpRaw("aec3_echo_path_delay_estimator_delay", | 61   data_dumper_->DumpRaw("aec3_echo_path_delay_estimator_delay", | 
| 67                         aggregated_matched_filter_lag | 62                         aggregated_matched_filter_lag | 
| 68                             ? static_cast<int>(*aggregated_matched_filter_lag * | 63                             ? static_cast<int>(*aggregated_matched_filter_lag * | 
| 69                                                kDownSamplingFactor) | 64                                                kDownSamplingFactor) | 
| 70                             : -1); | 65                             : -1); | 
| 71 | 66 | 
| 72   // Return the detected delay in samples as the aggregated matched filter lag | 67   // Return the detected delay in samples as the aggregated matched filter lag | 
| 73   // compensated by the down sampling factor for the signal being correlated. | 68   // compensated by the down sampling factor for the signal being correlated. | 
| 74   return aggregated_matched_filter_lag | 69   return aggregated_matched_filter_lag | 
| 75              ? rtc::Optional<size_t>(*aggregated_matched_filter_lag * | 70              ? rtc::Optional<size_t>(*aggregated_matched_filter_lag * | 
| 76                                      kDownSamplingFactor) | 71                                      kDownSamplingFactor) | 
| 77              : rtc::Optional<size_t>(); | 72              : rtc::Optional<size_t>(); | 
| 78 } | 73 } | 
| 79 | 74 | 
| 80 }  // namespace webrtc | 75 }  // namespace webrtc | 
| OLD | NEW | 
|---|