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

Unified Diff: webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc

Issue 2090583002: New module for the adaptive level controlling functionality in the audio processing module (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Corrected the initial behavior for the peak level estimate, and ensured a nonzero minimum peak leveā€¦ Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..91b07952b37969db4005a68a7bd5d2f72295dae5
--- /dev/null
+++ b/webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/audio_processing/level_controller/peak_level_estimator.h"
+
+#include <algorithm>
+
+#include "webrtc/modules/audio_processing/audio_buffer.h"
+#include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
+
+namespace webrtc {
+
+PeakLevelEstimator::PeakLevelEstimator() {
+ Initialize();
+}
+
+PeakLevelEstimator::~PeakLevelEstimator() {}
+
+void PeakLevelEstimator::Initialize() {
+ peak_level_ = 32767.f;
+}
+
+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 there frame peak level is
hlundin-webrtc 2016/06/27 11:21:16 there -> the
peah-webrtc 2016/06/27 22:51:50 Done.
+ // higher than the estimate.
+ peak_level_ += 0.1f * (frame_peak_level - peak_level_);
+ } else {
+ // When the signal is highly non-stationary, update the estimate slowly
+ // downwards
+ // if the estimate is lower than the frame peak level
hlundin-webrtc 2016/06/27 11:21:16 Weird line-wrapping, and end the sentence with a p
peah-webrtc 2016/06/27 22:51:50 Done.
+ if (signal_type == SignalClassifier::SignalType::kHighlyNonStationary &&
+ peak_level_ > frame_peak_level) {
hlundin-webrtc 2016/06/27 11:21:16 You already know that peak_level_ >= frame_peak_le
peah-webrtc 2016/06/27 22:51:50 Good find! Done.
+ peak_level_ += 0.05f * (frame_peak_level - peak_level_);
+ }
+ }
+ }
+
+ peak_level_ = std::max(peak_level_, 30.f);
+
+ return peak_level_;
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698