• 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 #ifndef MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_MODE_LEVEL_ESTIMATOR_H_
12 #define MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_MODE_LEVEL_ESTIMATOR_H_
13 
14 #include <stddef.h>
15 
16 #include "modules/audio_processing/agc2/agc2_common.h"  // kFullBufferSizeMs...
17 #include "modules/audio_processing/agc2/saturation_protector.h"
18 #include "modules/audio_processing/agc2/vad_with_level.h"
19 #include "modules/audio_processing/include/audio_processing.h"
20 
21 namespace webrtc {
22 class ApmDataDumper;
23 
24 class AdaptiveModeLevelEstimator {
25  public:
26   explicit AdaptiveModeLevelEstimator(ApmDataDumper* apm_data_dumper);
27   AdaptiveModeLevelEstimator(
28       ApmDataDumper* apm_data_dumper,
29       AudioProcessing::Config::GainController2::LevelEstimator level_estimator,
30       bool use_saturation_protector,
31       float extra_saturation_margin_db);
32   void UpdateEstimation(const VadWithLevel::LevelAndProbability& vad_data);
33   float LatestLevelEstimate() const;
34   void Reset();
LevelEstimationIsConfident()35   bool LevelEstimationIsConfident() const {
36     return buffer_size_ms_ >= kFullBufferSizeMs;
37   }
38 
39  private:
40   void DebugDumpEstimate();
41 
42   const AudioProcessing::Config::GainController2::LevelEstimator
43       level_estimator_;
44   const bool use_saturation_protector_;
45   size_t buffer_size_ms_ = 0;
46   float last_estimate_with_offset_dbfs_ = kInitialSpeechLevelEstimateDbfs;
47   float estimate_numerator_ = 0.f;
48   float estimate_denominator_ = 0.f;
49   SaturationProtector saturation_protector_;
50   ApmDataDumper* const apm_data_dumper_;
51 };
52 
53 }  // namespace webrtc
54 
55 #endif  // MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_MODE_LEVEL_ESTIMATOR_H_
56