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

Side by Side Diff: webrtc/modules/audio_processing/echo_detector/echo_detector.cc

Issue 2419563003: Add algorithm for Residual Echo Detector. (Closed)
Patch Set: Added unittests and some small changes. Created 4 years, 2 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) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 10
11 #include "webrtc/modules/audio_processing/echo_detector/echo_detector.h" 11 #include "webrtc/modules/audio_processing/echo_detector/echo_detector.h"
12 12
13 #include <algorithm>
14 #include <numeric>
15
16 namespace {
17
18 float Power(const rtc::ArrayView<const float>& input) {
hlundin-webrtc 2016/10/17 18:49:40 Pass the ArrayView by value, not as ref.
ivoc 2016/10/18 15:20:19 Done.
19 return std::inner_product(input.begin(), input.end(), input.begin(), 0.f);
20 }
21
22 } // namespace
23
13 namespace webrtc { 24 namespace webrtc {
14 25
15 void EchoDetector::BufferFarend(const rtc::ArrayView<const float>& /*farend*/) { 26 EchoDetector::EchoDetector() = default;
16 // TODO(ivoc): Add implementation. 27
17 RTC_NOTREACHED(); 28 EchoDetector::~EchoDetector() = default;
29
30 constexpr size_t EchoDetector::kLookbackFrames;
31 constexpr size_t EchoDetector::kRenderBufferSize;
32
33 void EchoDetector::BufferRender(const rtc::ArrayView<const float>& render) {
34 float power = Power(render);
35 render_buffer_.Insert(power);
18 } 36 }
19 37
20 void EchoDetector::Process(const rtc::ArrayView<const float>& /*nearend*/) { 38 void EchoDetector::Process(const rtc::ArrayView<const float>& nearend) {
21 // TODO(ivoc): Add implementation. 39 const float capture_power = Power(nearend);
22 RTC_NOTREACHED(); 40 capture_variance_.UpdateEstimate(capture_power);
41 const float capture_mean = capture_variance_.mean();
42 const float capture_std_deviation = capture_variance_.std_deviation();
43 echo_likelihood_ = 0.f;
44
45 const float latest_render_power = render_buffer_.GetValue();
46 render_variance_.UpdateEstimate(latest_render_power);
47 render_power_[next_insertion_index_] = latest_render_power;
48 render_power_mean_[next_insertion_index_] = render_variance_.mean();
49 render_power_std_dev_[next_insertion_index_] =
50 render_variance_.std_deviation();
51 for (size_t delay = 0; delay < covariance_.size(); ++delay) {
52 const size_t read_index =
53 (kLookbackFrames + next_insertion_index_ - delay) % kLookbackFrames;
54 RTC_DCHECK_LT(read_index, render_power_.size());
55 const float render_power = render_power_[read_index];
56 const float render_mean = render_power_mean_[read_index];
57 const float render_std_dev = render_power_std_dev_[read_index];
58 covariance_[delay].UpdateCovarianceEstimate(
59 capture_power, capture_mean, capture_std_deviation, render_power,
60 render_mean, render_std_dev);
61 echo_likelihood_ = std::max(
62 echo_likelihood_, covariance_[delay].normalized_cross_correlation());
63 }
64 // Update the next insertion index.
65 ++next_insertion_index_;
66 next_insertion_index_ %= kLookbackFrames;
67 RTC_DCHECK_LT(next_insertion_index_, kLookbackFrames);
hlundin-webrtc 2016/10/17 18:49:40 DCHECKing immediately after the modulo is maybe no
ivoc 2016/10/18 15:20:19 Good idea.
23 } 68 }
24 69
25 void EchoDetector::Initialize(int /*sample_rate_hz*/) { 70 void EchoDetector::Initialize() {
26 // TODO(ivoc): Add implementation. 71 render_buffer_.Clear();
27 RTC_NOTREACHED(); 72 std::fill(render_power_.begin(), render_power_.end(), 0.f);
73 std::fill(render_power_mean_.begin(), render_power_mean_.end(), 0.f);
74 std::fill(render_power_std_dev_.begin(), render_power_std_dev_.end(), 0.f);
75 render_variance_.Clear();
76 capture_variance_.Clear();
77 for (auto& cov : covariance_) {
78 cov.Clear();
79 }
80 echo_likelihood_ = 0.f;
81 next_insertion_index_ = 0;
28 } 82 }
29 83
30 } // namespace webrtc 84 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698