tor-browser

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

limiter.h (2228B)


      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_LIMITER_H_
     12 #define MODULES_AUDIO_PROCESSING_AGC2_LIMITER_H_
     13 
     14 #include <array>
     15 #include <cstddef>
     16 
     17 #include "absl/strings/string_view.h"
     18 #include "api/audio/audio_view.h"
     19 #include "modules/audio_processing/agc2/agc2_common.h"
     20 #include "modules/audio_processing/agc2/fixed_digital_level_estimator.h"
     21 #include "modules/audio_processing/agc2/interpolated_gain_curve.h"
     22 
     23 namespace webrtc {
     24 class ApmDataDumper;
     25 
     26 class Limiter {
     27 public:
     28  // See `SetSamplesPerChannel()` for valid values for `samples_per_channel`.
     29  Limiter(ApmDataDumper* apm_data_dumper,
     30          size_t samples_per_channel,
     31          absl::string_view histogram_name_prefix);
     32 
     33  Limiter(const Limiter& limiter) = delete;
     34  Limiter& operator=(const Limiter& limiter) = delete;
     35  ~Limiter();
     36 
     37  // Applies limiter and hard-clipping to `signal`.
     38  void Process(DeinterleavedView<float> signal);
     39 
     40  InterpolatedGainCurve::Stats GetGainCurveStats() const;
     41 
     42  // Supported values must be
     43  // * Supported by FixedDigitalLevelEstimator
     44  // * Below or equal to kMaximalNumberOfSamplesPerChannel so that samples
     45  //   fit in the per_sample_scaling_factors_ array.
     46  void SetSamplesPerChannel(size_t samples_per_channel);
     47 
     48  // Resets the internal state.
     49  void Reset();
     50 
     51  float LastAudioLevel() const;
     52 
     53 private:
     54  const InterpolatedGainCurve interp_gain_curve_;
     55  FixedDigitalLevelEstimator level_estimator_;
     56  ApmDataDumper* const apm_data_dumper_ = nullptr;
     57 
     58  // Work array containing the sub-frame scaling factors to be interpolated.
     59  std::array<float, kSubFramesInFrame + 1> scaling_factors_ = {};
     60  std::array<float, kMaximalNumberOfSamplesPerChannel>
     61      per_sample_scaling_factors_ = {};
     62  float last_scaling_factor_ = 1.f;
     63 };
     64 
     65 }  // namespace webrtc
     66 
     67 #endif  // MODULES_AUDIO_PROCESSING_AGC2_LIMITER_H_