tor-browser

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

agc2_testing_common.h (2220B)


      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_AGC2_TESTING_COMMON_H_
     12 #define MODULES_AUDIO_PROCESSING_AGC2_AGC2_TESTING_COMMON_H_
     13 
     14 #include <cstdint>
     15 #include <limits>
     16 #include <vector>
     17 
     18 #include "rtc_base/random.h"
     19 
     20 namespace webrtc {
     21 namespace test {
     22 
     23 constexpr float kMinS16 =
     24    static_cast<float>(std::numeric_limits<int16_t>::min());
     25 constexpr float kMaxS16 =
     26    static_cast<float>(std::numeric_limits<int16_t>::max());
     27 
     28 // Level Estimator test parameters.
     29 constexpr float kDecayMs = 20.0f;
     30 
     31 // Limiter parameters.
     32 constexpr float kLimiterMaxInputLevelDbFs = 1.f;
     33 constexpr float kLimiterKneeSmoothnessDb = 1.f;
     34 constexpr float kLimiterCompressionRatio = 5.f;
     35 
     36 // Returns evenly spaced `num_points` numbers over a specified interval [l, r].
     37 std::vector<double> LinSpace(double l, double r, int num_points);
     38 
     39 // Generates white noise.
     40 class WhiteNoiseGenerator {
     41 public:
     42  WhiteNoiseGenerator(int min_amplitude, int max_amplitude);
     43  float operator()();
     44 
     45 private:
     46  Random rand_gen_;
     47  const int min_amplitude_;
     48  const int max_amplitude_;
     49 };
     50 
     51 // Generates a sine function.
     52 class SineGenerator {
     53 public:
     54  SineGenerator(float amplitude, float frequency_hz, int sample_rate_hz);
     55  float operator()();
     56 
     57 private:
     58  const float amplitude_;
     59  const float frequency_hz_;
     60  const int sample_rate_hz_;
     61  float x_radians_;
     62 };
     63 
     64 // Generates periodic pulses.
     65 class PulseGenerator {
     66 public:
     67  PulseGenerator(float pulse_amplitude,
     68                 float no_pulse_amplitude,
     69                 float frequency_hz,
     70                 int sample_rate_hz);
     71  float operator()();
     72 
     73 private:
     74  const float pulse_amplitude_;
     75  const float no_pulse_amplitude_;
     76  const int samples_period_;
     77  int sample_counter_;
     78 };
     79 
     80 }  // namespace test
     81 }  // namespace webrtc
     82 
     83 #endif  // MODULES_AUDIO_PROCESSING_AGC2_AGC2_TESTING_COMMON_H_