| 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 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 // Get the next capture value, update capture statistics and add the relevant | 87 // Get the next capture value, update capture statistics and add the relevant |
| 88 // values to the buffers. | 88 // values to the buffers. |
| 89 const float capture_power = Power(capture_audio); | 89 const float capture_power = Power(capture_audio); |
| 90 capture_statistics_.Update(capture_power); | 90 capture_statistics_.Update(capture_power); |
| 91 const float capture_mean = capture_statistics_.mean(); | 91 const float capture_mean = capture_statistics_.mean(); |
| 92 const float capture_std_deviation = capture_statistics_.std_deviation(); | 92 const float capture_std_deviation = capture_statistics_.std_deviation(); |
| 93 | 93 |
| 94 // Update the covariance values and determine the new echo likelihood. | 94 // Update the covariance values and determine the new echo likelihood. |
| 95 echo_likelihood_ = 0.f; | 95 echo_likelihood_ = 0.f; |
| 96 size_t read_index = next_insertion_index_; |
| 96 for (size_t delay = 0; delay < covariances_.size(); ++delay) { | 97 for (size_t delay = 0; delay < covariances_.size(); ++delay) { |
| 97 const size_t read_index = | |
| 98 (kLookbackFrames + next_insertion_index_ - delay) % kLookbackFrames; | |
| 99 RTC_DCHECK_LT(read_index, render_power_.size()); | 98 RTC_DCHECK_LT(read_index, render_power_.size()); |
| 100 covariances_[delay].Update(capture_power, capture_mean, | 99 covariances_[delay].Update(capture_power, capture_mean, |
| 101 capture_std_deviation, render_power_[read_index], | 100 capture_std_deviation, render_power_[read_index], |
| 102 render_power_mean_[read_index], | 101 render_power_mean_[read_index], |
| 103 render_power_std_dev_[read_index]); | 102 render_power_std_dev_[read_index]); |
| 104 echo_likelihood_ = std::max( | 103 echo_likelihood_ = std::max( |
| 105 echo_likelihood_, covariances_[delay].normalized_cross_correlation()); | 104 echo_likelihood_, covariances_[delay].normalized_cross_correlation()); |
| 105 |
| 106 read_index = read_index > 0 ? read_index - 1 : kLookbackFrames - 1; |
| 106 } | 107 } |
| 107 reliability_ = (1.0f - kAlpha) * reliability_ + kAlpha * 1.0f; | 108 reliability_ = (1.0f - kAlpha) * reliability_ + kAlpha * 1.0f; |
| 108 echo_likelihood_ *= reliability_; | 109 echo_likelihood_ *= reliability_; |
| 109 // This is a temporary fix to prevent echo likelihood values > 1.0. | 110 // This is a temporary fix to prevent echo likelihood values > 1.0. |
| 110 // TODO(ivoc): Find the root cause of this issue and fix it. | 111 // TODO(ivoc): Find the root cause of this issue and fix it. |
| 111 echo_likelihood_ = std::min(echo_likelihood_, 1.0f); | 112 echo_likelihood_ = std::min(echo_likelihood_, 1.0f); |
| 112 int echo_percentage = static_cast<int>(echo_likelihood_ * 100); | 113 int echo_percentage = static_cast<int>(echo_likelihood_ * 100); |
| 113 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.ResidualEchoDetector.EchoLikelihood", | 114 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.ResidualEchoDetector.EchoLikelihood", |
| 114 echo_percentage, 0, 100, 100 /* number of bins */); | 115 echo_percentage, 0, 100, 100 /* number of bins */); |
| 115 | 116 |
| 116 // Update the buffer of recent likelihood values. | 117 // Update the buffer of recent likelihood values. |
| 117 recent_likelihood_max_.Update(echo_likelihood_); | 118 recent_likelihood_max_.Update(echo_likelihood_); |
| 118 | 119 |
| 119 // Update the next insertion index. | 120 // Update the next insertion index. |
| 120 ++next_insertion_index_; | 121 next_insertion_index_ = next_insertion_index_ < (kLookbackFrames - 1) |
| 121 next_insertion_index_ %= kLookbackFrames; | 122 ? next_insertion_index_ + 1 |
| 123 : 0; |
| 122 } | 124 } |
| 123 | 125 |
| 124 void ResidualEchoDetector::Initialize() { | 126 void ResidualEchoDetector::Initialize() { |
| 125 render_buffer_.Clear(); | 127 render_buffer_.Clear(); |
| 126 std::fill(render_power_.begin(), render_power_.end(), 0.f); | 128 std::fill(render_power_.begin(), render_power_.end(), 0.f); |
| 127 std::fill(render_power_mean_.begin(), render_power_mean_.end(), 0.f); | 129 std::fill(render_power_mean_.begin(), render_power_mean_.end(), 0.f); |
| 128 std::fill(render_power_std_dev_.begin(), render_power_std_dev_.end(), 0.f); | 130 std::fill(render_power_std_dev_.begin(), render_power_std_dev_.end(), 0.f); |
| 129 render_statistics_.Clear(); | 131 render_statistics_.Clear(); |
| 130 capture_statistics_.Clear(); | 132 capture_statistics_.Clear(); |
| 131 recent_likelihood_max_.Clear(); | 133 recent_likelihood_max_.Clear(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 143 RTC_DCHECK_GE(160, audio->num_frames_per_band()); | 145 RTC_DCHECK_GE(160, audio->num_frames_per_band()); |
| 144 | 146 |
| 145 packed_buffer->clear(); | 147 packed_buffer->clear(); |
| 146 packed_buffer->insert(packed_buffer->end(), | 148 packed_buffer->insert(packed_buffer->end(), |
| 147 audio->split_bands_const_f(0)[kBand0To8kHz], | 149 audio->split_bands_const_f(0)[kBand0To8kHz], |
| 148 (audio->split_bands_const_f(0)[kBand0To8kHz] + | 150 (audio->split_bands_const_f(0)[kBand0To8kHz] + |
| 149 audio->num_frames_per_band())); | 151 audio->num_frames_per_band())); |
| 150 } | 152 } |
| 151 | 153 |
| 152 } // namespace webrtc | 154 } // namespace webrtc |
| OLD | NEW |