1 /* 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_PROCESSING_AEC3_ECHO_PATH_DELAY_ESTIMATOR_H_ 12 #define MODULES_AUDIO_PROCESSING_AEC3_ECHO_PATH_DELAY_ESTIMATOR_H_ 13 14 #include <stddef.h> 15 16 #include "absl/types/optional.h" 17 #include "api/array_view.h" 18 #include "modules/audio_processing/aec3/alignment_mixer.h" 19 #include "modules/audio_processing/aec3/clockdrift_detector.h" 20 #include "modules/audio_processing/aec3/decimator.h" 21 #include "modules/audio_processing/aec3/delay_estimate.h" 22 #include "modules/audio_processing/aec3/matched_filter.h" 23 #include "modules/audio_processing/aec3/matched_filter_lag_aggregator.h" 24 #include "rtc_base/constructor_magic.h" 25 26 namespace webrtc { 27 28 class ApmDataDumper; 29 struct DownsampledRenderBuffer; 30 struct EchoCanceller3Config; 31 32 // Estimates the delay of the echo path. 33 class EchoPathDelayEstimator { 34 public: 35 EchoPathDelayEstimator(ApmDataDumper* data_dumper, 36 const EchoCanceller3Config& config, 37 size_t num_capture_channels); 38 ~EchoPathDelayEstimator(); 39 40 // Resets the estimation. If the delay confidence is reset, the reset behavior 41 // is as if the call is restarted. 42 void Reset(bool reset_delay_confidence); 43 44 // Produce a delay estimate if such is avaliable. 45 absl::optional<DelayEstimate> EstimateDelay( 46 const DownsampledRenderBuffer& render_buffer, 47 const std::vector<std::vector<float>>& capture); 48 49 // Log delay estimator properties. LogDelayEstimationProperties(int sample_rate_hz,size_t shift)50 void LogDelayEstimationProperties(int sample_rate_hz, size_t shift) const { 51 matched_filter_.LogFilterProperties(sample_rate_hz, shift, 52 down_sampling_factor_); 53 } 54 55 // Returns the level of detected clockdrift. Clockdrift()56 ClockdriftDetector::Level Clockdrift() const { 57 return clockdrift_detector_.ClockdriftLevel(); 58 } 59 60 private: 61 ApmDataDumper* const data_dumper_; 62 const size_t down_sampling_factor_; 63 const size_t sub_block_size_; 64 AlignmentMixer capture_mixer_; 65 Decimator capture_decimator_; 66 MatchedFilter matched_filter_; 67 MatchedFilterLagAggregator matched_filter_lag_aggregator_; 68 absl::optional<DelayEstimate> old_aggregated_lag_; 69 size_t consistent_estimate_counter_ = 0; 70 ClockdriftDetector clockdrift_detector_; 71 72 // Internal reset method with more granularity. 73 void Reset(bool reset_lag_aggregator, bool reset_delay_confidence); 74 75 RTC_DISALLOW_COPY_AND_ASSIGN(EchoPathDelayEstimator); 76 }; 77 } // namespace webrtc 78 79 #endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_PATH_DELAY_ESTIMATOR_H_ 80