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