blob: 4572d9cffd70523c1b31280f825121d5453e9e54 [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 <limits>
Alex Loikoa05ee822018-02-20 15:58:36 +010015#include <vector>
16
Alessio Bazzica70b775d2021-04-07 12:03:11 +020017#include "rtc_base/random.h"
Alex Loikoa05ee822018-02-20 15:58:36 +010018
Alex Loiko153f11e2018-02-16 12:39:00 +010019namespace webrtc {
Alex Loikoa05ee822018-02-20 15:58:36 +010020namespace test {
21
Alessio Bazzica70b775d2021-04-07 12:03:11 +020022constexpr float kMinS16 =
23 static_cast<float>(std::numeric_limits<int16_t>::min());
24constexpr float kMaxS16 =
25 static_cast<float>(std::numeric_limits<int16_t>::max());
26
Alex Loikoa05ee822018-02-20 15:58:36 +010027// Level Estimator test parameters.
Alex Loiko153f11e2018-02-16 12:39:00 +010028constexpr float kDecayMs = 500.f;
29
Alex Loikoa05ee822018-02-20 15:58:36 +010030// Limiter parameters.
31constexpr float kLimiterMaxInputLevelDbFs = 1.f;
32constexpr float kLimiterKneeSmoothnessDb = 1.f;
33constexpr float kLimiterCompressionRatio = 5.f;
34
Alessio Bazzica70b775d2021-04-07 12:03:11 +020035// Returns evenly spaced `num_points` numbers over a specified interval [l, r].
36std::vector<double> LinSpace(double l, double r, int num_points);
Alex Loiko4ed47d02018-04-04 15:05:57 +020037
Alessio Bazzica70b775d2021-04-07 12:03:11 +020038// Generates white noise.
39class WhiteNoiseGenerator {
Alex Loiko4ed47d02018-04-04 15:05:57 +020040 public:
Alessio Bazzica70b775d2021-04-07 12:03:11 +020041 WhiteNoiseGenerator(int min_amplitude, int max_amplitude);
42 float operator()();
Alex Loiko4ed47d02018-04-04 15:05:57 +020043
44 private:
Alessio Bazzica70b775d2021-04-07 12:03:11 +020045 Random rand_gen_;
46 const int min_amplitude_;
47 const int max_amplitude_;
Alex Loiko4ed47d02018-04-04 15:05:57 +020048};
49
Alessio Bazzica70b775d2021-04-07 12:03:11 +020050// Generates a sine function.
51class SineGenerator {
Alex Loiko4ed47d02018-04-04 15:05:57 +020052 public:
Alessio Bazzica70b775d2021-04-07 12:03:11 +020053 SineGenerator(float amplitude, float frequency_hz, int sample_rate_hz);
54 float operator()();
Alex Loiko4ed47d02018-04-04 15:05:57 +020055
56 private:
Alessio Bazzica70b775d2021-04-07 12:03:11 +020057 const float amplitude_;
58 const float frequency_hz_;
59 const int sample_rate_hz_;
60 float x_radians_;
61};
62
63// Generates periodic pulses.
64class 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 Loiko4ed47d02018-04-04 15:05:57 +020077};
78
Alex Loikoa05ee822018-02-20 15:58:36 +010079} // namespace test
Alex Loiko153f11e2018-02-16 12:39:00 +010080} // namespace webrtc
81
82#endif // MODULES_AUDIO_PROCESSING_AGC2_AGC2_TESTING_COMMON_H_