| 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 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 float Power(rtc::ArrayView<const float> input) { | 21 float Power(rtc::ArrayView<const float> input) { |
| 21 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); |
| 22 } | 23 } |
| 23 | 24 |
| 24 constexpr size_t kLookbackFrames = 650; | 25 constexpr size_t kLookbackFrames = 650; |
| 25 // TODO(ivoc): Verify the size of this buffer. | 26 // TODO(ivoc): Verify the size of this buffer. |
| 26 constexpr size_t kRenderBufferSize = 30; | 27 constexpr size_t kRenderBufferSize = 30; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 const size_t read_index = | 93 const size_t read_index = |
| 93 (kLookbackFrames + next_insertion_index_ - delay) % kLookbackFrames; | 94 (kLookbackFrames + next_insertion_index_ - delay) % kLookbackFrames; |
| 94 RTC_DCHECK_LT(read_index, render_power_.size()); | 95 RTC_DCHECK_LT(read_index, render_power_.size()); |
| 95 covariances_[delay].Update(capture_power, capture_mean, | 96 covariances_[delay].Update(capture_power, capture_mean, |
| 96 capture_std_deviation, render_power_[read_index], | 97 capture_std_deviation, render_power_[read_index], |
| 97 render_power_mean_[read_index], | 98 render_power_mean_[read_index], |
| 98 render_power_std_dev_[read_index]); | 99 render_power_std_dev_[read_index]); |
| 99 echo_likelihood_ = std::max( | 100 echo_likelihood_ = std::max( |
| 100 echo_likelihood_, covariances_[delay].normalized_cross_correlation()); | 101 echo_likelihood_, covariances_[delay].normalized_cross_correlation()); |
| 101 } | 102 } |
| 103 int echo_percentage = static_cast<int>(echo_likelihood_ * 100); |
| 104 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.ResidualEchoDetector.EchoLikelihood", |
| 105 echo_percentage, 0, 100, 100 /* number of bins */); |
| 102 | 106 |
| 103 // Update the next insertion index. | 107 // Update the next insertion index. |
| 104 ++next_insertion_index_; | 108 ++next_insertion_index_; |
| 105 next_insertion_index_ %= kLookbackFrames; | 109 next_insertion_index_ %= kLookbackFrames; |
| 106 } | 110 } |
| 107 | 111 |
| 108 void ResidualEchoDetector::Initialize() { | 112 void ResidualEchoDetector::Initialize() { |
| 109 render_buffer_.Clear(); | 113 render_buffer_.Clear(); |
| 110 std::fill(render_power_.begin(), render_power_.end(), 0.f); | 114 std::fill(render_power_.begin(), render_power_.end(), 0.f); |
| 111 std::fill(render_power_mean_.begin(), render_power_mean_.end(), 0.f); | 115 std::fill(render_power_mean_.begin(), render_power_mean_.end(), 0.f); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 125 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); | 129 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
| 126 | 130 |
| 127 packed_buffer->clear(); | 131 packed_buffer->clear(); |
| 128 packed_buffer->insert(packed_buffer->end(), | 132 packed_buffer->insert(packed_buffer->end(), |
| 129 audio->split_bands_const_f(0)[kBand0To8kHz], | 133 audio->split_bands_const_f(0)[kBand0To8kHz], |
| 130 (audio->split_bands_const_f(0)[kBand0To8kHz] + | 134 (audio->split_bands_const_f(0)[kBand0To8kHz] + |
| 131 audio->num_frames_per_band())); | 135 audio->num_frames_per_band())); |
| 132 } | 136 } |
| 133 | 137 |
| 134 } // namespace webrtc | 138 } // namespace webrtc |
| OLD | NEW |