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

Side by Side Diff: webrtc/modules/audio_processing/residual_echo_detector.cc

Issue 2884593002: Moving the residual echo detector outside of band-scheme in APM (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_processing/residual_echo_detector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "webrtc/modules/audio_processing/residual_echo_detector.h" 11 #include "webrtc/modules/audio_processing/residual_echo_detector.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <numeric> 14 #include <numeric>
15 15
16 #include "webrtc/base/atomicops.h"
16 #include "webrtc/modules/audio_processing/audio_buffer.h" 17 #include "webrtc/modules/audio_processing/audio_buffer.h"
18 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
17 #include "webrtc/system_wrappers/include/metrics.h" 19 #include "webrtc/system_wrappers/include/metrics.h"
18 20
19 namespace { 21 namespace {
20 22
21 float Power(rtc::ArrayView<const float> input) { 23 float Power(rtc::ArrayView<const float> input) {
22 return std::inner_product(input.begin(), input.end(), input.begin(), 0.f); 24 if (input.size() == 0) {
25 return 0.f;
26 }
27 return std::inner_product(input.begin(), input.end(), input.begin(), 0.f) /
28 input.size();
23 } 29 }
24 30
25 constexpr size_t kLookbackFrames = 650; 31 constexpr size_t kLookbackFrames = 650;
26 // TODO(ivoc): Verify the size of this buffer. 32 // TODO(ivoc): Verify the size of this buffer.
27 constexpr size_t kRenderBufferSize = 30; 33 constexpr size_t kRenderBufferSize = 30;
28 constexpr float kAlpha = 0.001f; 34 constexpr float kAlpha = 0.001f;
29 // 10 seconds of data, updated every 10 ms. 35 // 10 seconds of data, updated every 10 ms.
30 constexpr size_t kAggregationBufferSize = 10 * 100; 36 constexpr size_t kAggregationBufferSize = 10 * 100;
31 37
32 } // namespace 38 } // namespace
33 39
34 namespace webrtc { 40 namespace webrtc {
35 41
42 int ResidualEchoDetector::instance_count_ = 0;
43
36 ResidualEchoDetector::ResidualEchoDetector() 44 ResidualEchoDetector::ResidualEchoDetector()
37 : render_buffer_(kRenderBufferSize), 45 : data_dumper_(
46 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
47 render_buffer_(kRenderBufferSize),
38 render_power_(kLookbackFrames), 48 render_power_(kLookbackFrames),
39 render_power_mean_(kLookbackFrames), 49 render_power_mean_(kLookbackFrames),
40 render_power_std_dev_(kLookbackFrames), 50 render_power_std_dev_(kLookbackFrames),
41 covariances_(kLookbackFrames), 51 covariances_(kLookbackFrames),
42 recent_likelihood_max_(kAggregationBufferSize) {} 52 recent_likelihood_max_(kAggregationBufferSize) {}
43 53
44 ResidualEchoDetector::~ResidualEchoDetector() = default; 54 ResidualEchoDetector::~ResidualEchoDetector() = default;
45 55
46 void ResidualEchoDetector::AnalyzeRenderAudio( 56 void ResidualEchoDetector::AnalyzeRenderAudio(
47 rtc::ArrayView<const float> render_audio) { 57 rtc::ArrayView<const float> render_audio) {
58 // Dump debug data assuming 48 kHz sample rate (if this assumption is not
59 // valid the dumped audio will need to be converted offline accordingly).
60 data_dumper_->DumpWav("ed_render", render_audio.size(), render_audio.data(),
61 48000, 1);
62
48 if (render_buffer_.Size() == 0) { 63 if (render_buffer_.Size() == 0) {
49 frames_since_zero_buffer_size_ = 0; 64 frames_since_zero_buffer_size_ = 0;
50 } else if (frames_since_zero_buffer_size_ >= kRenderBufferSize) { 65 } else if (frames_since_zero_buffer_size_ >= kRenderBufferSize) {
51 // This can happen in a few cases: at the start of a call, due to a glitch 66 // This can happen in a few cases: at the start of a call, due to a glitch
52 // or due to clock drift. The excess capture value will be ignored. 67 // or due to clock drift. The excess capture value will be ignored.
53 // TODO(ivoc): Include how often this happens in APM stats. 68 // TODO(ivoc): Include how often this happens in APM stats.
54 render_buffer_.Pop(); 69 render_buffer_.Pop();
55 frames_since_zero_buffer_size_ = 0; 70 frames_since_zero_buffer_size_ = 0;
56 } 71 }
57 ++frames_since_zero_buffer_size_; 72 ++frames_since_zero_buffer_size_;
58 float power = Power(render_audio); 73 float power = Power(render_audio);
59 render_buffer_.Push(power); 74 render_buffer_.Push(power);
60 } 75 }
61 76
62 void ResidualEchoDetector::AnalyzeCaptureAudio( 77 void ResidualEchoDetector::AnalyzeCaptureAudio(
63 rtc::ArrayView<const float> capture_audio) { 78 rtc::ArrayView<const float> capture_audio) {
79 // Dump debug data assuming 48 kHz sample rate (if this assumption is not
80 // valid the dumped audio will need to be converted offline accordingly).
81 data_dumper_->DumpWav("ed_capture", capture_audio.size(),
82 capture_audio.data(), 48000, 1);
83
64 if (first_process_call_) { 84 if (first_process_call_) {
65 // On the first process call (so the start of a call), we must flush the 85 // On the first process call (so the start of a call), we must flush the
66 // render buffer, otherwise the render data will be delayed. 86 // render buffer, otherwise the render data will be delayed.
67 render_buffer_.Clear(); 87 render_buffer_.Clear();
68 first_process_call_ = false; 88 first_process_call_ = false;
69 } 89 }
70 90
71 // Get the next render value. 91 // Get the next render value.
72 const rtc::Optional<float> buffered_render_power = render_buffer_.Pop(); 92 const rtc::Optional<float> buffered_render_power = render_buffer_.Pop();
73 if (!buffered_render_power) { 93 if (!buffered_render_power) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 cov.Clear(); 153 cov.Clear();
134 } 154 }
135 echo_likelihood_ = 0.f; 155 echo_likelihood_ = 0.f;
136 next_insertion_index_ = 0; 156 next_insertion_index_ = 0;
137 reliability_ = 0.f; 157 reliability_ = 0.f;
138 } 158 }
139 159
140 void ResidualEchoDetector::PackRenderAudioBuffer( 160 void ResidualEchoDetector::PackRenderAudioBuffer(
141 AudioBuffer* audio, 161 AudioBuffer* audio,
142 std::vector<float>* packed_buffer) { 162 std::vector<float>* packed_buffer) {
143 RTC_DCHECK_GE(160, audio->num_frames_per_band());
144
145 packed_buffer->clear(); 163 packed_buffer->clear();
146 packed_buffer->insert(packed_buffer->end(), 164 packed_buffer->insert(packed_buffer->end(), audio->channels_f()[0],
147 audio->split_bands_const_f(0)[kBand0To8kHz], 165 audio->channels_f()[0] + audio->num_frames());
148 (audio->split_bands_const_f(0)[kBand0To8kHz] +
149 audio->num_frames_per_band()));
150 } 166 }
151 167
152 } // namespace webrtc 168 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/residual_echo_detector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698