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

Side by Side 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: Temporarily deactivated the level controller until the CL with the proper tuning has been landed Created 4 years, 5 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 unified diff | Download patch
OLDNEW
(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/peak_level_estimator. h"
12
13 #include <algorithm>
14
15 #include "webrtc/modules/audio_processing/audio_buffer.h"
16 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
17
18 namespace webrtc {
19
20 PeakLevelEstimator::PeakLevelEstimator() {
21 Initialize();
22 }
23
24 PeakLevelEstimator::~PeakLevelEstimator() {}
25
26 void PeakLevelEstimator::Initialize() {
27 peak_level_ = 1000.f;
28 hold_counter_ = 0;
29 }
30
31 float PeakLevelEstimator::Analyze(SignalClassifier::SignalType signal_type,
32 float frame_peak_level) {
33 if (frame_peak_level > 0) {
34 if (peak_level_ < frame_peak_level) {
35 // Smoothly update the estimate upwards when the frame peak level is
36 // higher than the estimate.
37 peak_level_ += 0.1f * (frame_peak_level - peak_level_);
38 hold_counter_ = 100;
39 } else {
40 hold_counter_ = std::max(0, hold_counter_ - 1);
41
42 // When the signal is highly non-stationary, update the estimate slowly
43 // downwards if the estimate is lower than the frame peak level.
44 if (signal_type == SignalClassifier::SignalType::kHighlyNonStationary &&
45 hold_counter_ == 0) {
46 peak_level_ =
47 std::max(peak_level_ + 0.01f * (frame_peak_level - peak_level_),
48 peak_level_ * 0.995f);
49 }
50 }
51 }
52
53 peak_level_ = std::max(peak_level_, 30.f);
54
55 return peak_level_;
56 }
57
58 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698