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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_ECHO_DETECTOR_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_ECHO_DETECTOR_H_ |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_ECHO_DETECTOR_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_ECHO_DETECTOR_H_ |
13 | 13 |
14 #include <stddef.h> | 14 #include <stddef.h> |
15 #include <vector> | |
15 | 16 |
16 namespace webrtc { | 17 namespace webrtc { |
17 | 18 |
19 // This class iteratively estimates the mean and variance of a signal. | |
20 class MeanVarianceEstimator { | |
hlundin-webrtc
2016/10/14 08:00:39
This and the two next classes are an internal matt
ivoc
2016/10/17 16:05:08
Ok, I will move each to its own file.
| |
21 public: | |
22 void UpdateEstimate(float value); | |
23 float SigmaEstimate(); | |
hlundin-webrtc
2016/10/14 08:00:40
const method
hlundin-webrtc
2016/10/14 08:00:40
This is almost an accessor method; you can name it
peah-webrtc
2016/10/14 08:18:58
const
ivoc
2016/10/17 16:05:08
Done, I went with std_deviation (without estimate)
| |
24 float MeanEstimate(); | |
hlundin-webrtc
2016/10/14 08:00:40
This is a simple accessor method => float mean() c
peah-webrtc
2016/10/14 08:18:58
const
ivoc
2016/10/17 16:05:08
Done.
| |
25 void Clear(); | |
26 | |
27 private: | |
28 // Estimate of the expected value of the input values. | |
29 float mean_ = 0.f; | |
30 // Estimate of the variance of the input values. | |
31 float variance_ = 0.f; | |
32 // Parameter controlling the adaptation speed. | |
33 static constexpr float alpha_ = 0.01f; | |
hlundin-webrtc
2016/10/14 08:00:40
static const members should go before variable mem
ivoc
2016/10/17 16:05:08
Done.
| |
34 }; | |
35 | |
36 // This class iteratively estimates the covariance between two signals. | |
37 class CovarianceEstimator { | |
38 public: | |
39 void UpdateCovarianceEstimate(float x, | |
40 float x_mean, | |
41 float x_var, | |
42 float y, | |
43 float y_mean, | |
44 float y_var); | |
45 float PCCEstimate(); | |
hlundin-webrtc
2016/10/14 08:00:39
float pcc() const { return pcc_; }
hlundin-webrtc
2016/10/14 08:00:40
Comment, so that the reader understands what PCC m
ivoc
2016/10/17 16:05:08
Done.
| |
46 void Clear(); | |
47 | |
48 private: | |
49 // Estimate of the Pearson product-moment correlation coefficient of the two | |
50 // signals. | |
51 float PCC_ = 0.f; | |
hlundin-webrtc
2016/10/14 08:00:39
pcc_
ivoc
2016/10/17 16:05:08
I renamed this to normalized_cross_correlation_, f
| |
52 // Estimate of the covariance value. | |
53 float covariance_ = 0.f; | |
54 // Parameter controlling the adaptation speed. | |
55 static constexpr float alpha_ = 0.01f; | |
hlundin-webrtc
2016/10/14 08:00:39
Same comments as above: move up and rename to kAlp
ivoc
2016/10/17 16:05:08
Done.
| |
56 }; | |
57 | |
58 // Ring buffer containing floating point values. | |
59 struct CircularBuffer { | |
60 public: | |
61 CircularBuffer(int size); | |
hlundin-webrtc
2016/10/14 08:00:39
explicit
hlundin-webrtc
2016/10/14 08:00:40
size_t size
ivoc
2016/10/17 16:05:08
Done.
| |
62 ~CircularBuffer(); | |
63 | |
64 void Insert(float value); | |
65 float GetValue(int delay); | |
66 void Clear(); | |
67 | |
68 private: | |
69 std::vector<float> buffer_; | |
70 const int size_; | |
hlundin-webrtc
2016/10/14 08:00:39
const size_t
peah-webrtc
2016/10/14 08:18:58
You don't need the size_ constant. Use buffer_.siz
ivoc
2016/10/17 16:05:08
I thought it would be more efficient to store it t
| |
71 int next_insertion_index_ = 0; | |
hlundin-webrtc
2016/10/14 08:00:39
size_t
ivoc
2016/10/17 16:05:08
Done.
| |
72 }; | |
73 | |
18 class EchoDetector { | 74 class EchoDetector { |
19 public: | 75 public: |
20 EchoDetector() {} | 76 EchoDetector(); |
21 ~EchoDetector() {} | 77 ~EchoDetector(); |
22 | 78 |
23 void BufferFarend(const float* farend, size_t num_samples); | 79 void BufferFarend(const float* farend, size_t num_samples); |
24 | 80 |
25 void Process(const float* nearend, size_t num_samples); | 81 void Process(const float* nearend, size_t num_samples); |
26 | 82 |
27 void Initialize(int sample_rate_hz); | 83 void Initialize(int sample_rate_hz); |
84 | |
85 float EchoLikelihood(); | |
hlundin-webrtc
2016/10/14 08:00:39
float echo_likelihood() const { return echo_likeli
ivoc
2016/10/17 16:05:08
Done.
| |
86 | |
87 private: | |
88 static constexpr int lookback_periods_ = 650; | |
hlundin-webrtc
2016/10/14 08:00:39
kLookbackPeriods
hlundin-webrtc
2016/10/14 08:00:39
size_t?
peah-webrtc
2016/10/14 08:18:58
size_t?
ivoc
2016/10/17 16:05:08
Done.
| |
89 static constexpr int render_buffer_size_ = 20; | |
hlundin-webrtc
2016/10/14 08:00:39
kRenderBufferSize
hlundin-webrtc
2016/10/14 08:00:40
Definitely size_t.
peah-webrtc
2016/10/14 08:18:58
size_t?
ivoc
2016/10/17 16:05:08
Done.
| |
90 | |
91 // Buffer for storing the power of incoming farend buffers. This is needed for | |
92 // cases where calls to BufferFarend and Process are jittery. | |
93 CircularBuffer render_buffer_; | |
94 // Delay of next render sample that should be used. | |
95 int render_buffer_delay_ = 0; | |
peah-webrtc
2016/10/14 08:18:58
size_t?
ivoc
2016/10/17 16:05:08
Done.
| |
96 | |
97 // Delayed versions of the power, mean and sigma, for calculating the delayed | |
98 // covariance values. | |
99 CircularBuffer render_power_; | |
100 CircularBuffer render_power_mean_; | |
101 CircularBuffer render_power_sigma_; | |
hlundin-webrtc
2016/10/14 08:00:39
render_power_std_dev_
ivoc
2016/10/17 16:05:08
Done.
| |
102 | |
103 MeanVarianceEstimator render_variance_; | |
104 MeanVarianceEstimator capture_variance_; | |
105 // Covariance estimates for different delay values. | |
106 std::vector<CovarianceEstimator> covariance_; | |
107 // Current echo likelihood. | |
108 float echo_likelihood_ = 0.f; | |
28 }; | 109 }; |
29 | 110 |
30 } // namespace webrtc | 111 } // namespace webrtc |
31 | 112 |
32 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_ECHO_DETECTOR_H_ | 113 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_ECHO_DETECTOR_H_ |
OLD | NEW |