• 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_AGC_H_
12 #define MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_MODE_LEVEL_ESTIMATOR_AGC_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include "modules/audio_processing/agc/agc.h"
18 #include "modules/audio_processing/agc2/adaptive_mode_level_estimator.h"
19 #include "modules/audio_processing/agc2/saturation_protector.h"
20 #include "modules/audio_processing/agc2/vad_with_level.h"
21 
22 namespace webrtc {
23 class AdaptiveModeLevelEstimatorAgc : public Agc {
24  public:
25   explicit AdaptiveModeLevelEstimatorAgc(ApmDataDumper* apm_data_dumper);
26 
27   // |audio| must be mono; in a multi-channel stream, provide the first (usually
28   // left) channel.
29   void Process(const int16_t* audio,
30                size_t length,
31                int sample_rate_hz) override;
32 
33   // Retrieves the difference between the target RMS level and the current
34   // signal RMS level in dB. Returns true if an update is available and false
35   // otherwise, in which case |error| should be ignored and no action taken.
36   bool GetRmsErrorDb(int* error) override;
37   void Reset() override;
38 
39   float voice_probability() const override;
40 
41  private:
42   static constexpr int kTimeUntilConfidentMs = 700;
43   static constexpr int kDefaultAgc2LevelHeadroomDbfs = -1;
44   int32_t time_in_ms_since_last_estimate_ = 0;
45   AdaptiveModeLevelEstimator level_estimator_;
46   VadWithLevel agc2_vad_;
47   float latest_voice_probability_ = 0.f;
48 };
49 }  // namespace webrtc
50 
51 #endif  // MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_MODE_LEVEL_ESTIMATOR_AGC_H_
52