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

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

Issue 1654443004: Surface the noise estimate of the NS to be used by other components (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 sample_rate_hz_ = sample_rate_hz; 58 sample_rate_hz_ = sample_rate_hz;
59 std::vector<rtc::scoped_ptr<Suppressor>> new_suppressors; 59 std::vector<rtc::scoped_ptr<Suppressor>> new_suppressors;
60 if (enabled_) { 60 if (enabled_) {
61 new_suppressors.resize(channels); 61 new_suppressors.resize(channels);
62 for (size_t i = 0; i < channels; i++) { 62 for (size_t i = 0; i < channels; i++) {
63 new_suppressors[i].reset(new Suppressor(sample_rate_hz)); 63 new_suppressors[i].reset(new Suppressor(sample_rate_hz));
64 } 64 }
65 } 65 }
66 suppressors_.swap(new_suppressors); 66 suppressors_.swap(new_suppressors);
67 set_level(level_); 67 set_level(level_);
68 noise_estimate_updated_ = false;
68 } 69 }
69 70
70 void NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { 71 void NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
71 RTC_DCHECK(audio); 72 RTC_DCHECK(audio);
72 #if defined(WEBRTC_NS_FLOAT) 73 #if defined(WEBRTC_NS_FLOAT)
73 rtc::CritScope cs(crit_); 74 rtc::CritScope cs(crit_);
74 if (!enabled_) { 75 if (!enabled_) {
75 return; 76 return;
76 } 77 }
77 78
78 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); 79 RTC_DCHECK_GE(160u, audio->num_frames_per_band());
79 RTC_DCHECK_EQ(suppressors_.size(), audio->num_channels()); 80 RTC_DCHECK_EQ(suppressors_.size(), audio->num_channels());
80 for (size_t i = 0; i < suppressors_.size(); i++) { 81 for (size_t i = 0; i < suppressors_.size(); i++) {
81 WebRtcNs_Analyze(suppressors_[i]->state(), 82 WebRtcNs_Analyze(suppressors_[i]->state(),
82 audio->split_bands_const_f(i)[kBand0To8kHz]); 83 audio->split_bands_const_f(i)[kBand0To8kHz]);
83 } 84 }
85 noise_estimate_updated_ = true;
84 #endif 86 #endif
85 } 87 }
86 88
87 void NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) { 89 void NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) {
88 RTC_DCHECK(audio); 90 RTC_DCHECK(audio);
89 rtc::CritScope cs(crit_); 91 rtc::CritScope cs(crit_);
90 if (!enabled_) { 92 if (!enabled_) {
91 return; 93 return;
92 } 94 }
93 95
94 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); 96 RTC_DCHECK_GE(160u, audio->num_frames_per_band());
95 RTC_DCHECK_EQ(suppressors_.size(), audio->num_channels()); 97 RTC_DCHECK_EQ(suppressors_.size(), audio->num_channels());
96 for (size_t i = 0; i < suppressors_.size(); i++) { 98 for (size_t i = 0; i < suppressors_.size(); i++) {
97 #if defined(WEBRTC_NS_FLOAT) 99 #if defined(WEBRTC_NS_FLOAT)
98 WebRtcNs_Process(suppressors_[i]->state(), 100 WebRtcNs_Process(suppressors_[i]->state(),
99 audio->split_bands_const_f(i), 101 audio->split_bands_const_f(i),
100 audio->num_bands(), 102 audio->num_bands(),
101 audio->split_bands_f(i)); 103 audio->split_bands_f(i));
102 #elif defined(WEBRTC_NS_FIXED) 104 #elif defined(WEBRTC_NS_FIXED)
103 WebRtcNsx_Process(suppressors_[i]->state(), 105 WebRtcNsx_Process(suppressors_[i]->state(),
104 audio->split_bands_const(i), 106 audio->split_bands_const(i),
105 audio->num_bands(), 107 audio->num_bands(),
106 audio->split_bands(i)); 108 audio->split_bands(i));
109 noise_estimate_updated_ = true;
107 #endif 110 #endif
108 } 111 }
109 } 112 }
110 113
111 int NoiseSuppressionImpl::Enable(bool enable) { 114 int NoiseSuppressionImpl::Enable(bool enable) {
112 rtc::CritScope cs(crit_); 115 rtc::CritScope cs(crit_);
113 if (enabled_ != enable) { 116 if (enabled_ != enable) {
114 enabled_ = enable; 117 enabled_ = enable;
115 Initialize(channels_, sample_rate_hz_); 118 Initialize(channels_, sample_rate_hz_);
116 } 119 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 if (!suppressors_.empty()) { 168 if (!suppressors_.empty()) {
166 probability_average /= suppressors_.size(); 169 probability_average /= suppressors_.size();
167 } 170 }
168 return probability_average; 171 return probability_average;
169 #elif defined(WEBRTC_NS_FIXED) 172 #elif defined(WEBRTC_NS_FIXED)
170 // TODO(peah): Returning error code as a float! Remove this. 173 // TODO(peah): Returning error code as a float! Remove this.
171 // Currently not available for the fixed point implementation. 174 // Currently not available for the fixed point implementation.
172 return AudioProcessing::kUnsupportedFunctionError; 175 return AudioProcessing::kUnsupportedFunctionError;
173 #endif 176 #endif
174 } 177 }
178
179 const std::vector<float>& NoiseSuppressionImpl::noise_estimate() {
180 rtc::CritScope cs(crit_);
181 if (noise_estimate_updated_) {
182 #if defined(WEBRTC_NS_FLOAT)
183 noise_estimate_.assign(WebRtcNs_num_freq(), 0.f);
184 for (auto& suppressor : suppressors_) {
185 float* noise = WebRtcNs_noise_estimate(suppressor->state());
186 for (size_t i = 0; i < noise_estimate_.size(); ++i) {
187 noise_estimate_[i] += noise[i] / suppressors_.size();
188 }
189 }
190 #elif defined(WEBRTC_NS_FIXED)
191 noise_estimate_.assign(WebRtcNsx_num_freq(), 0.f);
192 for (auto& suppressor : suppressors_) {
193 uint32_t* noise = WebRtcNsx_noise_estimate(suppressor->state());
194 for (size_t i = 0; i < noise_estimate_.size(); ++i) {
195 noise_estimate_[i] +=
196 static_cast<float>(noise[i] >> 17) / suppressors_.size();
turaj 2016/02/05 01:47:58 Is nois[] is Q17? maybe a comment helps. And if it
aluebs-webrtc 2016/02/06 00:12:27 It is an unsigned 32-bit integer, and we want to g
197 }
198 }
199 #endif
200 noise_estimate_updated_ = false;
201 }
202 return noise_estimate_;
203 }
204
175 } // namespace webrtc 205 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698