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 "webrtc/base/checks.h" | 12 #include <algorithm> |
hlundin-webrtc
2017/02/01 08:30:02
You are still using checks. Don't delete this.
peah-webrtc
2017/02/02 14:04:47
Done.
| |
13 | |
13 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" | 14 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" |
14 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | 15 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
15 | 16 |
16 namespace webrtc { | 17 namespace webrtc { |
17 | 18 |
18 // TODO(peah): Add functionality. | 19 namespace { |
20 | |
21 constexpr size_t kNumCorrelatorAlignmentShifts = 3; | |
22 constexpr size_t kCorrelatorWindowSizeSubBlocks = 32; | |
23 constexpr size_t kCorrelatorAlignmentShiftSizeSubBlocks = | |
24 kCorrelatorWindowSizeSubBlocks * 3 / 4; | |
25 | |
26 } // namespace | |
27 | |
19 EchoPathDelayEstimator::EchoPathDelayEstimator(ApmDataDumper* data_dumper, | 28 EchoPathDelayEstimator::EchoPathDelayEstimator(ApmDataDumper* data_dumper, |
20 int sample_rate_hz) { | 29 int sample_rate_hz) |
30 : data_dumper_(data_dumper), | |
31 render_down_sampler_(sample_rate_hz), | |
32 capture_down_sampler_(sample_rate_hz), | |
33 down_sampling_factor_(capture_down_sampler_.GetDownSamplingFactor()), | |
hlundin-webrtc
2017/02/01 08:30:02
Can't you call capture_down_sampler_.GetDownSampli
peah-webrtc
2017/02/02 14:04:47
I refactored it a bit. PTAL
| |
34 correlator_(data_dumper_, | |
35 kCorrelatorWindowSizeSubBlocks, | |
36 kNumCorrelatorAlignmentShifts, | |
37 kCorrelatorAlignmentShiftSizeSubBlocks), | |
38 correlator_lag_aggregator_(data_dumper_, correlator_.NumLagEstimates()) { | |
21 RTC_DCHECK(data_dumper); | 39 RTC_DCHECK(data_dumper); |
22 RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 || | 40 RTC_DCHECK(ValidFullBandRate(sample_rate_hz)); |
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 float downsampled_render[kSubBlockSize]; | |
52 float downsampled_capture[kSubBlockSize]; | |
53 | |
54 render_down_sampler_.DownSample(render, downsampled_render); | |
55 capture_down_sampler_.DownSample(capture, downsampled_capture); | |
56 | |
57 correlator_.Update(downsampled_render, downsampled_capture); | |
58 | |
59 rtc::Optional<size_t> aggregated_correlator_lag = | |
60 correlator_lag_aggregator_.Aggregate(correlator_.GetLagEstimates()); | |
61 | |
62 // TODO(peah): Move this logging outside of this class once EchoCanceller3 | |
63 // development is done. | |
64 data_dumper_->DumpRaw( | |
65 "aec3_echo_path_delay_estimator_delay", | |
66 aggregated_correlator_lag | |
67 ? static_cast<int>(*aggregated_correlator_lag * down_sampling_factor_) | |
68 : -1); | |
69 | |
70 // Return the detected delay in samples as the aggregated correlator lag | |
71 // compensated by the down sampling factor for the signal being correlated. | |
72 return aggregated_correlator_lag | |
73 ? rtc::Optional<size_t>(*aggregated_correlator_lag * | |
74 down_sampling_factor_) | |
75 : rtc::Optional<size_t>(); | |
35 } | 76 } |
36 | 77 |
37 } // namespace webrtc | 78 } // namespace webrtc |
OLD | NEW |