Index: webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc |
diff --git a/webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc b/webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc |
index 9175717ab7c77271732b8398c60bef13694f1825..2ba806c8ee0d15b58c366421aaa1e2b5c20d635b 100644 |
--- a/webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc |
+++ b/webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc |
@@ -13,6 +13,7 @@ |
#include <algorithm> |
#include "webrtc/modules/audio_processing/audio_buffer.h" |
+#include "webrtc/modules/audio_processing/level_controller/lc_constants.h" |
#include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" |
namespace webrtc { |
@@ -24,29 +25,35 @@ PeakLevelEstimator::PeakLevelEstimator() { |
PeakLevelEstimator::~PeakLevelEstimator() {} |
void PeakLevelEstimator::Initialize() { |
- peak_level_ = 1000.f; |
+ peak_level_ = kTargetLcPeakLevel; |
hold_counter_ = 0; |
+ initialization_phase_ = true; |
} |
float PeakLevelEstimator::Analyze(SignalClassifier::SignalType signal_type, |
float frame_peak_level) { |
- if (frame_peak_level > 0) { |
- if (peak_level_ < frame_peak_level) { |
- // Smoothly update the estimate upwards when the frame peak level is |
- // higher than the estimate. |
- peak_level_ += 0.1f * (frame_peak_level - peak_level_); |
- hold_counter_ = 100; |
- } else { |
- hold_counter_ = std::max(0, hold_counter_ - 1); |
- |
- // When the signal is highly non-stationary, update the estimate slowly |
- // downwards if the estimate is lower than the frame peak level. |
- if (signal_type == SignalClassifier::SignalType::kHighlyNonStationary && |
- hold_counter_ == 0) { |
- peak_level_ = |
- std::max(peak_level_ + 0.01f * (frame_peak_level - peak_level_), |
- peak_level_ * 0.995f); |
- } |
+ if (frame_peak_level == 0) { |
+ RTC_DCHECK_LE(30.f, peak_level_); |
+ return peak_level_; |
+ } |
+ |
+ if (peak_level_ < frame_peak_level) { |
+ // Smoothly update the estimate upwards when the frame peak level is |
+ // higher than the estimate. |
+ peak_level_ += 0.1f * (frame_peak_level - peak_level_); |
+ hold_counter_ = 100; |
+ initialization_phase_ = false; |
+ } else { |
+ hold_counter_ = std::max(0, hold_counter_ - 1); |
+ |
+ // When the signal is highly non-stationary, update the estimate slowly |
+ // downwards if the estimate is lower than the frame peak level. |
+ if ((signal_type == SignalClassifier::SignalType::kHighlyNonStationary && |
+ hold_counter_ == 0) || |
+ initialization_phase_) { |
+ peak_level_ = |
+ std::max(peak_level_ + 0.01f * (frame_peak_level - peak_level_), |
+ peak_level_ * 0.995f); |
} |
} |