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

Side by Side Diff: webrtc/modules/audio_processing/level_controller/gain_selector.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 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/gain_selector.h"
12
13 #include <math.h>
14 #include <algorithm>
15
16 #include "webrtc/base/checks.h"
17 #include "webrtc/modules/audio_processing/include/audio_processing.h"
18 #include "webrtc/modules/audio_processing/level_controller/lc_constants.h"
19
20 namespace webrtc {
21
22 GainSelector::GainSelector() {
23 Initialize(AudioProcessing::kSampleRate48kHz);
24 }
25
26 void GainSelector::Initialize(int sample_rate_hz) {
27 gain_ = 1.f;
28 frame_length_ = sample_rate_hz / 100;
hlundin-webrtc 2016/06/27 11:21:14 rtc::CheckedDivExact
peah-webrtc 2016/06/27 22:51:47 Great! Done.
29 }
30
31 /* Chooses the gain to apply by the level controller such that
hlundin-webrtc 2016/06/27 11:21:14 Use // style comments.
peah-webrtc 2016/06/27 22:51:48 Done.
32 1) The level of the stationary noise does not exceed
33 a predefined threshold.
34 2) The gain does not exceed the that has been deemed
hlundin-webrtc 2016/06/27 11:21:14 deemed to -> found to
hlundin-webrtc 2016/06/27 11:21:14 "the that" ?
peah-webrtc 2016/06/27 22:51:47 Done.
peah-webrtc 2016/06/27 22:51:47 Done.
35 to saturate the signal.
36 3) Such that the peak level achieves the target peak level.
hlundin-webrtc 2016/06/27 11:21:14 Skip "Such that"; you already have that before the
peah-webrtc 2016/06/27 22:51:47 Done.
37 4) The gain is not below 1.
38 5) The gain is not above the maximum gain. */
39 float GainSelector::GetNewGain(float peak_level,
40 float noise_energy,
41 float saturating_gain) {
42 float desired_gain = gain_;
43
44 RTC_DCHECK_LT(0.f, peak_level);
hlundin-webrtc 2016/06/27 11:21:14 This will fail if peak_level == 0.f. Is this inten
peah-webrtc 2016/06/27 22:51:47 Yes, the peak level detector should ensure a minim
hlundin-webrtc 2016/06/28 11:29:00 Acknowledged.
peah-webrtc 2016/06/28 22:19:37 Acknowledged.
45 desired_gain = kTargetLcPeakLevel / peak_level;
46
47 float max_noise_energy = kMaxLcNoisePower * frame_length_;
48 if (noise_energy * desired_gain * desired_gain > max_noise_energy) {
49 RTC_DCHECK_LE(0.f, noise_energy);
50 desired_gain = sqrtf(max_noise_energy / noise_energy);
51 }
52
53 gain_ += 0.2f * (desired_gain - gain_);
54 gain_ = std::min(gain_, saturating_gain);
55 gain_ = std::min(gain_, kMaxLcGain);
56 gain_ = std::max(gain_, 1.f);
57
58 return gain_;
59 }
60
61 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698