Chromium Code Reviews| Index: webrtc/modules/audio_processing/residual_echo_detector.cc |
| diff --git a/webrtc/modules/audio_processing/residual_echo_detector.cc b/webrtc/modules/audio_processing/residual_echo_detector.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..437710ce51a3d689b9e1924f84a4967a061b5dde |
| --- /dev/null |
| +++ b/webrtc/modules/audio_processing/residual_echo_detector.cc |
| @@ -0,0 +1,85 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/modules/audio_processing/residual_echo_detector.h" |
| +#include "webrtc/modules/audio_processing/audio_buffer.h" |
| +#include "webrtc/modules/audio_processing/echo_detector/echo_detector.h" |
| + |
| +namespace webrtc { |
| + |
| +ResidualEchoDetector::ResidualEchoDetector(rtc::CriticalSection* crit_render, |
| + rtc::CriticalSection* crit_capture) |
| + : crit_render_(crit_render), crit_capture_(crit_capture) { |
| + RTC_DCHECK(crit_render); |
| + RTC_DCHECK(crit_capture); |
| +} |
| + |
| +ResidualEchoDetector::~ResidualEchoDetector() {} |
| + |
| +void ResidualEchoDetector::AnalyzeRenderAudio(const AudioBuffer* audio) { |
| + rtc::CritScope cs_render(crit_render_); |
| + |
| + RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
| + |
| + render_queue_buffer_.clear(); |
| + |
| + // Buffer the samples in the render queue. |
| + render_queue_buffer_.insert(render_queue_buffer_.end(), |
| + audio->split_bands_const_f(0)[kBand0To8kHz], |
| + (audio->split_bands_const_f(0)[kBand0To8kHz] + |
| + audio->num_frames_per_band())); |
| + |
| + // Insert the samples into the queue. |
| + if (!render_signal_queue_->Insert(&render_queue_buffer_)) { |
| + // The data queue is full and needs to be emptied. |
| + ReadQueuedRenderData(); |
| + |
| + // Retry the insert (should always work). |
| + bool reinsert = render_signal_queue_->Insert(&render_queue_buffer_); |
| + RTC_DCHECK(reinsert); |
| + } |
| +} |
| + |
| +void ResidualEchoDetector::AnalyzeCaptureAudio(const AudioBuffer* audio) { |
| + rtc::CritScope cs_capture(crit_capture_); |
| + |
| + RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
| + |
| + detector_->Process(audio->split_bands_const_f(0)[kBand0To8kHz], |
| + audio->num_frames_per_band()); |
| +} |
| + |
| +void ResidualEchoDetector::Initialize(int sample_rate_hz) { |
| + rtc::CritScope cs_render(crit_render_); |
| + rtc::CritScope cs_capture(crit_capture_); |
| + |
| + RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz || |
| + sample_rate_hz == AudioProcessing::kSampleRate16kHz || |
| + sample_rate_hz == AudioProcessing::kSampleRate32kHz || |
| + sample_rate_hz == AudioProcessing::kSampleRate48kHz); |
| + |
| + detector_->Initialize(sample_rate_hz); |
| +} |
| + |
| +// Read chunks of data that were received and queued on the render side from |
|
hlundin-webrtc
2016/10/14 06:59:18
You have two similar, but not identical, descripti
ivoc
2016/10/14 09:53:19
Ok, I removed this one.
|
| +// a queue. All the data chunks are buffered into the farend signal of the AEC. |
| +void ResidualEchoDetector::ReadQueuedRenderData() { |
| + rtc::CritScope cs_capture(crit_capture_); |
| + while (render_signal_queue_->Remove(&capture_queue_buffer_)) { |
| + const size_t num_frames_per_band = capture_queue_buffer_.size(); |
| + detector_->BufferFarend(capture_queue_buffer_.data(), num_frames_per_band); |
| + } |
| +} |
| + |
| +float ResidualEchoDetector::get_echo_likelihood() const { |
| + return 0.0f; |
| +} |
| + |
| +} // namespace webrtc |