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.h"
12
13 #include "common_audio/include/audio_util.h"
14 #include "modules/audio_processing/agc2/agc2_common.h"
15 #include "modules/audio_processing/agc2/agc2_testing_common.h"
16 #include "modules/audio_processing/agc2/vector_float_frame.h"
17 #include "modules/audio_processing/logging/apm_data_dumper.h"
18 #include "rtc_base/gunit.h"
19
20 namespace webrtc {
21
TEST(Limiter,LimiterShouldConstructAndRun)22 TEST(Limiter, LimiterShouldConstructAndRun) {
23 const int sample_rate_hz = 48000;
24 ApmDataDumper apm_data_dumper(0);
25
26 Limiter limiter(sample_rate_hz, &apm_data_dumper, "");
27
28 VectorFloatFrame vectors_with_float_frame(1, sample_rate_hz / 100,
29 kMaxAbsFloatS16Value);
30 limiter.Process(vectors_with_float_frame.float_frame_view());
31 }
32
TEST(Limiter,OutputVolumeAboveThreshold)33 TEST(Limiter, OutputVolumeAboveThreshold) {
34 const int sample_rate_hz = 48000;
35 const float input_level =
36 (kMaxAbsFloatS16Value + DbfsToFloatS16(test::kLimiterMaxInputLevelDbFs)) /
37 2.f;
38 ApmDataDumper apm_data_dumper(0);
39
40 Limiter limiter(sample_rate_hz, &apm_data_dumper, "");
41
42 // Give the level estimator time to adapt.
43 for (int i = 0; i < 5; ++i) {
44 VectorFloatFrame vectors_with_float_frame(1, sample_rate_hz / 100,
45 input_level);
46 limiter.Process(vectors_with_float_frame.float_frame_view());
47 }
48
49 VectorFloatFrame vectors_with_float_frame(1, sample_rate_hz / 100,
50 input_level);
51 limiter.Process(vectors_with_float_frame.float_frame_view());
52 rtc::ArrayView<const float> channel =
53 vectors_with_float_frame.float_frame_view().channel(0);
54
55 for (const auto& sample : channel) {
56 EXPECT_LT(0.9f * kMaxAbsFloatS16Value, sample);
57 }
58 }
59
60 } // namespace webrtc
61