| 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_RESIDUAL_ECHO_DETECTOR_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_RESIDUAL_ECHO_DETECTOR_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_RESIDUAL_ECHO_DETECTOR_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_RESIDUAL_ECHO_DETECTOR_H_ |
| 13 | 13 |
| 14 #include <memory> | |
| 15 #include <vector> | 14 #include <vector> |
| 16 | 15 |
| 17 #include "webrtc/base/array_view.h" | 16 #include "webrtc/base/array_view.h" |
| 17 #include "webrtc/modules/audio_processing/echo_detector/circular_buffer.h" |
| 18 #include "webrtc/modules/audio_processing/echo_detector/mean_variance_estimator.
h" |
| 19 #include "webrtc/modules/audio_processing/echo_detector/normalized_covariance_es
timator.h" |
| 18 | 20 |
| 19 namespace webrtc { | 21 namespace webrtc { |
| 20 | 22 |
| 21 class AudioBuffer; | 23 class AudioBuffer; |
| 22 class EchoDetector; | 24 class EchoDetector; |
| 23 | 25 |
| 24 class ResidualEchoDetector { | 26 class ResidualEchoDetector { |
| 25 public: | 27 public: |
| 26 ResidualEchoDetector(); | 28 ResidualEchoDetector(); |
| 27 ~ResidualEchoDetector(); | 29 ~ResidualEchoDetector(); |
| 28 | 30 |
| 29 // This function should be called while holding the render lock. | 31 // This function should be called while holding the render lock. |
| 30 void AnalyzeRenderAudio(rtc::ArrayView<const float> render_audio) const; | 32 void AnalyzeRenderAudio(rtc::ArrayView<const float> render_audio); |
| 31 | 33 |
| 32 // This function should be called while holding the capture lock. | 34 // This function should be called while holding the capture lock. |
| 33 void AnalyzeCaptureAudio(rtc::ArrayView<const float> capture_audio); | 35 void AnalyzeCaptureAudio(rtc::ArrayView<const float> capture_audio); |
| 34 | 36 |
| 35 // This function should be called while holding the capture lock. | 37 // This function should be called while holding the capture lock. |
| 36 void Initialize(); | 38 void Initialize(); |
| 37 | 39 |
| 38 static void PackRenderAudioBuffer(AudioBuffer* audio, | 40 static void PackRenderAudioBuffer(AudioBuffer* audio, |
| 39 std::vector<float>* packed_buffer); | 41 std::vector<float>* packed_buffer); |
| 40 | 42 |
| 41 // This function should be called while holding the capture lock. | 43 // This function should be called while holding the capture lock. |
| 42 float get_echo_likelihood() const; | 44 float echo_likelihood() const { return echo_likelihood_; } |
| 45 |
| 46 private: |
| 47 // Keep track if the |Process| function has been previously called. |
| 48 bool first_process_call_ = true; |
| 49 // Buffer for storing the power of incoming farend buffers. This is needed for |
| 50 // cases where calls to BufferFarend and Process are jittery. |
| 51 CircularBuffer render_buffer_; |
| 52 // Count how long ago it was that the size of |render_buffer_| was zero. This |
| 53 // value is also reset to zero when clock drift is detected and a value from |
| 54 // the renderbuffer is discarded, even though the buffer is not actually zero |
| 55 // at that point. This is done to avoid repeatedly removing elements in this |
| 56 // situation. |
| 57 size_t frames_since_zero_buffer_size_ = 0; |
| 58 |
| 59 // Circular buffers containing delayed versions of the power, mean and |
| 60 // standard deviation, for calculating the delayed covariance values. |
| 61 std::vector<float> render_power_; |
| 62 std::vector<float> render_power_mean_; |
| 63 std::vector<float> render_power_std_dev_; |
| 64 // Covariance estimates for different delay values. |
| 65 std::vector<NormalizedCovarianceEstimator> covariances_; |
| 66 // Index where next element should be inserted in all of the above circular |
| 67 // buffers. |
| 68 size_t next_insertion_index_ = 0; |
| 69 |
| 70 MeanVarianceEstimator render_statistics_; |
| 71 MeanVarianceEstimator capture_statistics_; |
| 72 // Current echo likelihood. |
| 73 float echo_likelihood_ = 0.f; |
| 43 }; | 74 }; |
| 44 | 75 |
| 45 } // namespace webrtc | 76 } // namespace webrtc |
| 46 | 77 |
| 47 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_RESIDUAL_ECHO_DETECTOR_H_ | 78 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_RESIDUAL_ECHO_DETECTOR_H_ |
| OLD | NEW |