• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2018 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 "modules/audio_processing/agc2/agc2_common.h"
12 
13 #include <stdio.h>
14 
15 #include <string>
16 
17 #include "system_wrappers/include/field_trial.h"
18 
19 namespace webrtc {
20 
GetInitialSaturationMarginDb()21 float GetInitialSaturationMarginDb() {
22   constexpr char kForceInitialSaturationMarginFieldTrial[] =
23       "WebRTC-Audio-Agc2ForceInitialSaturationMargin";
24 
25   const bool use_forced_initial_saturation_margin =
26       webrtc::field_trial::IsEnabled(kForceInitialSaturationMarginFieldTrial);
27   if (use_forced_initial_saturation_margin) {
28     const std::string field_trial_string = webrtc::field_trial::FindFullName(
29         kForceInitialSaturationMarginFieldTrial);
30     float margin_db = -1;
31     if (sscanf(field_trial_string.c_str(), "Enabled-%f", &margin_db) == 1 &&
32         margin_db >= 12.f && margin_db <= 25.f) {
33       return margin_db;
34     }
35   }
36   constexpr float kDefaultInitialSaturationMarginDb = 20.f;
37   return kDefaultInitialSaturationMarginDb;
38 }
39 
GetExtraSaturationMarginOffsetDb()40 float GetExtraSaturationMarginOffsetDb() {
41   constexpr char kForceExtraSaturationMarginFieldTrial[] =
42       "WebRTC-Audio-Agc2ForceExtraSaturationMargin";
43 
44   const bool use_forced_extra_saturation_margin =
45       webrtc::field_trial::IsEnabled(kForceExtraSaturationMarginFieldTrial);
46   if (use_forced_extra_saturation_margin) {
47     const std::string field_trial_string = webrtc::field_trial::FindFullName(
48         kForceExtraSaturationMarginFieldTrial);
49     float margin_db = -1;
50     if (sscanf(field_trial_string.c_str(), "Enabled-%f", &margin_db) == 1 &&
51         margin_db >= 0.f && margin_db <= 10.f) {
52       return margin_db;
53     }
54   }
55   constexpr float kDefaultExtraSaturationMarginDb = 2.f;
56   return kDefaultExtraSaturationMarginDb;
57 }
58 }  // namespace webrtc
59