blob: 7bfadbb3fceb39b8712e1eca1e1112f689f401d3 [file] [log] [blame]
Alex Loiko153f11e2018-02-16 12:39:00 +01001/*
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 Loiko4ed47d02018-04-04 15:05:57 +020014#include <math.h>
15
16#include <limits>
Alex Loikoa05ee822018-02-20 15:58:36 +010017#include <vector>
18
Alex Loiko4ed47d02018-04-04 15:05:57 +020019#include "rtc_base/checks.h"
Alex Loikoa05ee822018-02-20 15:58:36 +010020
Alex Loiko153f11e2018-02-16 12:39:00 +010021namespace webrtc {
22
Alex Loikoa05ee822018-02-20 15:58:36 +010023namespace test {
24
25// Level Estimator test parameters.
Alex Loiko153f11e2018-02-16 12:39:00 +010026constexpr float kDecayMs = 500.f;
27
Alex Loikoa05ee822018-02-20 15:58:36 +010028// Limiter parameters.
29constexpr float kLimiterMaxInputLevelDbFs = 1.f;
30constexpr float kLimiterKneeSmoothnessDb = 1.f;
31constexpr float kLimiterCompressionRatio = 5.f;
Alex Loiko4ed47d02018-04-04 15:05:57 +020032constexpr float kPi = 3.1415926536f;
Alex Loikoa05ee822018-02-20 15:58:36 +010033
34std::vector<double> LinSpace(const double l, const double r, size_t num_points);
Alex Loiko4ed47d02018-04-04 15:05:57 +020035
36class 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
54class 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 Loikoa05ee822018-02-20 15:58:36 +010075} // namespace test
Alex Loiko153f11e2018-02-16 12:39:00 +010076} // namespace webrtc
77
78#endif // MODULES_AUDIO_PROCESSING_AGC2_AGC2_TESTING_COMMON_H_