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/echo_detector/normalized_covariance_es
timator.h" | 11 #include "webrtc/modules/audio_processing/echo_detector/normalized_covariance_es
timator.h" |
12 | 12 |
13 #include <math.h> | 13 #include <math.h> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/rtc_base/checks.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Parameter controlling the adaptation speed. | 20 // Parameter controlling the adaptation speed. |
21 constexpr float kAlpha = 0.001f; | 21 constexpr float kAlpha = 0.001f; |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 void NormalizedCovarianceEstimator::Update(float x, | 25 void NormalizedCovarianceEstimator::Update(float x, |
26 float x_mean, | 26 float x_mean, |
27 float x_sigma, | 27 float x_sigma, |
28 float y, | 28 float y, |
29 float y_mean, | 29 float y_mean, |
30 float y_sigma) { | 30 float y_sigma) { |
31 covariance_ = | 31 covariance_ = |
32 (1.f - kAlpha) * covariance_ + kAlpha * (x - x_mean) * (y - y_mean); | 32 (1.f - kAlpha) * covariance_ + kAlpha * (x - x_mean) * (y - y_mean); |
33 normalized_cross_correlation_ = covariance_ / (x_sigma * y_sigma + .0001f); | 33 normalized_cross_correlation_ = covariance_ / (x_sigma * y_sigma + .0001f); |
34 RTC_DCHECK(isfinite(covariance_)); | 34 RTC_DCHECK(isfinite(covariance_)); |
35 RTC_DCHECK(isfinite(normalized_cross_correlation_)); | 35 RTC_DCHECK(isfinite(normalized_cross_correlation_)); |
36 } | 36 } |
37 | 37 |
38 void NormalizedCovarianceEstimator::Clear() { | 38 void NormalizedCovarianceEstimator::Clear() { |
39 covariance_ = 0.f; | 39 covariance_ = 0.f; |
40 normalized_cross_correlation_ = 0.f; | 40 normalized_cross_correlation_ = 0.f; |
41 } | 41 } |
42 | 42 |
43 } // namespace webrtc | 43 } // namespace webrtc |
OLD | NEW |