Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc

Issue 2644123002: Adding full initial version of delay estimation functionality in echo canceller 3 (Closed)
Patch Set: Changes in response to reviewer comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {
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;
30 } // namespace
31
19 EchoPathDelayEstimator::EchoPathDelayEstimator(ApmDataDumper* data_dumper, 32 EchoPathDelayEstimator::EchoPathDelayEstimator(ApmDataDumper* data_dumper,
20 int sample_rate_hz) { 33 int sample_rate_hz)
34 : data_dumper_(data_dumper),
35 matched_filter_(data_dumper_,
36 kMatchedFilterWindowSizeSubBlocks,
37 kNumMatchedFilters,
38 kMatchedFilterAlignmentShiftSizeSubBlocks),
39 matched_filter_lag_aggregator_(data_dumper_,
40 matched_filter_.NumLagEstimates()) {
21 RTC_DCHECK(data_dumper); 41 RTC_DCHECK(data_dumper);
22 RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 || 42 RTC_DCHECK(ValidFullBandRate(sample_rate_hz));
23 sample_rate_hz == 32000 || sample_rate_hz == 48000);
24 } 43 }
25 44
26 EchoPathDelayEstimator::~EchoPathDelayEstimator() = default; 45 EchoPathDelayEstimator::~EchoPathDelayEstimator() = default;
27 46
28 // TODO(peah): Add functionality.
29 rtc::Optional<size_t> EchoPathDelayEstimator::EstimateDelay( 47 rtc::Optional<size_t> EchoPathDelayEstimator::EstimateDelay(
30 rtc::ArrayView<const float> render, 48 rtc::ArrayView<const float> render,
31 rtc::ArrayView<const float> capture) { 49 rtc::ArrayView<const float> capture) {
32 RTC_DCHECK_EQ(render.size(), kBlockSize); 50 RTC_DCHECK_EQ(kBlockSize, capture.size());
33 RTC_DCHECK_EQ(capture.size(), kBlockSize); 51 RTC_DCHECK_EQ(render.size(), capture.size());
34 return rtc::Optional<size_t>(); 52
53 std::array<float, kSubBlockSize> downsampled_render;
54 std::array<float, kSubBlockSize> downsampled_capture;
55
56 render_decimator_.Decimate(render, &downsampled_render);
57 capture_decimator_.Decimate(capture, &downsampled_capture);
58
59 matched_filter_.Update(downsampled_render, downsampled_capture);
60
61 rtc::Optional<size_t> aggregated_matched_filter_lag =
62 matched_filter_lag_aggregator_.Aggregate(
63 matched_filter_.GetLagEstimates());
64
65 // TODO(peah): Move this logging outside of this class once EchoCanceller3
66 // development is done.
67 data_dumper_->DumpRaw("aec3_echo_path_delay_estimator_delay",
68 aggregated_matched_filter_lag
69 ? static_cast<int>(*aggregated_matched_filter_lag *
70 kDownSamplingFactor)
71 : -1);
72
73 // Return the detected delay in samples as the aggregated matched filter lag
74 // compensated by the down sampling factor for the signal being correlated.
75 return aggregated_matched_filter_lag
76 ? rtc::Optional<size_t>(*aggregated_matched_filter_lag *
77 kDownSamplingFactor)
78 : rtc::Optional<size_t>();
35 } 79 }
36 80
37 } // namespace webrtc 81 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698