OLD | NEW |
---|---|
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 Loading... | |
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; | |
hlundin-webrtc
2016/11/16 09:46:30
How long until this converges to close enough to 1
ivoc
2016/11/16 12:30:38
After about a minute the reliability is at 0.9975
hlundin-webrtc
2016/11/17 08:14:45
Neither am I...
| |
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() { |
(...skipping 16 matching lines...) Expand all Loading... | |
129 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); | 132 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
130 | 133 |
131 packed_buffer->clear(); | 134 packed_buffer->clear(); |
132 packed_buffer->insert(packed_buffer->end(), | 135 packed_buffer->insert(packed_buffer->end(), |
133 audio->split_bands_const_f(0)[kBand0To8kHz], | 136 audio->split_bands_const_f(0)[kBand0To8kHz], |
134 (audio->split_bands_const_f(0)[kBand0To8kHz] + | 137 (audio->split_bands_const_f(0)[kBand0To8kHz] + |
135 audio->num_frames_per_band())); | 138 audio->num_frames_per_band())); |
136 } | 139 } |
137 | 140 |
138 } // namespace webrtc | 141 } // namespace webrtc |
OLD | NEW |