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..2f1e31f363d4a61b2f4aca8a5ec436ab34af3dd0 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,32 @@ float NoiseSuppressionImpl::speech_probability() const { |
return AudioProcessing::kUnsupportedFunctionError; |
#endif |
} |
+ |
+const std::vector<float>& NoiseSuppressionImpl::noise_estimate() { |
hlundin-webrtc
2016/02/08 10:12:31
I think I would prefer the following changes to th
aluebs-webrtc
2016/02/09 00:01:42
I thought about doing that, but then each call to
|
+ rtc::CritScope cs(crit_); |
+ if (noise_estimate_updated_) { |
hlundin-webrtc
2016/02/08 10:12:31
What if the noise estimate is not updated. How val
aluebs-webrtc
2016/02/09 00:01:42
Since the vector is calculated every time, I remov
|
+#if defined(WEBRTC_NS_FLOAT) |
+ noise_estimate_.assign(WebRtcNs_num_freq(), 0.f); |
+ for (auto& suppressor : suppressors_) { |
+ const 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) |
+ const float kNormalizationFactor = 1.f / (1 << 17); |
+ noise_estimate_.assign(WebRtcNsx_num_freq(), 0.f); |
+ for (auto& suppressor : suppressors_) { |
+ const uint32_t* noise = WebRtcNsx_noise_estimate(suppressor->state()); |
+ for (size_t i = 0; i < noise_estimate_.size(); ++i) { |
+ noise_estimate_[i] += kNormalizationFactor * |
+ static_cast<float>(noise[i]) / suppressors_.size(); |
+ } |
+ } |
+#endif |
+ noise_estimate_updated_ = false; |
+ } |
+ return noise_estimate_; |
+} |
+ |
} // namespace webrtc |