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

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

Issue 2503843004: Add a reliability term to the echo detector. (Closed)
Patch Set: Added function to set reliability directly for use in unittests. Created 4 years, 1 month 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/residual_echo_detector.h" 11 #include "webrtc/modules/audio_processing/residual_echo_detector.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <numeric> 14 #include <numeric>
15 15
16 #include "webrtc/modules/audio_processing/audio_buffer.h" 16 #include "webrtc/modules/audio_processing/audio_buffer.h"
17 #include "webrtc/system_wrappers/include/metrics.h" 17 #include "webrtc/system_wrappers/include/metrics.h"
18 18
19 namespace { 19 namespace {
20 20
21 float Power(rtc::ArrayView<const float> input) { 21 float Power(rtc::ArrayView<const float> input) {
22 return std::inner_product(input.begin(), input.end(), input.begin(), 0.f); 22 return std::inner_product(input.begin(), input.end(), input.begin(), 0.f);
23 } 23 }
24 24
25 constexpr size_t kLookbackFrames = 650; 25 constexpr size_t kLookbackFrames = 650;
26 // TODO(ivoc): Verify the size of this buffer. 26 // TODO(ivoc): Verify the size of this buffer.
27 constexpr size_t kRenderBufferSize = 30; 27 constexpr size_t kRenderBufferSize = 30;
28 constexpr float kAlpha = 0.001f;
28 29
29 } // namespace 30 } // namespace
30 31
31 namespace webrtc { 32 namespace webrtc {
32 33
33 ResidualEchoDetector::ResidualEchoDetector() 34 ResidualEchoDetector::ResidualEchoDetector()
34 : render_buffer_(kRenderBufferSize), 35 : render_buffer_(kRenderBufferSize),
35 render_power_(kLookbackFrames), 36 render_power_(kLookbackFrames),
36 render_power_mean_(kLookbackFrames), 37 render_power_mean_(kLookbackFrames),
37 render_power_std_dev_(kLookbackFrames), 38 render_power_std_dev_(kLookbackFrames),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 const size_t read_index = 94 const size_t read_index =
94 (kLookbackFrames + next_insertion_index_ - delay) % kLookbackFrames; 95 (kLookbackFrames + next_insertion_index_ - delay) % kLookbackFrames;
95 RTC_DCHECK_LT(read_index, render_power_.size()); 96 RTC_DCHECK_LT(read_index, render_power_.size());
96 covariances_[delay].Update(capture_power, capture_mean, 97 covariances_[delay].Update(capture_power, capture_mean,
97 capture_std_deviation, render_power_[read_index], 98 capture_std_deviation, render_power_[read_index],
98 render_power_mean_[read_index], 99 render_power_mean_[read_index],
99 render_power_std_dev_[read_index]); 100 render_power_std_dev_[read_index]);
100 echo_likelihood_ = std::max( 101 echo_likelihood_ = std::max(
101 echo_likelihood_, covariances_[delay].normalized_cross_correlation()); 102 echo_likelihood_, covariances_[delay].normalized_cross_correlation());
102 } 103 }
104 reliability_ = (1.0f - kAlpha) * reliability_ + kAlpha * 1.0f;
105 echo_likelihood_ *= reliability_;
103 int echo_percentage = static_cast<int>(echo_likelihood_ * 100); 106 int echo_percentage = static_cast<int>(echo_likelihood_ * 100);
104 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.ResidualEchoDetector.EchoLikelihood", 107 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.ResidualEchoDetector.EchoLikelihood",
105 echo_percentage, 0, 100, 100 /* number of bins */); 108 echo_percentage, 0, 100, 100 /* number of bins */);
106 109
107 // Update the next insertion index. 110 // Update the next insertion index.
108 ++next_insertion_index_; 111 ++next_insertion_index_;
109 next_insertion_index_ %= kLookbackFrames; 112 next_insertion_index_ %= kLookbackFrames;
110 } 113 }
111 114
112 void ResidualEchoDetector::Initialize() { 115 void ResidualEchoDetector::Initialize() {
113 render_buffer_.Clear(); 116 render_buffer_.Clear();
114 std::fill(render_power_.begin(), render_power_.end(), 0.f); 117 std::fill(render_power_.begin(), render_power_.end(), 0.f);
115 std::fill(render_power_mean_.begin(), render_power_mean_.end(), 0.f); 118 std::fill(render_power_mean_.begin(), render_power_mean_.end(), 0.f);
116 std::fill(render_power_std_dev_.begin(), render_power_std_dev_.end(), 0.f); 119 std::fill(render_power_std_dev_.begin(), render_power_std_dev_.end(), 0.f);
117 render_statistics_.Clear(); 120 render_statistics_.Clear();
118 capture_statistics_.Clear(); 121 capture_statistics_.Clear();
119 for (auto& cov : covariances_) { 122 for (auto& cov : covariances_) {
120 cov.Clear(); 123 cov.Clear();
121 } 124 }
122 echo_likelihood_ = 0.f; 125 echo_likelihood_ = 0.f;
123 next_insertion_index_ = 0; 126 next_insertion_index_ = 0;
127 reliability_ = 0.f;
124 } 128 }
125 129
126 void ResidualEchoDetector::PackRenderAudioBuffer( 130 void ResidualEchoDetector::PackRenderAudioBuffer(
127 AudioBuffer* audio, 131 AudioBuffer* audio,
128 std::vector<float>* packed_buffer) { 132 std::vector<float>* packed_buffer) {
129 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); 133 RTC_DCHECK_GE(160u, audio->num_frames_per_band());
130 134
131 packed_buffer->clear(); 135 packed_buffer->clear();
132 packed_buffer->insert(packed_buffer->end(), 136 packed_buffer->insert(packed_buffer->end(),
133 audio->split_bands_const_f(0)[kBand0To8kHz], 137 audio->split_bands_const_f(0)[kBand0To8kHz],
134 (audio->split_bands_const_f(0)[kBand0To8kHz] + 138 (audio->split_bands_const_f(0)[kBand0To8kHz] +
135 audio->num_frames_per_band())); 139 audio->num_frames_per_band()));
136 } 140 }
137 141
138 } // namespace webrtc 142 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698