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

Side by Side Diff: webrtc/modules/audio_processing/level_controller/peak_level_estimator.cc

Issue 2283793002: Revert of Added functionality for specifying the initial signal level to use for the gain estimation (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 3 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
« no previous file with comments | « webrtc/modules/audio_processing/level_controller/peak_level_estimator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_processing/level_controller/peak_level_estimator. h" 11 #include "webrtc/modules/audio_processing/level_controller/peak_level_estimator. h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/modules/audio_processing/audio_buffer.h" 15 #include "webrtc/modules/audio_processing/audio_buffer.h"
16 #include "webrtc/modules/audio_processing/level_controller/lc_constants.h"
16 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" 17 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
17 18
18 namespace webrtc { 19 namespace webrtc {
19 namespace {
20
21 const float kMinLevel = 30.f;
22
23 } // namespace
24 20
25 PeakLevelEstimator::PeakLevelEstimator() { 21 PeakLevelEstimator::PeakLevelEstimator() {
26 Initialize(); 22 Initialize();
27 } 23 }
28 24
29 PeakLevelEstimator::~PeakLevelEstimator() {} 25 PeakLevelEstimator::~PeakLevelEstimator() {}
30 26
31 void PeakLevelEstimator::Initialize() { 27 void PeakLevelEstimator::Initialize() {
32 peak_level_ = initial_peak_level_; 28 peak_level_ = kTargetLcPeakLevel;
33 hold_counter_ = 0; 29 hold_counter_ = 0;
34 initialization_phase_ = true; 30 initialization_phase_ = true;
35 } 31 }
36 32
37 void PeakLevelEstimator::SetInitialPeakLevel(float level) {
38 RTC_DCHECK_LE(-100.f, level);
39 RTC_DCHECK_GE(0.f, level);
40
41 float linear_level = std::pow(10.f, level / 20.f) * 32768.f;
42
43 // Limit the supplied level to the level range used internally.
44 initial_peak_level_ = std::max(linear_level, kMinLevel);
45 Initialize();
46 }
47
48 float PeakLevelEstimator::Analyze(SignalClassifier::SignalType signal_type, 33 float PeakLevelEstimator::Analyze(SignalClassifier::SignalType signal_type,
49 float frame_peak_level) { 34 float frame_peak_level) {
50 if (frame_peak_level == 0) { 35 if (frame_peak_level == 0) {
51 RTC_DCHECK_LE(kMinLevel, peak_level_); 36 RTC_DCHECK_LE(30.f, peak_level_);
52 return peak_level_; 37 return peak_level_;
53 } 38 }
54 39
55 if (peak_level_ < frame_peak_level) { 40 if (peak_level_ < frame_peak_level) {
56 // Smoothly update the estimate upwards when the frame peak level is 41 // Smoothly update the estimate upwards when the frame peak level is
57 // higher than the estimate. 42 // higher than the estimate.
58 peak_level_ += 0.1f * (frame_peak_level - peak_level_); 43 peak_level_ += 0.1f * (frame_peak_level - peak_level_);
59 hold_counter_ = 100; 44 hold_counter_ = 100;
60 initialization_phase_ = false; 45 initialization_phase_ = false;
61 } else { 46 } else {
62 hold_counter_ = std::max(0, hold_counter_ - 1); 47 hold_counter_ = std::max(0, hold_counter_ - 1);
63 48
64 // When the signal is highly non-stationary, update the estimate slowly 49 // When the signal is highly non-stationary, update the estimate slowly
65 // downwards if the estimate is lower than the frame peak level. 50 // downwards if the estimate is lower than the frame peak level.
66 if ((signal_type == SignalClassifier::SignalType::kHighlyNonStationary && 51 if ((signal_type == SignalClassifier::SignalType::kHighlyNonStationary &&
67 hold_counter_ == 0) || 52 hold_counter_ == 0) ||
68 initialization_phase_) { 53 initialization_phase_) {
69 peak_level_ = 54 peak_level_ =
70 std::max(peak_level_ + 0.01f * (frame_peak_level - peak_level_), 55 std::max(peak_level_ + 0.01f * (frame_peak_level - peak_level_),
71 peak_level_ * 0.995f); 56 peak_level_ * 0.995f);
72 } 57 }
73 } 58 }
74 59
75 peak_level_ = std::max(peak_level_, kMinLevel); 60 peak_level_ = std::max(peak_level_, 30.f);
76 61
77 return peak_level_; 62 return peak_level_;
78 } 63 }
79 64
80 } // namespace webrtc 65 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/level_controller/peak_level_estimator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698