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 <vector>
15 
16 #include "api/optional.h"
17 #include "modules/audio_processing/aec3/decimator.h"
18 #include "modules/audio_processing/aec3/downsampled_render_buffer.h"
19 #include "modules/audio_processing/aec3/matched_filter.h"
20 #include "modules/audio_processing/aec3/matched_filter_lag_aggregator.h"
21 #include "modules/audio_processing/include/audio_processing.h"
22 #include "rtc_base/constructormagic.h"
23 
24 namespace webrtc {
25 
26 class ApmDataDumper;
27 
28 // Estimates the delay of the echo path.
29 class EchoPathDelayEstimator {
30  public:
31   EchoPathDelayEstimator(ApmDataDumper* data_dumper,
32                          const EchoCanceller3Config& config);
33   ~EchoPathDelayEstimator();
34 
35   // Resets the estimation.
36   void Reset();
37 
38   // Produce a delay estimate if such is avaliable.
39   rtc::Optional<size_t> EstimateDelay(
40       const DownsampledRenderBuffer& render_buffer,
41       rtc::ArrayView<const float> capture);
42 
43   // Log delay estimator properties.
LogDelayEstimationProperties(int sample_rate_hz,size_t shift)44   void LogDelayEstimationProperties(int sample_rate_hz, size_t shift) const {
45     matched_filter_.LogFilterProperties(sample_rate_hz, shift,
46                                         down_sampling_factor_);
47   }
48 
49  private:
50   ApmDataDumper* const data_dumper_;
51   const size_t down_sampling_factor_;
52   const size_t sub_block_size_;
53   Decimator capture_decimator_;
54   MatchedFilter matched_filter_;
55   MatchedFilterLagAggregator matched_filter_lag_aggregator_;
56 
57   RTC_DISALLOW_COPY_AND_ASSIGN(EchoPathDelayEstimator);
58 };
59 }  // namespace webrtc
60 
61 #endif  // MODULES_AUDIO_PROCESSING_AEC3_ECHO_PATH_DELAY_ESTIMATOR_H_
62