Chromium Code Reviews| 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 bool reinsert = render_signal_queue_->Insert(&render_queue_buffer_); | |
| 46 RTC_DCHECK(reinsert); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 void ResidualEchoDetector::AnalyzeCaptureAudio(const AudioBuffer* audio) { | |
| 51 rtc::CritScope cs_capture(crit_capture_); | |
| 52 | |
| 53 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); | |
| 54 | |
| 55 detector_->Process(audio->split_bands_const_f(0)[kBand0To8kHz], | |
| 56 audio->num_frames_per_band()); | |
| 57 } | |
| 58 | |
| 59 void ResidualEchoDetector::Initialize(int sample_rate_hz) { | |
| 60 rtc::CritScope cs_render(crit_render_); | |
| 61 rtc::CritScope cs_capture(crit_capture_); | |
| 62 | |
| 63 RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz || | |
| 64 sample_rate_hz == AudioProcessing::kSampleRate16kHz || | |
| 65 sample_rate_hz == AudioProcessing::kSampleRate32kHz || | |
| 66 sample_rate_hz == AudioProcessing::kSampleRate48kHz); | |
| 67 | |
| 68 detector_->Initialize(sample_rate_hz); | |
| 69 } | |
| 70 | |
| 71 // 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.
| |
| 72 // a queue. All the data chunks are buffered into the farend signal of the AEC. | |
| 73 void ResidualEchoDetector::ReadQueuedRenderData() { | |
| 74 rtc::CritScope cs_capture(crit_capture_); | |
| 75 while (render_signal_queue_->Remove(&capture_queue_buffer_)) { | |
| 76 const size_t num_frames_per_band = capture_queue_buffer_.size(); | |
| 77 detector_->BufferFarend(capture_queue_buffer_.data(), num_frames_per_band); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 float ResidualEchoDetector::get_echo_likelihood() const { | |
| 82 return 0.0f; | |
| 83 } | |
| 84 | |
| 85 } // namespace webrtc | |
| OLD | NEW |