tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

adaptive_digital_gain_controller.h (2508B)


      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_DIGITAL_GAIN_CONTROLLER_H_
     12 #define MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_DIGITAL_GAIN_CONTROLLER_H_
     13 
     14 
     15 #include "api/audio/audio_processing.h"
     16 #include "api/audio/audio_view.h"
     17 #include "modules/audio_processing/agc2/gain_applier.h"
     18 
     19 namespace webrtc {
     20 
     21 class ApmDataDumper;
     22 
     23 // Selects the target digital gain, decides when and how quickly to adapt to the
     24 // target and applies the current gain to 10 ms frames.
     25 class AdaptiveDigitalGainController {
     26 public:
     27  // Information about a frame to process.
     28  struct FrameInfo {
     29    float speech_probability;    // Probability of speech in the [0, 1] range.
     30    float speech_level_dbfs;     // Estimated speech level (dBFS).
     31    bool speech_level_reliable;  // True with reliable speech level estimation.
     32    float noise_rms_dbfs;        // Estimated noise RMS level (dBFS).
     33    float headroom_db;           // Headroom (dB).
     34    // TODO(bugs.webrtc.org/7494): Remove `limiter_envelope_dbfs`.
     35    float limiter_envelope_dbfs;  // Envelope level from the limiter (dBFS).
     36  };
     37 
     38  AdaptiveDigitalGainController(
     39      ApmDataDumper* apm_data_dumper,
     40      const AudioProcessing::Config::GainController2::AdaptiveDigital& config,
     41      int adjacent_speech_frames_threshold);
     42  AdaptiveDigitalGainController(const AdaptiveDigitalGainController&) = delete;
     43  AdaptiveDigitalGainController& operator=(
     44      const AdaptiveDigitalGainController&) = delete;
     45 
     46  // Analyzes `info`, updates the digital gain and applies it to a 10 ms
     47  // `frame`. Supports any sample rate supported by APM.
     48  void Process(const FrameInfo& info, DeinterleavedView<float> frame);
     49 
     50 private:
     51  ApmDataDumper* const apm_data_dumper_;
     52  GainApplier gain_applier_;
     53 
     54  const AudioProcessing::Config::GainController2::AdaptiveDigital config_;
     55  const int adjacent_speech_frames_threshold_;
     56  const float max_gain_change_db_per_10ms_;
     57 
     58  int calls_since_last_gain_log_;
     59  int frames_to_gain_increase_allowed_;
     60  float last_gain_db_;
     61 };
     62 
     63 }  // namespace webrtc
     64 
     65 #endif  // MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_DIGITAL_GAIN_CONTROLLER_H_