Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 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 | |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 11 | #include "modules/audio_processing/agc2/limiter.h" |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 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" |
Alex Loiko | 507e8d1 | 2018-02-27 13:51:47 +0100 | [diff] [blame] | 17 | #include "modules/audio_processing/logging/apm_data_dumper.h" |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 18 | #include "rtc_base/gunit.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 22 | TEST(Limiter, LimiterShouldConstructAndRun) { |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 23 | const int sample_rate_hz = 48000; |
| 24 | ApmDataDumper apm_data_dumper(0); |
| 25 | |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 26 | Limiter limiter(sample_rate_hz, &apm_data_dumper, ""); |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 27 | |
| 28 | VectorFloatFrame vectors_with_float_frame(1, sample_rate_hz / 100, |
| 29 | kMaxAbsFloatS16Value); |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 30 | limiter.Process(vectors_with_float_frame.float_frame_view()); |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 31 | } |
| 32 | |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 33 | TEST(Limiter, OutputVolumeAboveThreshold) { |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 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 | |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 40 | Limiter limiter(sample_rate_hz, &apm_data_dumper, ""); |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 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); |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 46 | limiter.Process(vectors_with_float_frame.float_frame_view()); |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | VectorFloatFrame vectors_with_float_frame(1, sample_rate_hz / 100, |
| 50 | input_level); |
Alessio Bazzica | 746d46b | 2018-10-30 10:48:38 +0100 | [diff] [blame] | 51 | limiter.Process(vectors_with_float_frame.float_frame_view()); |
Alex Loiko | a05ee82 | 2018-02-20 15:58:36 +0100 | [diff] [blame] | 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 |