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