limiter_unittest.cc (2053B)
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 <algorithm> 14 #include <array> 15 #include <cstddef> 16 17 #include "api/audio/audio_view.h" 18 #include "common_audio/include/audio_util.h" 19 #include "modules/audio_processing/agc2/agc2_common.h" 20 #include "modules/audio_processing/agc2/agc2_testing_common.h" 21 #include "modules/audio_processing/logging/apm_data_dumper.h" 22 #include "test/gtest.h" 23 24 namespace webrtc { 25 26 TEST(Limiter, LimiterShouldConstructAndRun) { 27 constexpr size_t kSamplesPerChannel = 480; 28 ApmDataDumper apm_data_dumper(0); 29 30 Limiter limiter(&apm_data_dumper, kSamplesPerChannel, ""); 31 32 std::array<float, kSamplesPerChannel> buffer; 33 buffer.fill(kMaxAbsFloatS16Value); 34 limiter.Process( 35 DeinterleavedView<float>(buffer.data(), kSamplesPerChannel, 1)); 36 } 37 38 TEST(Limiter, OutputVolumeAboveThreshold) { 39 constexpr size_t kSamplesPerChannel = 480; 40 const float input_level = 41 (kMaxAbsFloatS16Value + DbfsToFloatS16(test::kLimiterMaxInputLevelDbFs)) / 42 2.f; 43 ApmDataDumper apm_data_dumper(0); 44 45 Limiter limiter(&apm_data_dumper, kSamplesPerChannel, ""); 46 47 std::array<float, kSamplesPerChannel> buffer; 48 49 // Give the level estimator time to adapt. 50 for (int i = 0; i < 5; ++i) { 51 std::fill(buffer.begin(), buffer.end(), input_level); 52 limiter.Process( 53 DeinterleavedView<float>(buffer.data(), kSamplesPerChannel, 1)); 54 } 55 56 std::fill(buffer.begin(), buffer.end(), input_level); 57 limiter.Process( 58 DeinterleavedView<float>(buffer.data(), kSamplesPerChannel, 1)); 59 for (const auto& sample : buffer) { 60 ASSERT_LT(0.9f * kMaxAbsFloatS16Value, sample); 61 } 62 } 63 64 } // namespace webrtc