tor-browser

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

clipping_predictor.h (2374B)


      1 /*
      2 *  Copyright (c) 2021 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_CLIPPING_PREDICTOR_H_
     12 #define MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_H_
     13 
     14 #include <memory>
     15 #include <optional>
     16 
     17 #include "api/audio/audio_processing.h"
     18 #include "modules/audio_processing/include/audio_frame_view.h"
     19 
     20 namespace webrtc {
     21 
     22 // Frame-wise clipping prediction and clipped level step estimation. Analyzes
     23 // 10 ms multi-channel frames and estimates an analog mic level decrease step
     24 // to possibly avoid clipping when predicted. `Analyze()` and
     25 // `EstimateClippedLevelStep()` can be called in any order.
     26 class ClippingPredictor {
     27 public:
     28  virtual ~ClippingPredictor() = default;
     29 
     30  virtual void Reset() = 0;
     31 
     32  // Analyzes a 10 ms multi-channel audio frame.
     33  virtual void Analyze(const AudioFrameView<const float>& frame) = 0;
     34 
     35  // Predicts if clipping is going to occur for the specified `channel` in the
     36  // near-future and, if so, it returns a recommended analog mic level decrease
     37  // step. Returns std::nullopt if clipping is not predicted.
     38  // `level` is the current analog mic level, `default_step` is the amount the
     39  // mic level is lowered by the analog controller with every clipping event and
     40  // `min_mic_level` and `max_mic_level` is the range of allowed analog mic
     41  // levels.
     42  virtual std::optional<int> EstimateClippedLevelStep(
     43      int channel,
     44      int level,
     45      int default_step,
     46      int min_mic_level,
     47      int max_mic_level) const = 0;
     48 };
     49 
     50 // Creates a ClippingPredictor based on the provided `config`. When enabled,
     51 // the following must hold for `config`:
     52 // `window_length < reference_window_length + reference_window_delay`.
     53 // Returns `nullptr` if `config.enabled` is false.
     54 std::unique_ptr<ClippingPredictor> CreateClippingPredictor(
     55    int num_channels,
     56    const AudioProcessing::Config::GainController1::AnalogGainController::
     57        ClippingPredictor& config);
     58 
     59 }  // namespace webrtc
     60 
     61 #endif  // MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_H_