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 <math.h> 15 16 #include <limits> 17 #include <vector> 18 19 #include "rtc_base/checks.h" 20 21 namespace webrtc { 22 23 namespace test { 24 25 // Level Estimator test parameters. 26 constexpr float kDecayMs = 500.f; 27 28 // Limiter parameters. 29 constexpr float kLimiterMaxInputLevelDbFs = 1.f; 30 constexpr float kLimiterKneeSmoothnessDb = 1.f; 31 constexpr float kLimiterCompressionRatio = 5.f; 32 constexpr float kPi = 3.1415926536f; 33 34 std::vector<double> LinSpace(const double l, const double r, size_t num_points); 35 36 class SineGenerator { 37 public: SineGenerator(float frequency,int rate)38 SineGenerator(float frequency, int rate) 39 : frequency_(frequency), rate_(rate) {} operator()40 float operator()() { 41 x_radians_ += frequency_ / rate_ * 2 * kPi; 42 if (x_radians_ > 2 * kPi) { 43 x_radians_ -= 2 * kPi; 44 } 45 return 1000.f * sinf(x_radians_); 46 } 47 48 private: 49 float frequency_; 50 int rate_; 51 float x_radians_ = 0.f; 52 }; 53 54 class PulseGenerator { 55 public: PulseGenerator(float frequency,int rate)56 PulseGenerator(float frequency, int rate) 57 : samples_period_( 58 static_cast<int>(static_cast<float>(rate) / frequency)) { 59 RTC_DCHECK_GT(rate, frequency); 60 } operator()61 float operator()() { 62 sample_counter_++; 63 if (sample_counter_ >= samples_period_) { 64 sample_counter_ -= samples_period_; 65 } 66 return static_cast<float>( 67 sample_counter_ == 0 ? std::numeric_limits<int16_t>::max() : 10.f); 68 } 69 70 private: 71 int samples_period_; 72 int sample_counter_ = 0; 73 }; 74 75 } // namespace test 76 } // namespace webrtc 77 78 #endif // MODULES_AUDIO_PROCESSING_AGC2_AGC2_TESTING_COMMON_H_ 79