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 #include "modules/audio_processing/agc2/limiter_db_gain_curve.h"
12
13 #include "rtc_base/gunit.h"
14
15 namespace webrtc {
16
TEST(FixedDigitalGainController2Limiter,ConstructDestruct)17 TEST(FixedDigitalGainController2Limiter, ConstructDestruct) {
18 LimiterDbGainCurve l;
19 }
20
TEST(FixedDigitalGainController2Limiter,GainCurveShouldBeMonotone)21 TEST(FixedDigitalGainController2Limiter, GainCurveShouldBeMonotone) {
22 LimiterDbGainCurve 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
TEST(FixedDigitalGainController2Limiter,GainCurveShouldBeContinuous)36 TEST(FixedDigitalGainController2Limiter, GainCurveShouldBeContinuous) {
37 LimiterDbGainCurve 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
TEST(FixedDigitalGainController2Limiter,OutputGainShouldBeLessThanFullScale)52 TEST(FixedDigitalGainController2Limiter, OutputGainShouldBeLessThanFullScale) {
53 LimiterDbGainCurve 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
61