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/level_controller/noise_spectrum_estima tor.h" | |
| 12 | |
| 13 #include <string.h> | |
| 14 #include <algorithm> | |
| 15 | |
| 16 #include "webrtc/base/array_view.h" | |
| 17 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | |
| 18 | |
| 19 namespace webrtc { | |
| 20 namespace { | |
| 21 float kMinNoisePower = 100.f; | |
| 22 } // namespace | |
| 23 | |
| 24 NoiseSpectrumEstimator::NoiseSpectrumEstimator(ApmDataDumper* data_dumper) | |
| 25 : data_dumper_(data_dumper) { | |
| 26 std::fill(noise_spectrum_, noise_spectrum_ + 65, kMinNoisePower); | |
|
hlundin-webrtc
2016/06/27 11:21:16
65 -> arraysize(noise_spectrum_)
peah-webrtc
2016/06/27 22:51:50
Good suggestion!
Done.
| |
| 27 } | |
| 28 | |
| 29 void NoiseSpectrumEstimator::Update(rtc::ArrayView<const float> spectrum, | |
| 30 bool first_update) { | |
| 31 RTC_DCHECK_EQ(65u, spectrum.size()); | |
| 32 | |
| 33 if (first_update) { | |
| 34 // Initialize the noise spectral estimate with the signal spectrum. | |
| 35 std::copy(spectrum.data(), spectrum.data() + spectrum.size(), | |
| 36 noise_spectrum_); | |
| 37 } else { | |
| 38 // Smoothly update the noise spectral estimate towards the signal spectrum | |
| 39 // such that the magnitude of the updates are limited. | |
| 40 for (size_t k = 0; k < spectrum.size(); ++k) { | |
| 41 if (noise_spectrum_[k] < spectrum[k]) { | |
| 42 noise_spectrum_[k] = std::min( | |
| 43 1.01f * noise_spectrum_[k], | |
| 44 noise_spectrum_[k] + 0.05f * (spectrum[k] - noise_spectrum_[k])); | |
| 45 } else { | |
| 46 noise_spectrum_[k] = std::max( | |
| 47 0.99f * noise_spectrum_[k], | |
| 48 noise_spectrum_[k] + 0.05f * (spectrum[k] - noise_spectrum_[k])); | |
| 49 } | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 // Ensure that the noise spectal estimate does not become too low. | |
| 54 for (auto& v : noise_spectrum_) { | |
| 55 v = std::max(v, kMinNoisePower); | |
| 56 } | |
| 57 | |
| 58 data_dumper_->DumpRaw("lc_noise_spectrum", 65, noise_spectrum_); | |
| 59 data_dumper_->DumpRaw("lc_signal_spectrum", spectrum); | |
| 60 } | |
| 61 | |
| 62 } // namespace webrtc | |
| OLD | NEW |