blob: 707981263475aa3b9f0eb35189175985bb3a7932 [file] [log] [blame]
Alex Loikoa05ee822018-02-20 15:58:36 +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#include "modules/audio_processing/agc2/limiter.h"
12
13#include "rtc_base/gunit.h"
14
15namespace webrtc {
16
17TEST(FixedDigitalGainController2Limiter, ConstructDestruct) {
18 Limiter l;
19}
20
21TEST(FixedDigitalGainController2Limiter, GainCurveShouldBeMonotone) {
22 Limiter l;
23 float last_output_level = 0.f;
24 bool has_last_output_level = false;
25 for (float level = -90.f; level <= l.max_input_level_db(); level += 0.5f) {
26 const float current_output_level = l.GetOutputLevelDbfs(level);
27 if (!has_last_output_level) {
28 last_output_level = current_output_level;
29 has_last_output_level = true;
30 }
31 EXPECT_LE(last_output_level, current_output_level);
32 last_output_level = current_output_level;
33 }
34}
35
36TEST(FixedDigitalGainController2Limiter, GainCurveShouldBeContinuous) {
37 Limiter l;
38 float last_output_level = 0.f;
39 bool has_last_output_level = false;
40 constexpr float kMaxDelta = 0.5f;
41 for (float level = -90.f; level <= l.max_input_level_db(); level += 0.5f) {
42 const float current_output_level = l.GetOutputLevelDbfs(level);
43 if (!has_last_output_level) {
44 last_output_level = current_output_level;
45 has_last_output_level = true;
46 }
47 EXPECT_LE(current_output_level, last_output_level + kMaxDelta);
48 last_output_level = current_output_level;
49 }
50}
51
52TEST(FixedDigitalGainController2Limiter, OutputGainShouldBeLessThanFullScale) {
53 Limiter l;
54 for (float level = -90.f; level <= l.max_input_level_db(); level += 0.5f) {
55 const float current_output_level = l.GetOutputLevelDbfs(level);
56 EXPECT_LE(current_output_level, 0.f);
57 }
58}
59
60} // namespace webrtc