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

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

Issue 2254973003: Added functionality for specifying the initial signal level to use for the gain estimation in the l… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase 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"
17 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" 16 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
18 17
19 namespace webrtc { 18 namespace webrtc {
19 namespace {
20
21 const float kMinLevel = 30.f;
22
23 } // namespace
20 24
21 PeakLevelEstimator::PeakLevelEstimator() { 25 PeakLevelEstimator::PeakLevelEstimator() {
22 Initialize(); 26 Initialize();
23 } 27 }
24 28
25 PeakLevelEstimator::~PeakLevelEstimator() {} 29 PeakLevelEstimator::~PeakLevelEstimator() {}
26 30
27 void PeakLevelEstimator::Initialize() { 31 void PeakLevelEstimator::Initialize() {
28 peak_level_ = kTargetLcPeakLevel; 32 peak_level_ = initial_peak_level_;
29 hold_counter_ = 0; 33 hold_counter_ = 0;
30 initialization_phase_ = true; 34 initialization_phase_ = true;
31 } 35 }
32 36
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
33 float PeakLevelEstimator::Analyze(SignalClassifier::SignalType signal_type, 48 float PeakLevelEstimator::Analyze(SignalClassifier::SignalType signal_type,
34 float frame_peak_level) { 49 float frame_peak_level) {
35 if (frame_peak_level == 0) { 50 if (frame_peak_level == 0) {
36 RTC_DCHECK_LE(30.f, peak_level_); 51 RTC_DCHECK_LE(kMinLevel, peak_level_);
37 return peak_level_; 52 return peak_level_;
38 } 53 }
39 54
40 if (peak_level_ < frame_peak_level) { 55 if (peak_level_ < frame_peak_level) {
41 // Smoothly update the estimate upwards when the frame peak level is 56 // Smoothly update the estimate upwards when the frame peak level is
42 // higher than the estimate. 57 // higher than the estimate.
43 peak_level_ += 0.1f * (frame_peak_level - peak_level_); 58 peak_level_ += 0.1f * (frame_peak_level - peak_level_);
44 hold_counter_ = 100; 59 hold_counter_ = 100;
45 initialization_phase_ = false; 60 initialization_phase_ = false;
46 } else { 61 } else {
47 hold_counter_ = std::max(0, hold_counter_ - 1); 62 hold_counter_ = std::max(0, hold_counter_ - 1);
48 63
49 // When the signal is highly non-stationary, update the estimate slowly 64 // When the signal is highly non-stationary, update the estimate slowly
50 // downwards if the estimate is lower than the frame peak level. 65 // downwards if the estimate is lower than the frame peak level.
51 if ((signal_type == SignalClassifier::SignalType::kHighlyNonStationary && 66 if ((signal_type == SignalClassifier::SignalType::kHighlyNonStationary &&
52 hold_counter_ == 0) || 67 hold_counter_ == 0) ||
53 initialization_phase_) { 68 initialization_phase_) {
54 peak_level_ = 69 peak_level_ =
55 std::max(peak_level_ + 0.01f * (frame_peak_level - peak_level_), 70 std::max(peak_level_ + 0.01f * (frame_peak_level - peak_level_),
56 peak_level_ * 0.995f); 71 peak_level_ * 0.995f);
57 } 72 }
58 } 73 }
59 74
60 peak_level_ = std::max(peak_level_, 30.f); 75 peak_level_ = std::max(peak_level_, kMinLevel);
61 76
62 return peak_level_; 77 return peak_level_;
63 } 78 }
64 79
65 } // namespace webrtc 80 } // 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