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 <math.h> |
| 15 | |
| 16 | #include <limits> |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 19 | #include "rtc_base/checks.h" |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 20 | |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 21 | namespace webrtc { |
| 22 | |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 23 | namespace test { |
| 24 | |
| 25 | // Level Estimator test parameters. |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 26 | constexpr float kDecayMs = 500.f; |
| 27 | |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 28 | // Limiter parameters. |
| 29 | constexpr float kLimiterMaxInputLevelDbFs = 1.f; |
| 30 | constexpr float kLimiterKneeSmoothnessDb = 1.f; |
| 31 | constexpr float kLimiterCompressionRatio = 5.f; |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 32 | constexpr float kPi = 3.1415926536f; |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 33 | |
| 34 | std::vector<double> LinSpace(const double l, const double r, size_t num_points); |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 35 | |
| 36 | class SineGenerator { |
| 37 | public: |
| 38 | SineGenerator(float frequency, int rate) |
| 39 | : frequency_(frequency), rate_(rate) {} |
| 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: |
| 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 | } |
| 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 | |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 75 | } // namespace test |
Alex Loiko | 153f11e | 2018-02-16 12:39:00 +0100 | [diff] [blame] | 76 | } // namespace webrtc |
| 77 | |
| 78 | #endif // MODULES_AUDIO_PROCESSING_AGC2_AGC2_TESTING_COMMON_H_ |