Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 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 | |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 14 | #include <limits> |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Alessio Bazzica | 70b775d | 2021-04-07 12:03:11 +0200 | [diff] [blame] | 17 | #include "rtc_base/random.h" |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 18 | |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 19 | namespace webrtc { |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 20 | namespace test { |
| 21 | |
Alessio Bazzica | 70b775d | 2021-04-07 12:03:11 +0200 | [diff] [blame] | 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 | |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 27 | // Level Estimator test parameters. |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 28 | constexpr float kDecayMs = 500.f; |
| 29 | |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 30 | // Limiter parameters. |
| 31 | constexpr float kLimiterMaxInputLevelDbFs = 1.f; |
| 32 | constexpr float kLimiterKneeSmoothnessDb = 1.f; |
| 33 | constexpr float kLimiterCompressionRatio = 5.f; |
| 34 | |
Alessio Bazzica | 70b775d | 2021-04-07 12:03:11 +0200 | [diff] [blame] | 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); |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 37 | |
Alessio Bazzica | 70b775d | 2021-04-07 12:03:11 +0200 | [diff] [blame] | 38 | // Generates white noise. |
| 39 | class WhiteNoiseGenerator { |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 40 | public: |
Alessio Bazzica | 70b775d | 2021-04-07 12:03:11 +0200 | [diff] [blame] | 41 | WhiteNoiseGenerator(int min_amplitude, int max_amplitude); |
| 42 | float operator()(); |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 43 | |
| 44 | private: |
Alessio Bazzica | 70b775d | 2021-04-07 12:03:11 +0200 | [diff] [blame] | 45 | Random rand_gen_; |
| 46 | const int min_amplitude_; |
| 47 | const int max_amplitude_; |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 48 | }; |
| 49 | |
Alessio Bazzica | 70b775d | 2021-04-07 12:03:11 +0200 | [diff] [blame] | 50 | // Generates a sine function. |
| 51 | class SineGenerator { |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 52 | public: |
Alessio Bazzica | 70b775d | 2021-04-07 12:03:11 +0200 | [diff] [blame] | 53 | SineGenerator(float amplitude, float frequency_hz, int sample_rate_hz); |
| 54 | float operator()(); |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 55 | |
| 56 | private: |
Alessio Bazzica | 70b775d | 2021-04-07 12:03:11 +0200 | [diff] [blame] | 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_; |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 77 | }; |
| 78 | |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 79 | } // namespace test |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 80 | } // namespace webrtc |
| 81 | |
| 82 | #endif // MODULES_AUDIO_PROCESSING_AGC2_AGC2_TESTING_COMMON_H_ |