ClippingPredictor/Evaluator/LevelBuffer and GainMap: Move to agc2

Bug: webrtc:7494
Change-Id: If88795fe34a73faa267a9c0bd5250e36455d4d81
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/277741
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Commit-Queue: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38296}
This commit is contained in:
Hanna Silen 2022-10-04 16:06:19 +02:00 committed by WebRTC LUCI CQ
parent d9b9c29143
commit cfbda697ec
16 changed files with 115 additions and 89 deletions

View file

@ -418,6 +418,7 @@ if (rtc_include_tests) {
"agc2:adaptive_digital_unittests",
"agc2:biquad_filter_unittests",
"agc2:fixed_digital_unittests",
"agc2:input_volume_controller_unittests",
"agc2:noise_estimator_unittests",
"agc2:test_utils",
"agc2:vad_wrapper_unittests",
@ -525,7 +526,7 @@ if (rtc_include_tests) {
"../../rtc_base:logging",
"../../rtc_base:safe_conversions",
"../../rtc_base:safe_minmax",
"agc:gain_map",
"agc2:gain_map",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}

View file

@ -19,10 +19,7 @@ rtc_library("agc") {
]
configs += [ "..:apm_debug_dump" ]
deps = [
":clipping_predictor",
":clipping_predictor_evaluator",
":gain_control_interface",
":gain_map",
":level_estimation",
"..:api",
"..:apm_logging",
@ -37,6 +34,9 @@ rtc_library("agc") {
"../../../rtc_base:safe_minmax",
"../../../system_wrappers:field_trial",
"../../../system_wrappers:metrics",
"../agc2:clipping_predictor",
"../agc2:clipping_predictor_evaluator",
"../agc2:gain_map",
"../vad",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
@ -56,48 +56,6 @@ rtc_library("analog_gain_stats_reporter") {
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
rtc_library("clipping_predictor") {
sources = [
"clipping_predictor.cc",
"clipping_predictor.h",
]
deps = [
":clipping_predictor_level_buffer",
":gain_map",
"..:api",
"..:audio_frame_view",
"../../../common_audio",
"../../../rtc_base:checks",
"../../../rtc_base:logging",
"../../../rtc_base:safe_minmax",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
rtc_library("clipping_predictor_evaluator") {
sources = [
"clipping_predictor_evaluator.cc",
"clipping_predictor_evaluator.h",
]
deps = [
"../../../rtc_base:checks",
"../../../rtc_base:logging",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
rtc_library("clipping_predictor_level_buffer") {
sources = [
"clipping_predictor_level_buffer.cc",
"clipping_predictor_level_buffer.h",
]
deps = [
"../../../rtc_base:checks",
"../../../rtc_base:logging",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
rtc_library("level_estimation") {
sources = [
"agc.cc",
@ -147,19 +105,12 @@ rtc_library("legacy_agc") {
}
}
rtc_source_set("gain_map") {
sources = [ "gain_map_internal.h" ]
}
if (rtc_include_tests) {
rtc_library("agc_unittests") {
testonly = true
sources = [
"agc_manager_direct_unittest.cc",
"analog_gain_stats_reporter_unittest.cc",
"clipping_predictor_evaluator_unittest.cc",
"clipping_predictor_level_buffer_unittest.cc",
"clipping_predictor_unittest.cc",
"loudness_histogram_unittest.cc",
"mock_agc.h",
]
@ -168,9 +119,6 @@ if (rtc_include_tests) {
deps = [
":agc",
":analog_gain_stats_reporter",
":clipping_predictor",
":clipping_predictor_evaluator",
":clipping_predictor_level_buffer",
":gain_control_interface",
":level_estimation",
"..:mocks",

View file

@ -16,7 +16,7 @@
#include "api/array_view.h"
#include "common_audio/include/audio_util.h"
#include "modules/audio_processing/agc/gain_control.h"
#include "modules/audio_processing/agc/gain_map_internal.h"
#include "modules/audio_processing/agc2/gain_map_internal.h"
#include "modules/audio_processing/include/audio_frame_view.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"

View file

@ -17,8 +17,8 @@
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "modules/audio_processing/agc/agc.h"
#include "modules/audio_processing/agc/clipping_predictor.h"
#include "modules/audio_processing/agc/clipping_predictor_evaluator.h"
#include "modules/audio_processing/agc2/clipping_predictor.h"
#include "modules/audio_processing/agc2/clipping_predictor_evaluator.h"
#include "modules/audio_processing/audio_buffer.h"
#include "modules/audio_processing/include/audio_processing.h"
#include "modules/audio_processing/logging/apm_data_dumper.h"

View file

@ -69,6 +69,51 @@ rtc_library("biquad_filter") {
]
}
rtc_library("clipping_predictor") {
visibility = [
"../agc:agc",
"./*",
]
sources = [
"clipping_predictor.cc",
"clipping_predictor.h",
"clipping_predictor_level_buffer.cc",
"clipping_predictor_level_buffer.h",
]
deps = [
":gain_map",
"..:api",
"..:audio_frame_view",
"../../../common_audio",
"../../../rtc_base:checks",
"../../../rtc_base:logging",
"../../../rtc_base:safe_minmax",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
rtc_library("clipping_predictor_evaluator") {
visibility = [
"../agc:agc",
"./*",
]
sources = [
"clipping_predictor_evaluator.cc",
"clipping_predictor_evaluator.h",
]
deps = [
"../../../rtc_base:checks",
"../../../rtc_base:logging",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
rtc_source_set("common") {
sources = [ "agc2_common.h" ]
}
@ -126,6 +171,16 @@ rtc_library("gain_applier") {
]
}
rtc_source_set("gain_map") {
visibility = [
"..:analog_mic_simulation",
"../agc:agc",
"./*",
]
sources = [ "gain_map_internal.h" ]
}
rtc_library("noise_level_estimator") {
sources = [
"noise_level_estimator.cc",
@ -256,6 +311,29 @@ rtc_library("fixed_digital_unittests") {
]
}
rtc_library("input_volume_controller_unittests") {
testonly = true
sources = [
"clipping_predictor_evaluator_unittest.cc",
"clipping_predictor_level_buffer_unittest.cc",
"clipping_predictor_unittest.cc",
]
configs += [ "..:apm_debug_dump" ]
deps = [
":clipping_predictor",
":clipping_predictor_evaluator",
":gain_map",
"../../../rtc_base:checks",
"../../../rtc_base:random",
"../../../rtc_base:safe_conversions",
"../../../test:test_support",
]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
rtc_library("noise_estimator_unittests") {
testonly = true
configs += [ "..:apm_debug_dump" ]

View file

@ -8,14 +8,14 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_processing/agc/clipping_predictor.h"
#include "modules/audio_processing/agc2/clipping_predictor.h"
#include <algorithm>
#include <memory>
#include "common_audio/include/audio_util.h"
#include "modules/audio_processing/agc/clipping_predictor_level_buffer.h"
#include "modules/audio_processing/agc/gain_map_internal.h"
#include "modules/audio_processing/agc2/clipping_predictor_level_buffer.h"
#include "modules/audio_processing/agc2/gain_map_internal.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_minmax.h"

View file

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_AUDIO_PROCESSING_AGC_CLIPPING_PREDICTOR_H_
#define MODULES_AUDIO_PROCESSING_AGC_CLIPPING_PREDICTOR_H_
#ifndef MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_H_
#define MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_H_
#include <memory>
#include <vector>
@ -46,7 +46,6 @@ class ClippingPredictor {
int default_step,
int min_mic_level,
int max_mic_level) const = 0;
};
// Creates a ClippingPredictor based on the provided `config`. When enabled,
@ -60,4 +59,4 @@ std::unique_ptr<ClippingPredictor> CreateClippingPredictor(
} // namespace webrtc
#endif // MODULES_AUDIO_PROCESSING_AGC_CLIPPING_PREDICTOR_H_
#endif // MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_H_

View file

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_processing/agc/clipping_predictor_evaluator.h"
#include "modules/audio_processing/agc2/clipping_predictor_evaluator.h"
#include <algorithm>

View file

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_AUDIO_PROCESSING_AGC_CLIPPING_PREDICTOR_EVALUATOR_H_
#define MODULES_AUDIO_PROCESSING_AGC_CLIPPING_PREDICTOR_EVALUATOR_H_
#ifndef MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_EVALUATOR_H_
#define MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_EVALUATOR_H_
#include <vector>
@ -119,4 +119,4 @@ absl::optional<ClippingPredictionMetrics> ComputeClippingPredictionMetrics(
} // namespace webrtc
#endif // MODULES_AUDIO_PROCESSING_AGC_CLIPPING_PREDICTOR_EVALUATOR_H_
#endif // MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_EVALUATOR_H_

View file

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_processing/agc/clipping_predictor_evaluator.h"
#include "modules/audio_processing/agc2/clipping_predictor_evaluator.h"
#include <cstdint>
#include <memory>

View file

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_processing/agc/clipping_predictor_level_buffer.h"
#include "modules/audio_processing/agc2/clipping_predictor_level_buffer.h"
#include <algorithm>
#include <cmath>

View file

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_AUDIO_PROCESSING_AGC_CLIPPING_PREDICTOR_LEVEL_BUFFER_H_
#define MODULES_AUDIO_PROCESSING_AGC_CLIPPING_PREDICTOR_LEVEL_BUFFER_H_
#ifndef MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_LEVEL_BUFFER_H_
#define MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_LEVEL_BUFFER_H_
#include <memory>
#include <vector>
@ -68,4 +68,4 @@ class ClippingPredictorLevelBuffer {
} // namespace webrtc
#endif // MODULES_AUDIO_PROCESSING_AGC_CLIPPING_PREDICTOR_LEVEL_BUFFER_H_
#endif // MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_LEVEL_BUFFER_H_

View file

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_processing/agc/clipping_predictor_level_buffer.h"
#include "modules/audio_processing/agc2/clipping_predictor_level_buffer.h"
#include <algorithm>

View file

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_processing/agc/clipping_predictor.h"
#include "modules/audio_processing/agc2/clipping_predictor.h"
#include <cstdint>
#include <limits>

View file

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_AUDIO_PROCESSING_AGC_GAIN_MAP_INTERNAL_H_
#define MODULES_AUDIO_PROCESSING_AGC_GAIN_MAP_INTERNAL_H_
#ifndef MODULES_AUDIO_PROCESSING_AGC2_GAIN_MAP_INTERNAL_H_
#define MODULES_AUDIO_PROCESSING_AGC2_GAIN_MAP_INTERNAL_H_
namespace webrtc {
@ -37,4 +37,4 @@ static const int kGainMap[kGainMapSize] = {
} // namespace webrtc
#endif // MODULES_AUDIO_PROCESSING_AGC_GAIN_MAP_INTERNAL_H_
#endif // MODULES_AUDIO_PROCESSING_AGC2_GAIN_MAP_INTERNAL_H_

View file

@ -14,7 +14,7 @@
#include <memory>
#include "absl/types/optional.h"
#include "modules/audio_processing/agc/gain_map_internal.h"
#include "modules/audio_processing/agc2/gain_map_internal.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/numerics/safe_minmax.h"
@ -94,8 +94,8 @@ class FakeRecordingDeviceLinear final : public FakeRecordingDeviceWorker {
}
};
float ComputeAgc1LinearFactor(const absl::optional<int>& undo_mic_level,
int mic_level) {
float ComputeAgcLinearFactor(const absl::optional<int>& undo_mic_level,
int mic_level) {
// If an undo level is specified, virtually restore the unmodified
// microphone level; otherwise simulate the mic gain only.
const int undo_level =
@ -105,14 +105,14 @@ float ComputeAgc1LinearFactor(const absl::optional<int>& undo_mic_level,
// Roughly dB-scale fake recording device. Valid levels are [0, 255]. The mic
// applies a gain from kGainMap in agc/gain_map_internal.h.
class FakeRecordingDeviceAgc1 final : public FakeRecordingDeviceWorker {
class FakeRecordingDeviceAgc final : public FakeRecordingDeviceWorker {
public:
explicit FakeRecordingDeviceAgc1(const int initial_mic_level)
explicit FakeRecordingDeviceAgc(const int initial_mic_level)
: FakeRecordingDeviceWorker(initial_mic_level) {}
~FakeRecordingDeviceAgc1() override = default;
~FakeRecordingDeviceAgc() override = default;
void ModifyBufferInt16(rtc::ArrayView<int16_t> buffer) override {
const float scaling_factor =
ComputeAgc1LinearFactor(undo_mic_level_, mic_level_);
ComputeAgcLinearFactor(undo_mic_level_, mic_level_);
const size_t number_of_samples = buffer.size();
int16_t* data = buffer.data();
for (size_t i = 0; i < number_of_samples; ++i) {
@ -121,7 +121,7 @@ class FakeRecordingDeviceAgc1 final : public FakeRecordingDeviceWorker {
}
void ModifyBufferFloat(ChannelBuffer<float>* buffer) override {
const float scaling_factor =
ComputeAgc1LinearFactor(undo_mic_level_, mic_level_);
ComputeAgcLinearFactor(undo_mic_level_, mic_level_);
for (size_t c = 0; c < buffer->num_channels(); ++c) {
for (size_t i = 0; i < buffer->num_frames(); ++i) {
buffer->channels()[c][i] =
@ -145,7 +145,7 @@ FakeRecordingDevice::FakeRecordingDevice(int initial_mic_level,
worker_ = std::make_unique<FakeRecordingDeviceLinear>(initial_mic_level);
break;
case 2:
worker_ = std::make_unique<FakeRecordingDeviceAgc1>(initial_mic_level);
worker_ = std::make_unique<FakeRecordingDeviceAgc>(initial_mic_level);
break;
default:
RTC_DCHECK_NOTREACHED();