Index: webrtc/modules/audio_processing/aec3/delay_handler.cc |
diff --git a/webrtc/modules/audio_processing/aec3/delay_handler.cc b/webrtc/modules/audio_processing/aec3/delay_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..de5eed771999696b4becf675f5b8ad3c9448beff |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/aec3/delay_handler.cc |
@@ -0,0 +1,69 @@ |
+/* |
+ * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "webrtc/modules/audio_processing/aec3/delay_handler.h" |
+ |
+#include "webrtc/base/checks.h" |
+#include "webrtc/modules/audio_processing/aec3/aec3_constants.h" |
+ |
+namespace webrtc { |
+namespace { |
+ |
+// Compute the delay of the adaptive filter as the partition with a distinct |
+// peak. |
+rtc::Optional<size_t> IdentifyFilterDelay( |
+ const std::vector<std::array<float, kFftLengthBy2Plus1>>& |
+ filter_frequency_response) { |
+ const std::vector<std::array<float, kFftLengthBy2Plus1>>& H2 = |
ivoc
2017/02/10 13:52:34
I would prefer const auto& here.
peah-webrtc
2017/02/20 07:37:15
Done.
|
+ filter_frequency_response; |
+ |
+ size_t reliable_delays_sum = 0; |
+ size_t num_reliable_delays = 0; |
+ |
+ for (size_t k = 1; k < kFftLengthBy2 - 5; ++k) { |
ivoc
2017/02/10 13:52:34
Why is the "- 5" here?
peah-webrtc
2017/02/20 07:37:15
The intention is that there is no point computing
|
+ int peak = 0; |
+ for (size_t j = 0; j < H2.size(); ++j) { |
+ if (H2[j][k] > H2[peak][k]) { |
+ peak = j; |
+ } |
+ } |
+ |
+ if (5 * H2[H2.size() - 1][k] < H2[peak][k]) { |
ivoc
2017/02/10 13:52:34
Please define the 5 as a constexpr.
peah-webrtc
2017/02/20 07:37:15
Done.
|
+ reliable_delays_sum += peak; |
+ ++num_reliable_delays; |
+ } |
+ } |
+ |
+ return num_reliable_delays > 5 |
ivoc
2017/02/10 13:52:34
This 5 as well.
peah-webrtc
2017/02/20 07:37:15
Done.
|
+ ? rtc::Optional<size_t>(reliable_delays_sum / num_reliable_delays) |
+ : rtc::Optional<size_t>(); |
+} |
+ |
+} // namespace |
+ |
+DelayHandler::DelayHandler() = default; |
+ |
+DelayHandler::~DelayHandler() = default; |
+ |
+void DelayHandler::UpdateDelays( |
+ const std::vector<std::array<float, kFftLengthBy2Plus1>>& |
+ filter_frequency_response, |
+ const rtc::Optional<size_t>& external_delay_samples) { |
+ filter_delay_ = IdentifyFilterDelay(filter_frequency_response); |
+ |
+ // Compute the externally provided delay in partitions. The truncation is |
+ // intended here. |
+ external_delay_ = |
+ external_delay_samples |
+ ? rtc::Optional<size_t>(*external_delay_samples / kBlockSize) |
+ : rtc::Optional<size_t>(); |
+} |
+ |
+} // namespace webrtc |