Index: webrtc/modules/audio_processing/noise_suppression_impl.cc |
diff --git a/webrtc/modules/audio_processing/noise_suppression_impl.cc b/webrtc/modules/audio_processing/noise_suppression_impl.cc |
index de7e856676ef14e86bebe2a53511d16f7a204943..5ee8160cdddc3b9ec4a263592e3b4e762e225373 100644 |
--- a/webrtc/modules/audio_processing/noise_suppression_impl.cc |
+++ b/webrtc/modules/audio_processing/noise_suppression_impl.cc |
@@ -65,6 +65,7 @@ void NoiseSuppressionImpl::Initialize(size_t channels, int sample_rate_hz) { |
} |
suppressors_.swap(new_suppressors); |
set_level(level_); |
+ noise_estimate_updated_ = false; |
} |
void NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { |
@@ -81,6 +82,7 @@ void NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { |
WebRtcNs_Analyze(suppressors_[i]->state(), |
audio->split_bands_const_f(i)[kBand0To8kHz]); |
} |
+ noise_estimate_updated_ = true; |
#endif |
} |
@@ -104,6 +106,7 @@ void NoiseSuppressionImpl::ProcessCaptureAudio(AudioBuffer* audio) { |
audio->split_bands_const(i), |
audio->num_bands(), |
audio->split_bands(i)); |
+ noise_estimate_updated_ = true; |
#endif |
} |
} |
@@ -172,4 +175,31 @@ float NoiseSuppressionImpl::speech_probability() const { |
return AudioProcessing::kUnsupportedFunctionError; |
#endif |
} |
+ |
+const std::vector<float>& NoiseSuppressionImpl::noise_estimate() { |
+ rtc::CritScope cs(crit_); |
+ if (noise_estimate_updated_) { |
+#if defined(WEBRTC_NS_FLOAT) |
+ noise_estimate_.assign(WebRtcNs_num_freq(), 0.f); |
+ for (auto& suppressor : suppressors_) { |
+ float* noise = WebRtcNs_noise_estimate(suppressor->state()); |
+ for (size_t i = 0; i < noise_estimate_.size(); ++i) { |
+ noise_estimate_[i] += noise[i] / suppressors_.size(); |
+ } |
+ } |
+#elif defined(WEBRTC_NS_FIXED) |
+ noise_estimate_.assign(WebRtcNsx_num_freq(), 0.f); |
+ for (auto& suppressor : suppressors_) { |
+ uint32_t* noise = WebRtcNsx_noise_estimate(suppressor->state()); |
+ for (size_t i = 0; i < noise_estimate_.size(); ++i) { |
+ noise_estimate_[i] += |
+ 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
|
+ } |
+ } |
+#endif |
+ noise_estimate_updated_ = false; |
+ } |
+ return noise_estimate_; |
+} |
+ |
} // namespace webrtc |