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

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

Issue 2678423005: Finalization of the first version of EchoCanceller 3 (Closed)
Patch Set: 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
(Empty)
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 #include "webrtc/modules/audio_processing/aec3/delay_handler.h"
12
13 #include "webrtc/base/checks.h"
14 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h"
15
16 namespace webrtc {
17 namespace {
18
19 // Compute the delay of the adaptive filter as the partition with a distinct
20 // peak.
21 rtc::Optional<size_t> IdentifyFilterDelay(
22 const std::vector<std::array<float, kFftLengthBy2Plus1>>&
23 filter_frequency_response) {
24 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.
25 filter_frequency_response;
26
27 size_t reliable_delays_sum = 0;
28 size_t num_reliable_delays = 0;
29
30 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
31 int peak = 0;
32 for (size_t j = 0; j < H2.size(); ++j) {
33 if (H2[j][k] > H2[peak][k]) {
34 peak = j;
35 }
36 }
37
38 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.
39 reliable_delays_sum += peak;
40 ++num_reliable_delays;
41 }
42 }
43
44 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.
45 ? rtc::Optional<size_t>(reliable_delays_sum / num_reliable_delays)
46 : rtc::Optional<size_t>();
47 }
48
49 } // namespace
50
51 DelayHandler::DelayHandler() = default;
52
53 DelayHandler::~DelayHandler() = default;
54
55 void DelayHandler::UpdateDelays(
56 const std::vector<std::array<float, kFftLengthBy2Plus1>>&
57 filter_frequency_response,
58 const rtc::Optional<size_t>& external_delay_samples) {
59 filter_delay_ = IdentifyFilterDelay(filter_frequency_response);
60
61 // Compute the externally provided delay in partitions. The truncation is
62 // intended here.
63 external_delay_ =
64 external_delay_samples
65 ? rtc::Optional<size_t>(*external_delay_samples / kBlockSize)
66 : rtc::Optional<size_t>();
67 }
68
69 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698