Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Unified Diff: webrtc/modules/audio_processing/residual_echo_detector.cc

Issue 2405403003: Add empty residual echo detector. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3e230f101ccf3ee50baf37cc656c418280d1ac7b
--- /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).
+ RTC_DCHECK_EQ(render_signal_queue_->Insert(&render_queue_buffer_), true);
+ }
+}
+
+float ResidualEchoDetector::get_echo_likelihood() {
+ return 0.0f;
+}
+
+// Read chunks of data that were received and queued on the render side from
+// 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);
+ }
+}
+
+void ResidualEchoDetector::AnalyzeCaptureAudio(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);
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698