mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-19 08:37:54 +01:00

This simplifies the following steps: * FrameCombiner infers the sample rate from channel size * Sends the inferred sample rate to FixedDigitalLevelEstimator and Limiter. * Those classes then convert the sample rate to channel size. Along the way perform checks that the derived channel size value is a legal value (which has already been done by FrameCombiner). To: * FrameCombiner sends channel size to FixedDigitalLevelEstimator and Limiter. Bug: chromium:335805780 Change-Id: I6d2953ba5ee99771f3ff5bf4f4a049a8a29b5577 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/352581 Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42480}
61 lines
2.2 KiB
C++
61 lines
2.2 KiB
C++
/*
|
|
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "modules/audio_processing/agc2/limiter.h"
|
|
|
|
#include "api/audio/audio_frame.h"
|
|
#include "common_audio/include/audio_util.h"
|
|
#include "modules/audio_processing/agc2/agc2_common.h"
|
|
#include "modules/audio_processing/agc2/agc2_testing_common.h"
|
|
#include "modules/audio_processing/agc2/vector_float_frame.h"
|
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
|
#include "rtc_base/gunit.h"
|
|
|
|
namespace webrtc {
|
|
|
|
TEST(Limiter, LimiterShouldConstructAndRun) {
|
|
const size_t samples_per_channel = SampleRateToDefaultChannelSize(48000);
|
|
ApmDataDumper apm_data_dumper(0);
|
|
|
|
Limiter limiter(&apm_data_dumper, samples_per_channel, "");
|
|
|
|
VectorFloatFrame vectors_with_float_frame(1, samples_per_channel,
|
|
kMaxAbsFloatS16Value);
|
|
limiter.Process(vectors_with_float_frame.float_frame_view());
|
|
}
|
|
|
|
TEST(Limiter, OutputVolumeAboveThreshold) {
|
|
const size_t samples_per_channel = SampleRateToDefaultChannelSize(48000);
|
|
const float input_level =
|
|
(kMaxAbsFloatS16Value + DbfsToFloatS16(test::kLimiterMaxInputLevelDbFs)) /
|
|
2.f;
|
|
ApmDataDumper apm_data_dumper(0);
|
|
|
|
Limiter limiter(&apm_data_dumper, samples_per_channel, "");
|
|
|
|
// Give the level estimator time to adapt.
|
|
for (int i = 0; i < 5; ++i) {
|
|
VectorFloatFrame vectors_with_float_frame(1, samples_per_channel,
|
|
input_level);
|
|
limiter.Process(vectors_with_float_frame.float_frame_view());
|
|
}
|
|
|
|
VectorFloatFrame vectors_with_float_frame(1, samples_per_channel,
|
|
input_level);
|
|
limiter.Process(vectors_with_float_frame.float_frame_view());
|
|
rtc::ArrayView<const float> channel =
|
|
vectors_with_float_frame.float_frame_view().channel(0);
|
|
|
|
for (const auto& sample : channel) {
|
|
EXPECT_LT(0.9f * kMaxAbsFloatS16Value, sample);
|
|
}
|
|
}
|
|
|
|
} // namespace webrtc
|