OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "webrtc/modules/audio_processing/residual_echo_detector.h" |
| 12 #include "webrtc/modules/audio_processing/audio_buffer.h" |
| 13 #include "webrtc/modules/audio_processing/echo_detector/echo_detector.h" |
| 14 |
| 15 namespace webrtc { |
| 16 |
| 17 ResidualEchoDetector::ResidualEchoDetector(rtc::CriticalSection* crit_render, |
| 18 rtc::CriticalSection* crit_capture) |
| 19 : crit_render_(crit_render), crit_capture_(crit_capture) { |
| 20 RTC_DCHECK(crit_render); |
| 21 RTC_DCHECK(crit_capture); |
| 22 } |
| 23 |
| 24 ResidualEchoDetector::~ResidualEchoDetector() {} |
| 25 |
| 26 void ResidualEchoDetector::AnalyzeRenderAudio(const AudioBuffer* audio) { |
| 27 rtc::CritScope cs_render(crit_render_); |
| 28 |
| 29 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
| 30 |
| 31 render_queue_buffer_.clear(); |
| 32 |
| 33 // Buffer the samples in the render queue. |
| 34 render_queue_buffer_.insert(render_queue_buffer_.end(), |
| 35 audio->split_bands_const_f(0)[kBand0To8kHz], |
| 36 (audio->split_bands_const_f(0)[kBand0To8kHz] + |
| 37 audio->num_frames_per_band())); |
| 38 |
| 39 // Insert the samples into the queue. |
| 40 if (!render_signal_queue_->Insert(&render_queue_buffer_)) { |
| 41 // The data queue is full and needs to be emptied. |
| 42 ReadQueuedRenderData(); |
| 43 |
| 44 // Retry the insert (should always work). |
| 45 RTC_DCHECK_EQ(render_signal_queue_->Insert(&render_queue_buffer_), true); |
| 46 } |
| 47 } |
| 48 |
| 49 float ResidualEchoDetector::get_echo_likelihood() { |
| 50 return 0.0f; |
| 51 } |
| 52 |
| 53 // Read chunks of data that were received and queued on the render side from |
| 54 // a queue. All the data chunks are buffered into the farend signal of the AEC. |
| 55 void ResidualEchoDetector::ReadQueuedRenderData() { |
| 56 rtc::CritScope cs_capture(crit_capture_); |
| 57 |
| 58 while (render_signal_queue_->Remove(&capture_queue_buffer_)) { |
| 59 const size_t num_frames_per_band = capture_queue_buffer_.size(); |
| 60 detector_->BufferFarend(capture_queue_buffer_.data(), num_frames_per_band); |
| 61 } |
| 62 } |
| 63 |
| 64 void ResidualEchoDetector::AnalyzeCaptureAudio(AudioBuffer* audio) { |
| 65 rtc::CritScope cs_capture(crit_capture_); |
| 66 |
| 67 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
| 68 |
| 69 detector_->Process(audio->split_bands_const_f(0)[kBand0To8kHz], |
| 70 audio->num_frames_per_band()); |
| 71 } |
| 72 |
| 73 void ResidualEchoDetector::Initialize(int sample_rate_hz) { |
| 74 rtc::CritScope cs_render(crit_render_); |
| 75 rtc::CritScope cs_capture(crit_capture_); |
| 76 |
| 77 RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz || |
| 78 sample_rate_hz == AudioProcessing::kSampleRate16kHz || |
| 79 sample_rate_hz == AudioProcessing::kSampleRate32kHz || |
| 80 sample_rate_hz == AudioProcessing::kSampleRate48kHz); |
| 81 |
| 82 detector_->Initialize(sample_rate_hz); |
| 83 } |
| 84 |
| 85 } // namespace webrtc |
OLD | NEW |