Chromium Code Reviews| Index: webrtc/modules/audio_processing/echo_detector/echo_detector.h |
| diff --git a/webrtc/modules/audio_processing/echo_detector/echo_detector.h b/webrtc/modules/audio_processing/echo_detector/echo_detector.h |
| index fd190834329cc1760208f0efd7349ab62e84fc62..f0a55fec74f99669ff7e9059ee30e3e231beebe3 100644 |
| --- a/webrtc/modules/audio_processing/echo_detector/echo_detector.h |
| +++ b/webrtc/modules/audio_processing/echo_detector/echo_detector.h |
| @@ -12,19 +12,100 @@ |
| #define WEBRTC_MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_ECHO_DETECTOR_H_ |
| #include <stddef.h> |
| +#include <vector> |
| namespace webrtc { |
| +// This class iteratively estimates the mean and variance of a signal. |
| +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.
|
| + public: |
| + void UpdateEstimate(float value); |
| + 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)
|
| + 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.
|
| + void Clear(); |
| + |
| + private: |
| + // Estimate of the expected value of the input values. |
| + float mean_ = 0.f; |
| + // Estimate of the variance of the input values. |
| + float variance_ = 0.f; |
| + // Parameter controlling the adaptation speed. |
| + 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.
|
| +}; |
| + |
| +// This class iteratively estimates the covariance between two signals. |
| +class CovarianceEstimator { |
| + public: |
| + void UpdateCovarianceEstimate(float x, |
| + float x_mean, |
| + float x_var, |
| + float y, |
| + float y_mean, |
| + float y_var); |
| + 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.
|
| + void Clear(); |
| + |
| + private: |
| + // Estimate of the Pearson product-moment correlation coefficient of the two |
| + // signals. |
| + 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
|
| + // Estimate of the covariance value. |
| + float covariance_ = 0.f; |
| + // Parameter controlling the adaptation speed. |
| + 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.
|
| +}; |
| + |
| +// Ring buffer containing floating point values. |
| +struct CircularBuffer { |
| + public: |
| + 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.
|
| + ~CircularBuffer(); |
| + |
| + void Insert(float value); |
| + float GetValue(int delay); |
| + void Clear(); |
| + |
| + private: |
| + std::vector<float> buffer_; |
| + 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
|
| + int next_insertion_index_ = 0; |
|
hlundin-webrtc
2016/10/14 08:00:39
size_t
ivoc
2016/10/17 16:05:08
Done.
|
| +}; |
| + |
| class EchoDetector { |
| public: |
| - EchoDetector() {} |
| - ~EchoDetector() {} |
| + EchoDetector(); |
| + ~EchoDetector(); |
| void BufferFarend(const float* farend, size_t num_samples); |
| void Process(const float* nearend, size_t num_samples); |
| void Initialize(int sample_rate_hz); |
| + |
| + 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.
|
| + |
| + private: |
| + 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.
|
| + 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.
|
| + |
| + // Buffer for storing the power of incoming farend buffers. This is needed for |
| + // cases where calls to BufferFarend and Process are jittery. |
| + CircularBuffer render_buffer_; |
| + // Delay of next render sample that should be used. |
| + int render_buffer_delay_ = 0; |
|
peah-webrtc
2016/10/14 08:18:58
size_t?
ivoc
2016/10/17 16:05:08
Done.
|
| + |
| + // Delayed versions of the power, mean and sigma, for calculating the delayed |
| + // covariance values. |
| + CircularBuffer render_power_; |
| + CircularBuffer render_power_mean_; |
| + CircularBuffer render_power_sigma_; |
|
hlundin-webrtc
2016/10/14 08:00:39
render_power_std_dev_
ivoc
2016/10/17 16:05:08
Done.
|
| + |
| + MeanVarianceEstimator render_variance_; |
| + MeanVarianceEstimator capture_variance_; |
| + // Covariance estimates for different delay values. |
| + std::vector<CovarianceEstimator> covariance_; |
| + // Current echo likelihood. |
| + float echo_likelihood_ = 0.f; |
| }; |
| } // namespace webrtc |