andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/audio_processing_impl.h" |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 12 | |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 13 | #include <array> |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 14 | #include <memory> |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 15 | #include <tuple> |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 16 | |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
Niels Möller | 105711e | 2022-06-14 15:48:26 +0200 | [diff] [blame] | 18 | #include "api/make_ref_counted.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 19 | #include "api/scoped_refptr.h" |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 20 | #include "modules/audio_processing/include/audio_processing.h" |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 21 | #include "modules/audio_processing/optionally_built_submodule_creators.h" |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 22 | #include "modules/audio_processing/test/audio_processing_builder_for_testing.h" |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 23 | #include "modules/audio_processing/test/echo_canceller_test_tools.h" |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 24 | #include "modules/audio_processing/test/echo_control_mock.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "modules/audio_processing/test/test_utils.h" |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 26 | #include "rtc_base/checks.h" |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 27 | #include "rtc_base/random.h" |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 28 | #include "rtc_base/strings/string_builder.h" |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 29 | #include "test/field_trial.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "test/gmock.h" |
| 31 | #include "test/gtest.h" |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 32 | |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 33 | namespace webrtc { |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 34 | namespace { |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 35 | |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 36 | using ::testing::Invoke; |
| 37 | using ::testing::NotNull; |
| 38 | |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 39 | class MockInitialize : public AudioProcessingImpl { |
| 40 | public: |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame] | 41 | MockInitialize() : AudioProcessingImpl() {} |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 42 | |
Per Åhgren | 0ade983 | 2020-09-01 23:57:20 +0200 | [diff] [blame] | 43 | MOCK_METHOD(void, InitializeLocked, (), (override)); |
Niels Möller | 5b74723 | 2021-07-26 17:16:25 +0200 | [diff] [blame] | 44 | void RealInitializeLocked() { |
| 45 | AssertLockedForTest(); |
Per Åhgren | 0ade983 | 2020-09-01 23:57:20 +0200 | [diff] [blame] | 46 | AudioProcessingImpl::InitializeLocked(); |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 47 | } |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 48 | |
Danil Chapovalov | 704fb55 | 2020-05-18 15:10:15 +0200 | [diff] [blame] | 49 | MOCK_METHOD(void, AddRef, (), (const, override)); |
| 50 | MOCK_METHOD(rtc::RefCountReleaseStatus, Release, (), (const, override)); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 53 | // Creates MockEchoControl instances and provides a raw pointer access to |
| 54 | // the next created one. The raw pointer is meant to be used with gmock. |
| 55 | // Returning a pointer of the next created MockEchoControl instance is necessary |
| 56 | // for the following reasons: (i) gmock expectations must be set before any call |
| 57 | // occurs, (ii) APM is initialized the first time that |
| 58 | // AudioProcessingImpl::ProcessStream() is called and the initialization leads |
| 59 | // to the creation of a new EchoControl object. |
| 60 | class MockEchoControlFactory : public EchoControlFactory { |
| 61 | public: |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 62 | MockEchoControlFactory() : next_mock_(std::make_unique<MockEchoControl>()) {} |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 63 | // Returns a pointer to the next MockEchoControl that this factory creates. |
| 64 | MockEchoControl* GetNext() const { return next_mock_.get(); } |
Per Åhgren | 4e5c709 | 2019-11-01 20:44:11 +0100 | [diff] [blame] | 65 | std::unique_ptr<EchoControl> Create(int sample_rate_hz, |
| 66 | int num_render_channels, |
| 67 | int num_capture_channels) override { |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 68 | std::unique_ptr<EchoControl> mock = std::move(next_mock_); |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 69 | next_mock_ = std::make_unique<MockEchoControl>(); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 70 | return mock; |
| 71 | } |
| 72 | |
| 73 | private: |
| 74 | std::unique_ptr<MockEchoControl> next_mock_; |
| 75 | }; |
| 76 | |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 77 | // Mocks EchoDetector and records the first samples of the last analyzed render |
| 78 | // stream frame. Used to check what data is read by an EchoDetector |
| 79 | // implementation injected into an APM. |
| 80 | class TestEchoDetector : public EchoDetector { |
| 81 | public: |
| 82 | TestEchoDetector() |
| 83 | : analyze_render_audio_called_(false), |
| 84 | last_render_audio_first_sample_(0.f) {} |
| 85 | ~TestEchoDetector() override = default; |
| 86 | void AnalyzeRenderAudio(rtc::ArrayView<const float> render_audio) override { |
| 87 | last_render_audio_first_sample_ = render_audio[0]; |
| 88 | analyze_render_audio_called_ = true; |
| 89 | } |
| 90 | void AnalyzeCaptureAudio(rtc::ArrayView<const float> capture_audio) override { |
| 91 | } |
| 92 | void Initialize(int capture_sample_rate_hz, |
| 93 | int num_capture_channels, |
| 94 | int render_sample_rate_hz, |
| 95 | int num_render_channels) override {} |
| 96 | EchoDetector::Metrics GetMetrics() const override { return {}; } |
| 97 | // Returns true if AnalyzeRenderAudio() has been called at least once. |
| 98 | bool analyze_render_audio_called() const { |
| 99 | return analyze_render_audio_called_; |
| 100 | } |
| 101 | // Returns the first sample of the last analyzed render frame. |
| 102 | float last_render_audio_first_sample() const { |
| 103 | return last_render_audio_first_sample_; |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | bool analyze_render_audio_called_; |
| 108 | float last_render_audio_first_sample_; |
| 109 | }; |
| 110 | |
| 111 | // Mocks CustomProcessing and applies ProcessSample() to all the samples. |
| 112 | // Meant to be injected into an APM to modify samples in a known and detectable |
| 113 | // way. |
| 114 | class TestRenderPreProcessor : public CustomProcessing { |
| 115 | public: |
| 116 | TestRenderPreProcessor() = default; |
| 117 | ~TestRenderPreProcessor() = default; |
| 118 | void Initialize(int sample_rate_hz, int num_channels) override {} |
| 119 | void Process(AudioBuffer* audio) override { |
| 120 | for (size_t k = 0; k < audio->num_channels(); ++k) { |
Per Åhgren | d47941e | 2019-08-22 11:51:13 +0200 | [diff] [blame] | 121 | rtc::ArrayView<float> channel_view(audio->channels()[k], |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 122 | audio->num_frames()); |
| 123 | std::transform(channel_view.begin(), channel_view.end(), |
| 124 | channel_view.begin(), ProcessSample); |
| 125 | } |
Mirko Bonadei | c4dd730 | 2019-02-25 09:12:02 +0100 | [diff] [blame] | 126 | } |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 127 | std::string ToString() const override { return "TestRenderPreProcessor"; } |
| 128 | void SetRuntimeSetting(AudioProcessing::RuntimeSetting setting) override {} |
| 129 | // Modifies a sample. This member is used in Process() to modify a frame and |
| 130 | // it is publicly visible to enable tests. |
| 131 | static constexpr float ProcessSample(float x) { return 2.f * x; } |
| 132 | }; |
| 133 | |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 134 | // Creates a simple `AudioProcessing` instance for APM input volume testing |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 135 | // with AGC1 analog and/or AGC2 input volume controller enabled and AGC2 |
| 136 | // digital controller enabled. |
| 137 | rtc::scoped_refptr<AudioProcessing> CreateApmForInputVolumeTest( |
| 138 | bool agc1_analog_gain_controller_enabled, |
| 139 | bool agc2_input_volume_controller_enabled) { |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 140 | webrtc::AudioProcessing::Config config; |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 141 | // Enable AGC1 analog controller. |
| 142 | config.gain_controller1.enabled = agc1_analog_gain_controller_enabled; |
| 143 | config.gain_controller1.analog_gain_controller.enabled = |
| 144 | agc1_analog_gain_controller_enabled; |
| 145 | // Enable AG2 input volume controller |
| 146 | config.gain_controller2.input_volume_controller.enabled = |
| 147 | agc2_input_volume_controller_enabled; |
| 148 | // Enable AGC2 adaptive digital controller. |
Alessio Bazzica | 9ea5381 | 2022-10-13 17:09:15 +0200 | [diff] [blame] | 149 | config.gain_controller1.analog_gain_controller.enable_digital_adaptive = |
| 150 | false; |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 151 | config.gain_controller2.enabled = true; |
| 152 | config.gain_controller2.adaptive_digital.enabled = true; |
| 153 | |
| 154 | auto apm(AudioProcessingBuilder().Create()); |
| 155 | apm->ApplyConfig(config); |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 156 | |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 157 | return apm; |
| 158 | } |
| 159 | |
| 160 | // Runs `apm` input processing for volume adjustments for `num_frames` random |
| 161 | // frames starting from the volume `initial_volume`. This includes three steps: |
| 162 | // 1) Set the input volume 2) Process the stream 3) Set the new recommended |
| 163 | // input volume. Returns the new recommended input volume. |
| 164 | int ProcessInputVolume(AudioProcessing& apm, |
| 165 | int num_frames, |
| 166 | int initial_volume) { |
| 167 | constexpr int kSampleRateHz = 48000; |
| 168 | constexpr int kNumChannels = 1; |
| 169 | std::array<float, kSampleRateHz / 100> buffer; |
| 170 | float* channel_pointers[] = {buffer.data()}; |
| 171 | StreamConfig stream_config(/*sample_rate_hz=*/kSampleRateHz, |
| 172 | /*num_channels=*/kNumChannels); |
| 173 | int recommended_input_volume = initial_volume; |
| 174 | for (int i = 0; i < num_frames; ++i) { |
| 175 | Random random_generator(2341U); |
| 176 | RandomizeSampleVector(&random_generator, buffer); |
| 177 | |
| 178 | apm.set_stream_analog_level(recommended_input_volume); |
| 179 | apm.ProcessStream(channel_pointers, stream_config, stream_config, |
| 180 | channel_pointers); |
| 181 | recommended_input_volume = apm.recommended_stream_analog_level(); |
| 182 | } |
| 183 | return recommended_input_volume; |
| 184 | } |
| 185 | |
| 186 | constexpr char kMinMicLevelFieldTrial[] = |
| 187 | "WebRTC-Audio-2ndAgcMinMicLevelExperiment"; |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 188 | constexpr char kMinInputVolumeFieldTrial[] = "WebRTC-Audio-Agc2-MinInputVolume"; |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 189 | constexpr int kMinInputVolume = 12; |
| 190 | |
| 191 | std::string GetMinMicLevelExperimentFieldTrial(absl::optional<int> value) { |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 192 | char field_trial_buffer[128]; |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 193 | rtc::SimpleStringBuilder builder(field_trial_buffer); |
| 194 | if (value.has_value()) { |
| 195 | RTC_DCHECK_GE(*value, 0); |
| 196 | RTC_DCHECK_LE(*value, 255); |
| 197 | builder << kMinMicLevelFieldTrial << "/Enabled-" << *value << "/"; |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 198 | builder << kMinInputVolumeFieldTrial << "/Enabled-" << *value << "/"; |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 199 | } else { |
| 200 | builder << kMinMicLevelFieldTrial << "/Disabled/"; |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 201 | builder << kMinInputVolumeFieldTrial << "/Disabled/"; |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 202 | } |
| 203 | return builder.str(); |
| 204 | } |
| 205 | |
| 206 | // TODO(webrtc:7494): Remove the fieldtrial from the input volume tests when |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 207 | // "WebRTC-Audio-2ndAgcMinMicLevelExperiment" and |
| 208 | // "WebRTC-Audio-Agc2-MinInputVolume" are removed. |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 209 | class InputVolumeStartupParameterizedTest |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 210 | : public ::testing::TestWithParam< |
| 211 | std::tuple<int, absl::optional<int>, bool, bool>> { |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 212 | protected: |
| 213 | InputVolumeStartupParameterizedTest() |
| 214 | : field_trials_( |
Alessio Bazzica | 9ea5381 | 2022-10-13 17:09:15 +0200 | [diff] [blame] | 215 | GetMinMicLevelExperimentFieldTrial(std::get<1>(GetParam()))) {} |
| 216 | int GetStartupVolume() const { return std::get<0>(GetParam()); } |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 217 | int GetMinVolume() const { |
Alessio Bazzica | 9ea5381 | 2022-10-13 17:09:15 +0200 | [diff] [blame] | 218 | return std::get<1>(GetParam()).value_or(kMinInputVolume); |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 219 | } |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 220 | bool GetAgc1AnalogControllerEnabled() const { |
| 221 | return std::get<2>(GetParam()); |
| 222 | } |
| 223 | bool GetAgc2InputVolumeControllerEnabled() const { |
| 224 | return std::get<3>(GetParam()); |
| 225 | } |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 226 | |
| 227 | private: |
| 228 | test::ScopedFieldTrials field_trials_; |
| 229 | }; |
| 230 | |
| 231 | class InputVolumeNotZeroParameterizedTest |
| 232 | : public ::testing::TestWithParam< |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 233 | std::tuple<int, int, absl::optional<int>, bool, bool>> { |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 234 | protected: |
| 235 | InputVolumeNotZeroParameterizedTest() |
| 236 | : field_trials_( |
| 237 | GetMinMicLevelExperimentFieldTrial(std::get<2>(GetParam()))) {} |
| 238 | int GetStartupVolume() const { return std::get<0>(GetParam()); } |
| 239 | int GetVolume() const { return std::get<1>(GetParam()); } |
| 240 | int GetMinVolume() const { |
| 241 | return std::get<2>(GetParam()).value_or(kMinInputVolume); |
| 242 | } |
| 243 | bool GetMinMicLevelExperimentEnabled() { |
| 244 | return std::get<2>(GetParam()).has_value(); |
| 245 | } |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 246 | bool GetAgc1AnalogControllerEnabled() const { |
| 247 | return std::get<3>(GetParam()); |
| 248 | } |
| 249 | bool GetAgc2InputVolumeControllerEnabled() const { |
| 250 | return std::get<4>(GetParam()); |
| 251 | } |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 252 | |
| 253 | private: |
| 254 | test::ScopedFieldTrials field_trials_; |
| 255 | }; |
| 256 | |
| 257 | class InputVolumeZeroParameterizedTest |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 258 | : public ::testing::TestWithParam< |
| 259 | std::tuple<int, absl::optional<int>, bool, bool>> { |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 260 | protected: |
| 261 | InputVolumeZeroParameterizedTest() |
| 262 | : field_trials_( |
| 263 | GetMinMicLevelExperimentFieldTrial(std::get<1>(GetParam()))) {} |
| 264 | int GetStartupVolume() const { return std::get<0>(GetParam()); } |
| 265 | int GetMinVolume() const { |
| 266 | return std::get<1>(GetParam()).value_or(kMinInputVolume); |
| 267 | } |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 268 | bool GetAgc1AnalogControllerEnabled() const { |
| 269 | return std::get<2>(GetParam()); |
| 270 | } |
| 271 | bool GetAgc2InputVolumeControllerEnabled() const { |
| 272 | return std::get<3>(GetParam()); |
| 273 | } |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 274 | |
| 275 | private: |
| 276 | test::ScopedFieldTrials field_trials_; |
| 277 | }; |
| 278 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 279 | } // namespace |
| 280 | |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 281 | TEST(AudioProcessingImplTest, AudioParameterChangeTriggersInit) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame] | 282 | MockInitialize mock; |
| 283 | ON_CALL(mock, InitializeLocked) |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 284 | .WillByDefault(Invoke(&mock, &MockInitialize::RealInitializeLocked)); |
| 285 | |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame] | 286 | EXPECT_CALL(mock, InitializeLocked).Times(1); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 287 | mock.Initialize(); |
| 288 | |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 289 | constexpr size_t kMaxSampleRateHz = 32000; |
| 290 | constexpr size_t kMaxNumChannels = 2; |
| 291 | std::array<int16_t, kMaxNumChannels * kMaxSampleRateHz / 100> frame; |
| 292 | frame.fill(0); |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 293 | StreamConfig config(16000, 1); |
peah | 2ace3f9 | 2016-09-10 04:42:27 -0700 | [diff] [blame] | 294 | // Call with the default parameters; there should be an init. |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame] | 295 | EXPECT_CALL(mock, InitializeLocked).Times(0); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 296 | EXPECT_NOERR(mock.ProcessStream(frame.data(), config, config, frame.data())); |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 297 | EXPECT_NOERR( |
| 298 | mock.ProcessReverseStream(frame.data(), config, config, frame.data())); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 299 | |
| 300 | // New sample rate. (Only impacts ProcessStream). |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 301 | config = StreamConfig(32000, 1); |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame] | 302 | EXPECT_CALL(mock, InitializeLocked).Times(1); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 303 | EXPECT_NOERR(mock.ProcessStream(frame.data(), config, config, frame.data())); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 304 | |
| 305 | // New number of channels. |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 306 | config = StreamConfig(32000, 2); |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame] | 307 | EXPECT_CALL(mock, InitializeLocked).Times(2); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 308 | EXPECT_NOERR(mock.ProcessStream(frame.data(), config, config, frame.data())); |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 309 | EXPECT_NOERR( |
| 310 | mock.ProcessReverseStream(frame.data(), config, config, frame.data())); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 311 | |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 312 | // A new sample rate passed to ProcessReverseStream should cause an init. |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 313 | config = StreamConfig(16000, 2); |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame] | 314 | EXPECT_CALL(mock, InitializeLocked).Times(1); |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 315 | EXPECT_NOERR( |
| 316 | mock.ProcessReverseStream(frame.data(), config, config, frame.data())); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 319 | TEST(AudioProcessingImplTest, UpdateCapturePreGainRuntimeSetting) { |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 320 | rtc::scoped_refptr<AudioProcessing> apm = |
| 321 | AudioProcessingBuilderForTesting().Create(); |
Alex Loiko | b5c9a79 | 2018-04-16 16:31:22 +0200 | [diff] [blame] | 322 | webrtc::AudioProcessing::Config apm_config; |
| 323 | apm_config.pre_amplifier.enabled = true; |
| 324 | apm_config.pre_amplifier.fixed_gain_factor = 1.f; |
| 325 | apm->ApplyConfig(apm_config); |
| 326 | |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 327 | constexpr int kSampleRateHz = 48000; |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 328 | constexpr int16_t kAudioLevel = 10000; |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 329 | constexpr size_t kNumChannels = 2; |
Alex Loiko | b5c9a79 | 2018-04-16 16:31:22 +0200 | [diff] [blame] | 330 | |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 331 | std::array<int16_t, kNumChannels * kSampleRateHz / 100> frame; |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 332 | StreamConfig config(kSampleRateHz, kNumChannels); |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 333 | frame.fill(kAudioLevel); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 334 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 335 | EXPECT_EQ(frame[100], kAudioLevel) |
Alex Loiko | b5c9a79 | 2018-04-16 16:31:22 +0200 | [diff] [blame] | 336 | << "With factor 1, frame shouldn't be modified."; |
| 337 | |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 338 | constexpr float kGainFactor = 2.f; |
Alex Loiko | b5c9a79 | 2018-04-16 16:31:22 +0200 | [diff] [blame] | 339 | apm->SetRuntimeSetting( |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 340 | AudioProcessing::RuntimeSetting::CreateCapturePreGain(kGainFactor)); |
Alex Loiko | b5c9a79 | 2018-04-16 16:31:22 +0200 | [diff] [blame] | 341 | |
| 342 | // Process for two frames to have time to ramp up gain. |
| 343 | for (int i = 0; i < 2; ++i) { |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 344 | frame.fill(kAudioLevel); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 345 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
Alex Loiko | b5c9a79 | 2018-04-16 16:31:22 +0200 | [diff] [blame] | 346 | } |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 347 | EXPECT_EQ(frame[100], kGainFactor * kAudioLevel) |
Alex Loiko | b5c9a79 | 2018-04-16 16:31:22 +0200 | [diff] [blame] | 348 | << "Frame should be amplified."; |
Alessio Bazzica | c054e78 | 2018-04-16 12:10:09 +0200 | [diff] [blame] | 349 | } |
| 350 | |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 351 | TEST(AudioProcessingImplTest, |
| 352 | LevelAdjustmentUpdateCapturePreGainRuntimeSetting) { |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 353 | rtc::scoped_refptr<AudioProcessing> apm = |
| 354 | AudioProcessingBuilderForTesting().Create(); |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 355 | webrtc::AudioProcessing::Config apm_config; |
| 356 | apm_config.capture_level_adjustment.enabled = true; |
| 357 | apm_config.capture_level_adjustment.pre_gain_factor = 1.f; |
| 358 | apm->ApplyConfig(apm_config); |
| 359 | |
| 360 | constexpr int kSampleRateHz = 48000; |
| 361 | constexpr int16_t kAudioLevel = 10000; |
| 362 | constexpr size_t kNumChannels = 2; |
| 363 | |
| 364 | std::array<int16_t, kNumChannels * kSampleRateHz / 100> frame; |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 365 | StreamConfig config(kSampleRateHz, kNumChannels); |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 366 | frame.fill(kAudioLevel); |
| 367 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 368 | EXPECT_EQ(frame[100], kAudioLevel) |
| 369 | << "With factor 1, frame shouldn't be modified."; |
| 370 | |
| 371 | constexpr float kGainFactor = 2.f; |
| 372 | apm->SetRuntimeSetting( |
| 373 | AudioProcessing::RuntimeSetting::CreateCapturePreGain(kGainFactor)); |
| 374 | |
| 375 | // Process for two frames to have time to ramp up gain. |
| 376 | for (int i = 0; i < 2; ++i) { |
| 377 | frame.fill(kAudioLevel); |
| 378 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 379 | } |
| 380 | EXPECT_EQ(frame[100], kGainFactor * kAudioLevel) |
| 381 | << "Frame should be amplified."; |
| 382 | } |
| 383 | |
| 384 | TEST(AudioProcessingImplTest, |
| 385 | LevelAdjustmentUpdateCapturePostGainRuntimeSetting) { |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 386 | rtc::scoped_refptr<AudioProcessing> apm = |
| 387 | AudioProcessingBuilderForTesting().Create(); |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 388 | webrtc::AudioProcessing::Config apm_config; |
| 389 | apm_config.capture_level_adjustment.enabled = true; |
| 390 | apm_config.capture_level_adjustment.post_gain_factor = 1.f; |
| 391 | apm->ApplyConfig(apm_config); |
| 392 | |
| 393 | constexpr int kSampleRateHz = 48000; |
| 394 | constexpr int16_t kAudioLevel = 10000; |
| 395 | constexpr size_t kNumChannels = 2; |
| 396 | |
| 397 | std::array<int16_t, kNumChannels * kSampleRateHz / 100> frame; |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 398 | StreamConfig config(kSampleRateHz, kNumChannels); |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 399 | frame.fill(kAudioLevel); |
| 400 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 401 | EXPECT_EQ(frame[100], kAudioLevel) |
| 402 | << "With factor 1, frame shouldn't be modified."; |
| 403 | |
| 404 | constexpr float kGainFactor = 2.f; |
| 405 | apm->SetRuntimeSetting( |
| 406 | AudioProcessing::RuntimeSetting::CreateCapturePostGain(kGainFactor)); |
| 407 | |
| 408 | // Process for two frames to have time to ramp up gain. |
| 409 | for (int i = 0; i < 2; ++i) { |
| 410 | frame.fill(kAudioLevel); |
| 411 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 412 | } |
| 413 | EXPECT_EQ(frame[100], kGainFactor * kAudioLevel) |
| 414 | << "Frame should be amplified."; |
| 415 | } |
| 416 | |
Per Åhgren | 652ada5 | 2021-03-03 10:52:44 +0000 | [diff] [blame] | 417 | TEST(AudioProcessingImplTest, EchoControllerObservesSetCaptureUsageChange) { |
| 418 | // Tests that the echo controller observes that the capture usage has been |
| 419 | // updated. |
| 420 | auto echo_control_factory = std::make_unique<MockEchoControlFactory>(); |
| 421 | const MockEchoControlFactory* echo_control_factory_ptr = |
| 422 | echo_control_factory.get(); |
| 423 | |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 424 | rtc::scoped_refptr<AudioProcessing> apm = |
Per Åhgren | 652ada5 | 2021-03-03 10:52:44 +0000 | [diff] [blame] | 425 | AudioProcessingBuilderForTesting() |
| 426 | .SetEchoControlFactory(std::move(echo_control_factory)) |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 427 | .Create(); |
Per Åhgren | 652ada5 | 2021-03-03 10:52:44 +0000 | [diff] [blame] | 428 | |
| 429 | constexpr int16_t kAudioLevel = 10000; |
| 430 | constexpr int kSampleRateHz = 48000; |
| 431 | constexpr int kNumChannels = 2; |
| 432 | std::array<int16_t, kNumChannels * kSampleRateHz / 100> frame; |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 433 | StreamConfig config(kSampleRateHz, kNumChannels); |
Per Åhgren | 652ada5 | 2021-03-03 10:52:44 +0000 | [diff] [blame] | 434 | frame.fill(kAudioLevel); |
| 435 | |
| 436 | MockEchoControl* echo_control_mock = echo_control_factory_ptr->GetNext(); |
| 437 | |
| 438 | // Ensure that SetCaptureOutputUsage is not called when no runtime settings |
| 439 | // are passed. |
| 440 | EXPECT_CALL(*echo_control_mock, SetCaptureOutputUsage(testing::_)).Times(0); |
| 441 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 442 | |
| 443 | // Ensure that SetCaptureOutputUsage is called with the right information when |
| 444 | // a runtime setting is passed. |
| 445 | EXPECT_CALL(*echo_control_mock, |
| 446 | SetCaptureOutputUsage(/*capture_output_used=*/false)) |
| 447 | .Times(1); |
| 448 | EXPECT_TRUE(apm->PostRuntimeSetting( |
| 449 | AudioProcessing::RuntimeSetting::CreateCaptureOutputUsedSetting( |
| 450 | /*capture_output_used=*/false))); |
| 451 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 452 | |
| 453 | EXPECT_CALL(*echo_control_mock, |
| 454 | SetCaptureOutputUsage(/*capture_output_used=*/true)) |
| 455 | .Times(1); |
| 456 | EXPECT_TRUE(apm->PostRuntimeSetting( |
| 457 | AudioProcessing::RuntimeSetting::CreateCaptureOutputUsedSetting( |
| 458 | /*capture_output_used=*/true))); |
| 459 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 460 | |
| 461 | // The number of positions to place items in the queue is equal to the queue |
| 462 | // size minus 1. |
| 463 | constexpr int kNumSlotsInQueue = RuntimeSettingQueueSize(); |
| 464 | |
| 465 | // Ensure that SetCaptureOutputUsage is called with the right information when |
| 466 | // many runtime settings are passed. |
| 467 | for (int k = 0; k < kNumSlotsInQueue - 1; ++k) { |
| 468 | EXPECT_TRUE(apm->PostRuntimeSetting( |
| 469 | AudioProcessing::RuntimeSetting::CreateCaptureOutputUsedSetting( |
| 470 | /*capture_output_used=*/false))); |
| 471 | } |
| 472 | EXPECT_CALL(*echo_control_mock, |
| 473 | SetCaptureOutputUsage(/*capture_output_used=*/false)) |
| 474 | .Times(kNumSlotsInQueue - 1); |
| 475 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 476 | |
| 477 | // Ensure that SetCaptureOutputUsage is properly called with the fallback |
| 478 | // value when the runtime settings queue becomes full. |
| 479 | for (int k = 0; k < kNumSlotsInQueue; ++k) { |
| 480 | EXPECT_TRUE(apm->PostRuntimeSetting( |
| 481 | AudioProcessing::RuntimeSetting::CreateCaptureOutputUsedSetting( |
| 482 | /*capture_output_used=*/false))); |
| 483 | } |
| 484 | EXPECT_FALSE(apm->PostRuntimeSetting( |
| 485 | AudioProcessing::RuntimeSetting::CreateCaptureOutputUsedSetting( |
| 486 | /*capture_output_used=*/false))); |
| 487 | EXPECT_FALSE(apm->PostRuntimeSetting( |
| 488 | AudioProcessing::RuntimeSetting::CreateCaptureOutputUsedSetting( |
| 489 | /*capture_output_used=*/false))); |
| 490 | EXPECT_CALL(*echo_control_mock, |
| 491 | SetCaptureOutputUsage(/*capture_output_used=*/false)) |
| 492 | .Times(kNumSlotsInQueue); |
| 493 | EXPECT_CALL(*echo_control_mock, |
| 494 | SetCaptureOutputUsage(/*capture_output_used=*/true)) |
| 495 | .Times(1); |
| 496 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 497 | } |
| 498 | |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 499 | TEST(AudioProcessingImplTest, |
| 500 | EchoControllerObservesPreAmplifierEchoPathGainChange) { |
| 501 | // Tests that the echo controller observes an echo path gain change when the |
| 502 | // pre-amplifier submodule changes the gain. |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 503 | auto echo_control_factory = std::make_unique<MockEchoControlFactory>(); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 504 | const auto* echo_control_factory_ptr = echo_control_factory.get(); |
| 505 | |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 506 | rtc::scoped_refptr<AudioProcessing> apm = |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 507 | AudioProcessingBuilderForTesting() |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 508 | .SetEchoControlFactory(std::move(echo_control_factory)) |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 509 | .Create(); |
Sam Zackrisson | 41478c7 | 2019-10-15 10:10:26 +0200 | [diff] [blame] | 510 | // Disable AGC. |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 511 | webrtc::AudioProcessing::Config apm_config; |
Sam Zackrisson | 41478c7 | 2019-10-15 10:10:26 +0200 | [diff] [blame] | 512 | apm_config.gain_controller1.enabled = false; |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 513 | apm_config.gain_controller2.enabled = false; |
| 514 | apm_config.pre_amplifier.enabled = true; |
| 515 | apm_config.pre_amplifier.fixed_gain_factor = 1.f; |
| 516 | apm->ApplyConfig(apm_config); |
| 517 | |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 518 | constexpr int16_t kAudioLevel = 10000; |
| 519 | constexpr size_t kSampleRateHz = 48000; |
| 520 | constexpr size_t kNumChannels = 2; |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 521 | std::array<int16_t, kNumChannels * kSampleRateHz / 100> frame; |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 522 | StreamConfig config(kSampleRateHz, kNumChannels); |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 523 | frame.fill(kAudioLevel); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 524 | |
| 525 | MockEchoControl* echo_control_mock = echo_control_factory_ptr->GetNext(); |
| 526 | |
Per Åhgren | 0aefbf0 | 2019-08-23 21:29:17 +0200 | [diff] [blame] | 527 | EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1); |
Fredrik Hernqvist | bf47f34 | 2019-05-09 10:50:31 +0200 | [diff] [blame] | 528 | EXPECT_CALL(*echo_control_mock, |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 529 | ProcessCapture(NotNull(), testing::_, /*echo_path_change=*/false)) |
Fredrik Hernqvist | bf47f34 | 2019-05-09 10:50:31 +0200 | [diff] [blame] | 530 | .Times(1); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 531 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 532 | |
Per Åhgren | 0aefbf0 | 2019-08-23 21:29:17 +0200 | [diff] [blame] | 533 | EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1); |
Fredrik Hernqvist | bf47f34 | 2019-05-09 10:50:31 +0200 | [diff] [blame] | 534 | EXPECT_CALL(*echo_control_mock, |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 535 | ProcessCapture(NotNull(), testing::_, /*echo_path_change=*/true)) |
Fredrik Hernqvist | bf47f34 | 2019-05-09 10:50:31 +0200 | [diff] [blame] | 536 | .Times(1); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 537 | apm->SetRuntimeSetting( |
| 538 | AudioProcessing::RuntimeSetting::CreateCapturePreGain(2.f)); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 539 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | TEST(AudioProcessingImplTest, |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 543 | EchoControllerObservesLevelAdjustmentPreGainEchoPathGainChange) { |
| 544 | // Tests that the echo controller observes an echo path gain change when the |
| 545 | // pre-amplifier submodule changes the gain. |
| 546 | auto echo_control_factory = std::make_unique<MockEchoControlFactory>(); |
| 547 | const auto* echo_control_factory_ptr = echo_control_factory.get(); |
| 548 | |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 549 | rtc::scoped_refptr<AudioProcessing> apm = |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 550 | AudioProcessingBuilderForTesting() |
| 551 | .SetEchoControlFactory(std::move(echo_control_factory)) |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 552 | .Create(); |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 553 | // Disable AGC. |
| 554 | webrtc::AudioProcessing::Config apm_config; |
| 555 | apm_config.gain_controller1.enabled = false; |
| 556 | apm_config.gain_controller2.enabled = false; |
| 557 | apm_config.capture_level_adjustment.enabled = true; |
| 558 | apm_config.capture_level_adjustment.pre_gain_factor = 1.f; |
| 559 | apm->ApplyConfig(apm_config); |
| 560 | |
| 561 | constexpr int16_t kAudioLevel = 10000; |
| 562 | constexpr size_t kSampleRateHz = 48000; |
| 563 | constexpr size_t kNumChannels = 2; |
| 564 | std::array<int16_t, kNumChannels * kSampleRateHz / 100> frame; |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 565 | StreamConfig config(kSampleRateHz, kNumChannels); |
Per Åhgren | db5d728 | 2021-03-15 16:31:04 +0000 | [diff] [blame] | 566 | frame.fill(kAudioLevel); |
| 567 | |
| 568 | MockEchoControl* echo_control_mock = echo_control_factory_ptr->GetNext(); |
| 569 | |
| 570 | EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1); |
| 571 | EXPECT_CALL(*echo_control_mock, |
| 572 | ProcessCapture(NotNull(), testing::_, /*echo_path_change=*/false)) |
| 573 | .Times(1); |
| 574 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 575 | |
| 576 | EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1); |
| 577 | EXPECT_CALL(*echo_control_mock, |
| 578 | ProcessCapture(NotNull(), testing::_, /*echo_path_change=*/true)) |
| 579 | .Times(1); |
| 580 | apm->SetRuntimeSetting( |
| 581 | AudioProcessing::RuntimeSetting::CreateCapturePreGain(2.f)); |
| 582 | apm->ProcessStream(frame.data(), config, config, frame.data()); |
| 583 | } |
| 584 | |
| 585 | TEST(AudioProcessingImplTest, |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 586 | EchoControllerObservesAnalogAgc1EchoPathGainChange) { |
| 587 | // Tests that the echo controller observes an echo path gain change when the |
| 588 | // AGC1 analog adaptive submodule changes the analog gain. |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 589 | auto echo_control_factory = std::make_unique<MockEchoControlFactory>(); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 590 | const auto* echo_control_factory_ptr = echo_control_factory.get(); |
| 591 | |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 592 | rtc::scoped_refptr<AudioProcessing> apm = |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 593 | AudioProcessingBuilderForTesting() |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 594 | .SetEchoControlFactory(std::move(echo_control_factory)) |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 595 | .Create(); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 596 | webrtc::AudioProcessing::Config apm_config; |
Sam Zackrisson | 41478c7 | 2019-10-15 10:10:26 +0200 | [diff] [blame] | 597 | // Enable AGC1. |
| 598 | apm_config.gain_controller1.enabled = true; |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 599 | apm_config.gain_controller1.analog_gain_controller.enabled = true; |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 600 | apm_config.gain_controller2.enabled = false; |
| 601 | apm_config.pre_amplifier.enabled = false; |
| 602 | apm->ApplyConfig(apm_config); |
| 603 | |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 604 | constexpr int16_t kAudioLevel = 1000; |
| 605 | constexpr size_t kSampleRateHz = 48000; |
| 606 | constexpr size_t kNumChannels = 2; |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 607 | std::array<int16_t, kNumChannels * kSampleRateHz / 100> frame; |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 608 | StreamConfig stream_config(kSampleRateHz, kNumChannels); |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 609 | frame.fill(kAudioLevel); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 610 | |
| 611 | MockEchoControl* echo_control_mock = echo_control_factory_ptr->GetNext(); |
| 612 | |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 613 | constexpr int kInitialStreamAnalogLevel = 123; |
| 614 | apm->set_stream_analog_level(kInitialStreamAnalogLevel); |
| 615 | |
| 616 | // When the first fame is processed, no echo path gain change must be |
| 617 | // detected. |
Per Åhgren | 0aefbf0 | 2019-08-23 21:29:17 +0200 | [diff] [blame] | 618 | EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1); |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 619 | EXPECT_CALL(*echo_control_mock, |
| 620 | ProcessCapture(NotNull(), testing::_, /*echo_path_change=*/false)) |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 621 | .Times(1); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 622 | apm->ProcessStream(frame.data(), stream_config, stream_config, frame.data()); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 623 | |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 624 | // Simulate the application of the recommended analog level. |
| 625 | int recommended_analog_level = apm->recommended_stream_analog_level(); |
| 626 | if (recommended_analog_level == kInitialStreamAnalogLevel) { |
| 627 | // Force an analog gain change if it did not happen. |
| 628 | recommended_analog_level++; |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 629 | } |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 630 | apm->set_stream_analog_level(recommended_analog_level); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 631 | |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 632 | // After the first fame and with a stream analog level change, the echo path |
| 633 | // gain change must be detected. |
Per Åhgren | 0aefbf0 | 2019-08-23 21:29:17 +0200 | [diff] [blame] | 634 | EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1); |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 635 | EXPECT_CALL(*echo_control_mock, |
| 636 | ProcessCapture(NotNull(), testing::_, /*echo_path_change=*/true)) |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 637 | .Times(1); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 638 | apm->ProcessStream(frame.data(), stream_config, stream_config, frame.data()); |
Alessio Bazzica | e449805 | 2018-12-17 09:44:06 +0100 | [diff] [blame] | 639 | } |
| 640 | |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 641 | // Tests that a stream is successfully processed when AGC2 adaptive digital is |
| 642 | // used and when the field trial |
| 643 | // `WebRTC-Audio-TransientSuppressorVadMode/Enabled-Default/` is set. |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 644 | TEST(AudioProcessingImplTest, |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 645 | ProcessWithAgc2AndTransientSuppressorVadModeDefault) { |
| 646 | webrtc::test::ScopedFieldTrials field_trials( |
| 647 | "WebRTC-Audio-TransientSuppressorVadMode/Enabled-Default/"); |
| 648 | rtc::scoped_refptr<AudioProcessing> apm = AudioProcessingBuilder().Create(); |
| 649 | ASSERT_EQ(apm->Initialize(), AudioProcessing::kNoError); |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 650 | webrtc::AudioProcessing::Config apm_config; |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 651 | apm_config.gain_controller1.enabled = false; |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 652 | apm_config.gain_controller2.enabled = true; |
| 653 | apm_config.gain_controller2.adaptive_digital.enabled = true; |
Alessio Bazzica | 17e14fd | 2022-12-07 17:08:45 +0100 | [diff] [blame^] | 654 | apm_config.transient_suppression.enabled = true; |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 655 | apm->ApplyConfig(apm_config); |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 656 | constexpr int kSampleRateHz = 48000; |
| 657 | constexpr int kNumChannels = 1; |
| 658 | std::array<float, kSampleRateHz / 100> buffer; |
| 659 | float* channel_pointers[] = {buffer.data()}; |
| 660 | StreamConfig stream_config(/*sample_rate_hz=*/kSampleRateHz, |
| 661 | /*num_channels=*/kNumChannels); |
| 662 | Random random_generator(2341U); |
| 663 | constexpr int kFramesToProcess = 10; |
| 664 | for (int i = 0; i < kFramesToProcess; ++i) { |
| 665 | RandomizeSampleVector(&random_generator, buffer); |
| 666 | ASSERT_EQ(apm->ProcessStream(channel_pointers, stream_config, stream_config, |
| 667 | channel_pointers), |
| 668 | kNoErr); |
| 669 | } |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 670 | } |
| 671 | |
Alessio Bazzica | a5aaedb | 2022-09-06 16:39:07 +0200 | [diff] [blame] | 672 | // Tests that a stream is successfully processed when AGC2 adaptive digital is |
| 673 | // used and when the field trial |
| 674 | // `WebRTC-Audio-TransientSuppressorVadMode/Enabled-RnnVad/` is set. |
| 675 | TEST(AudioProcessingImplTest, |
| 676 | ProcessWithAgc2AndTransientSuppressorVadModeRnnVad) { |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 677 | webrtc::test::ScopedFieldTrials field_trials( |
| 678 | "WebRTC-Audio-TransientSuppressorVadMode/Enabled-RnnVad/"); |
| 679 | rtc::scoped_refptr<AudioProcessing> apm = AudioProcessingBuilder().Create(); |
| 680 | ASSERT_EQ(apm->Initialize(), AudioProcessing::kNoError); |
| 681 | webrtc::AudioProcessing::Config apm_config; |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 682 | apm_config.gain_controller1.enabled = false; |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 683 | apm_config.gain_controller2.enabled = true; |
| 684 | apm_config.gain_controller2.adaptive_digital.enabled = true; |
Alessio Bazzica | 17e14fd | 2022-12-07 17:08:45 +0100 | [diff] [blame^] | 685 | apm_config.transient_suppression.enabled = true; |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 686 | apm->ApplyConfig(apm_config); |
| 687 | constexpr int kSampleRateHz = 48000; |
| 688 | constexpr int kNumChannels = 1; |
| 689 | std::array<float, kSampleRateHz / 100> buffer; |
| 690 | float* channel_pointers[] = {buffer.data()}; |
| 691 | StreamConfig stream_config(/*sample_rate_hz=*/kSampleRateHz, |
| 692 | /*num_channels=*/kNumChannels); |
| 693 | Random random_generator(2341U); |
| 694 | constexpr int kFramesToProcess = 10; |
| 695 | for (int i = 0; i < kFramesToProcess; ++i) { |
| 696 | RandomizeSampleVector(&random_generator, buffer); |
| 697 | ASSERT_EQ(apm->ProcessStream(channel_pointers, stream_config, stream_config, |
| 698 | channel_pointers), |
| 699 | kNoErr); |
| 700 | } |
| 701 | } |
| 702 | |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 703 | TEST(AudioProcessingImplTest, EchoControllerObservesPlayoutVolumeChange) { |
| 704 | // Tests that the echo controller observes an echo path gain change when a |
| 705 | // playout volume change is reported. |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 706 | auto echo_control_factory = std::make_unique<MockEchoControlFactory>(); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 707 | const auto* echo_control_factory_ptr = echo_control_factory.get(); |
| 708 | |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 709 | rtc::scoped_refptr<AudioProcessing> apm = |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 710 | AudioProcessingBuilderForTesting() |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 711 | .SetEchoControlFactory(std::move(echo_control_factory)) |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 712 | .Create(); |
Sam Zackrisson | 41478c7 | 2019-10-15 10:10:26 +0200 | [diff] [blame] | 713 | // Disable AGC. |
| 714 | webrtc::AudioProcessing::Config apm_config; |
| 715 | apm_config.gain_controller1.enabled = false; |
| 716 | apm_config.gain_controller2.enabled = false; |
| 717 | apm->ApplyConfig(apm_config); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 718 | |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 719 | constexpr int16_t kAudioLevel = 10000; |
| 720 | constexpr size_t kSampleRateHz = 48000; |
| 721 | constexpr size_t kNumChannels = 2; |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 722 | std::array<int16_t, kNumChannels * kSampleRateHz / 100> frame; |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 723 | StreamConfig stream_config(kSampleRateHz, kNumChannels); |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 724 | frame.fill(kAudioLevel); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 725 | |
| 726 | MockEchoControl* echo_control_mock = echo_control_factory_ptr->GetNext(); |
| 727 | |
Per Åhgren | 0aefbf0 | 2019-08-23 21:29:17 +0200 | [diff] [blame] | 728 | EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 729 | EXPECT_CALL(*echo_control_mock, |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 730 | ProcessCapture(NotNull(), testing::_, /*echo_path_change=*/false)) |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 731 | .Times(1); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 732 | apm->ProcessStream(frame.data(), stream_config, stream_config, frame.data()); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 733 | |
Per Åhgren | 0aefbf0 | 2019-08-23 21:29:17 +0200 | [diff] [blame] | 734 | EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 735 | EXPECT_CALL(*echo_control_mock, |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 736 | ProcessCapture(NotNull(), testing::_, /*echo_path_change=*/false)) |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 737 | .Times(1); |
| 738 | apm->SetRuntimeSetting( |
| 739 | AudioProcessing::RuntimeSetting::CreatePlayoutVolumeChange(50)); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 740 | apm->ProcessStream(frame.data(), stream_config, stream_config, frame.data()); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 741 | |
Per Åhgren | 0aefbf0 | 2019-08-23 21:29:17 +0200 | [diff] [blame] | 742 | EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 743 | EXPECT_CALL(*echo_control_mock, |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 744 | ProcessCapture(NotNull(), testing::_, /*echo_path_change=*/false)) |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 745 | .Times(1); |
| 746 | apm->SetRuntimeSetting( |
| 747 | AudioProcessing::RuntimeSetting::CreatePlayoutVolumeChange(50)); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 748 | apm->ProcessStream(frame.data(), stream_config, stream_config, frame.data()); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 749 | |
Per Åhgren | 0aefbf0 | 2019-08-23 21:29:17 +0200 | [diff] [blame] | 750 | EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 751 | EXPECT_CALL(*echo_control_mock, |
Per Åhgren | c20a19c | 2019-11-13 11:12:29 +0100 | [diff] [blame] | 752 | ProcessCapture(NotNull(), testing::_, /*echo_path_change=*/true)) |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 753 | .Times(1); |
| 754 | apm->SetRuntimeSetting( |
| 755 | AudioProcessing::RuntimeSetting::CreatePlayoutVolumeChange(100)); |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 756 | apm->ProcessStream(frame.data(), stream_config, stream_config, frame.data()); |
Fredrik Hernqvist | ca36285 | 2019-05-10 15:50:02 +0200 | [diff] [blame] | 757 | } |
| 758 | |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 759 | TEST(AudioProcessingImplTest, RenderPreProcessorBeforeEchoDetector) { |
| 760 | // Make sure that signal changes caused by a render pre-processing sub-module |
| 761 | // take place before any echo detector analysis. |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 762 | auto test_echo_detector = rtc::make_ref_counted<TestEchoDetector>(); |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 763 | std::unique_ptr<CustomProcessing> test_render_pre_processor( |
| 764 | new TestRenderPreProcessor()); |
| 765 | // Create APM injecting the test echo detector and render pre-processor. |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 766 | rtc::scoped_refptr<AudioProcessing> apm = |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 767 | AudioProcessingBuilderForTesting() |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 768 | .SetEchoDetector(test_echo_detector) |
| 769 | .SetRenderPreProcessing(std::move(test_render_pre_processor)) |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 770 | .Create(); |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 771 | webrtc::AudioProcessing::Config apm_config; |
| 772 | apm_config.pre_amplifier.enabled = true; |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 773 | apm->ApplyConfig(apm_config); |
| 774 | |
| 775 | constexpr int16_t kAudioLevel = 1000; |
| 776 | constexpr int kSampleRateHz = 16000; |
| 777 | constexpr size_t kNumChannels = 1; |
Sam Zackrisson | 12e319a | 2020-01-03 14:54:20 +0100 | [diff] [blame] | 778 | // Explicitly initialize APM to ensure no render frames are discarded. |
| 779 | const ProcessingConfig processing_config = {{ |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 780 | {kSampleRateHz, kNumChannels}, |
| 781 | {kSampleRateHz, kNumChannels}, |
| 782 | {kSampleRateHz, kNumChannels}, |
| 783 | {kSampleRateHz, kNumChannels}, |
Sam Zackrisson | 12e319a | 2020-01-03 14:54:20 +0100 | [diff] [blame] | 784 | }}; |
| 785 | apm->Initialize(processing_config); |
| 786 | |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 787 | std::array<int16_t, kNumChannels * kSampleRateHz / 100> frame; |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 788 | StreamConfig stream_config(kSampleRateHz, kNumChannels); |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 789 | |
| 790 | constexpr float kAudioLevelFloat = static_cast<float>(kAudioLevel); |
| 791 | constexpr float kExpectedPreprocessedAudioLevel = |
| 792 | TestRenderPreProcessor::ProcessSample(kAudioLevelFloat); |
| 793 | ASSERT_NE(kAudioLevelFloat, kExpectedPreprocessedAudioLevel); |
| 794 | |
| 795 | // Analyze a render stream frame. |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 796 | frame.fill(kAudioLevel); |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 797 | ASSERT_EQ(AudioProcessing::Error::kNoError, |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 798 | apm->ProcessReverseStream(frame.data(), stream_config, |
| 799 | stream_config, frame.data())); |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 800 | // Trigger a call to in EchoDetector::AnalyzeRenderAudio() via |
| 801 | // ProcessStream(). |
Per Åhgren | 2507f8c | 2020-03-19 12:33:29 +0100 | [diff] [blame] | 802 | frame.fill(kAudioLevel); |
| 803 | ASSERT_EQ(AudioProcessing::Error::kNoError, |
| 804 | apm->ProcessStream(frame.data(), stream_config, stream_config, |
Per Åhgren | dc5522b | 2020-03-19 14:55:58 +0100 | [diff] [blame] | 805 | frame.data())); |
Alessio Bazzica | d2b9740 | 2018-08-09 14:23:11 +0200 | [diff] [blame] | 806 | // Regardless of how the call to in EchoDetector::AnalyzeRenderAudio() is |
| 807 | // triggered, the line below checks that the call has occurred. If not, the |
| 808 | // APM implementation may have changed and this test might need to be adapted. |
| 809 | ASSERT_TRUE(test_echo_detector->analyze_render_audio_called()); |
| 810 | // Check that the data read in EchoDetector::AnalyzeRenderAudio() is that |
| 811 | // produced by the render pre-processor. |
| 812 | EXPECT_EQ(kExpectedPreprocessedAudioLevel, |
| 813 | test_echo_detector->last_render_audio_first_sample()); |
| 814 | } |
| 815 | |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 816 | // Disabling build-optional submodules and trying to enable them via the APM |
| 817 | // config should be bit-exact with running APM with said submodules disabled. |
| 818 | // This mainly tests that SetCreateOptionalSubmodulesForTesting has an effect. |
| 819 | TEST(ApmWithSubmodulesExcludedTest, BitexactWithDisabledModules) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame] | 820 | auto apm = rtc::make_ref_counted<AudioProcessingImpl>(); |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 821 | ASSERT_EQ(apm->Initialize(), AudioProcessing::kNoError); |
| 822 | |
| 823 | ApmSubmoduleCreationOverrides overrides; |
| 824 | overrides.transient_suppression = true; |
| 825 | apm->OverrideSubmoduleCreationForTesting(overrides); |
| 826 | |
| 827 | AudioProcessing::Config apm_config = apm->GetConfig(); |
| 828 | apm_config.transient_suppression.enabled = true; |
| 829 | apm->ApplyConfig(apm_config); |
| 830 | |
| 831 | rtc::scoped_refptr<AudioProcessing> apm_reference = |
| 832 | AudioProcessingBuilder().Create(); |
| 833 | apm_config = apm_reference->GetConfig(); |
| 834 | apm_config.transient_suppression.enabled = false; |
| 835 | apm_reference->ApplyConfig(apm_config); |
| 836 | |
| 837 | constexpr int kSampleRateHz = 16000; |
| 838 | constexpr int kNumChannels = 1; |
| 839 | std::array<float, kSampleRateHz / 100> buffer; |
| 840 | std::array<float, kSampleRateHz / 100> buffer_reference; |
| 841 | float* channel_pointers[] = {buffer.data()}; |
| 842 | float* channel_pointers_reference[] = {buffer_reference.data()}; |
| 843 | StreamConfig stream_config(/*sample_rate_hz=*/kSampleRateHz, |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 844 | /*num_channels=*/kNumChannels); |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 845 | Random random_generator(2341U); |
| 846 | constexpr int kFramesToProcessPerConfiguration = 10; |
| 847 | |
| 848 | for (int i = 0; i < kFramesToProcessPerConfiguration; ++i) { |
| 849 | RandomizeSampleVector(&random_generator, buffer); |
| 850 | std::copy(buffer.begin(), buffer.end(), buffer_reference.begin()); |
| 851 | ASSERT_EQ(apm->ProcessStream(channel_pointers, stream_config, stream_config, |
| 852 | channel_pointers), |
| 853 | kNoErr); |
| 854 | ASSERT_EQ( |
| 855 | apm_reference->ProcessStream(channel_pointers_reference, stream_config, |
| 856 | stream_config, channel_pointers_reference), |
| 857 | kNoErr); |
| 858 | for (int j = 0; j < kSampleRateHz / 100; ++j) { |
| 859 | EXPECT_EQ(buffer[j], buffer_reference[j]); |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | // Disable transient suppressor creation and run APM in ways that should trigger |
| 865 | // calls to the transient suppressor API. |
| 866 | TEST(ApmWithSubmodulesExcludedTest, ReinitializeTransientSuppressor) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame] | 867 | auto apm = rtc::make_ref_counted<AudioProcessingImpl>(); |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 868 | ASSERT_EQ(apm->Initialize(), kNoErr); |
| 869 | |
| 870 | ApmSubmoduleCreationOverrides overrides; |
| 871 | overrides.transient_suppression = true; |
| 872 | apm->OverrideSubmoduleCreationForTesting(overrides); |
| 873 | |
| 874 | AudioProcessing::Config config = apm->GetConfig(); |
| 875 | config.transient_suppression.enabled = true; |
| 876 | apm->ApplyConfig(config); |
| 877 | // 960 samples per frame: 10 ms of <= 48 kHz audio with <= 2 channels. |
| 878 | float buffer[960]; |
| 879 | float* channel_pointers[] = {&buffer[0], &buffer[480]}; |
| 880 | Random random_generator(2341U); |
| 881 | constexpr int kFramesToProcessPerConfiguration = 3; |
| 882 | |
| 883 | StreamConfig initial_stream_config(/*sample_rate_hz=*/16000, |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 884 | /*num_channels=*/1); |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 885 | for (int i = 0; i < kFramesToProcessPerConfiguration; ++i) { |
| 886 | RandomizeSampleVector(&random_generator, buffer); |
| 887 | EXPECT_EQ(apm->ProcessStream(channel_pointers, initial_stream_config, |
| 888 | initial_stream_config, channel_pointers), |
| 889 | kNoErr); |
| 890 | } |
| 891 | |
| 892 | StreamConfig stereo_stream_config(/*sample_rate_hz=*/16000, |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 893 | /*num_channels=*/2); |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 894 | for (int i = 0; i < kFramesToProcessPerConfiguration; ++i) { |
| 895 | RandomizeSampleVector(&random_generator, buffer); |
| 896 | EXPECT_EQ(apm->ProcessStream(channel_pointers, stereo_stream_config, |
| 897 | stereo_stream_config, channel_pointers), |
| 898 | kNoErr); |
| 899 | } |
| 900 | |
| 901 | StreamConfig high_sample_rate_stream_config(/*sample_rate_hz=*/48000, |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 902 | /*num_channels=*/2); |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 903 | for (int i = 0; i < kFramesToProcessPerConfiguration; ++i) { |
| 904 | RandomizeSampleVector(&random_generator, buffer); |
| 905 | EXPECT_EQ( |
| 906 | apm->ProcessStream(channel_pointers, high_sample_rate_stream_config, |
| 907 | high_sample_rate_stream_config, channel_pointers), |
| 908 | kNoErr); |
| 909 | } |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | // Disable transient suppressor creation and run APM in ways that should trigger |
| 913 | // calls to the transient suppressor API. |
| 914 | TEST(ApmWithSubmodulesExcludedTest, ToggleTransientSuppressor) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame] | 915 | auto apm = rtc::make_ref_counted<AudioProcessingImpl>(); |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 916 | ASSERT_EQ(apm->Initialize(), AudioProcessing::kNoError); |
| 917 | |
| 918 | ApmSubmoduleCreationOverrides overrides; |
| 919 | overrides.transient_suppression = true; |
| 920 | apm->OverrideSubmoduleCreationForTesting(overrides); |
| 921 | |
| 922 | // 960 samples per frame: 10 ms of <= 48 kHz audio with <= 2 channels. |
| 923 | float buffer[960]; |
| 924 | float* channel_pointers[] = {&buffer[0], &buffer[480]}; |
| 925 | Random random_generator(2341U); |
| 926 | constexpr int kFramesToProcessPerConfiguration = 3; |
| 927 | StreamConfig stream_config(/*sample_rate_hz=*/16000, |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 928 | /*num_channels=*/1); |
Sam Zackrisson | b37e59d | 2020-04-27 08:39:33 +0200 | [diff] [blame] | 929 | |
| 930 | AudioProcessing::Config config = apm->GetConfig(); |
| 931 | config.transient_suppression.enabled = true; |
| 932 | apm->ApplyConfig(config); |
| 933 | for (int i = 0; i < kFramesToProcessPerConfiguration; ++i) { |
| 934 | RandomizeSampleVector(&random_generator, buffer); |
| 935 | EXPECT_EQ(apm->ProcessStream(channel_pointers, stream_config, stream_config, |
| 936 | channel_pointers), |
| 937 | kNoErr); |
| 938 | } |
| 939 | |
| 940 | config = apm->GetConfig(); |
| 941 | config.transient_suppression.enabled = false; |
| 942 | apm->ApplyConfig(config); |
| 943 | for (int i = 0; i < kFramesToProcessPerConfiguration; ++i) { |
| 944 | RandomizeSampleVector(&random_generator, buffer); |
| 945 | EXPECT_EQ(apm->ProcessStream(channel_pointers, stream_config, stream_config, |
| 946 | channel_pointers), |
| 947 | kNoErr); |
| 948 | } |
| 949 | |
| 950 | config = apm->GetConfig(); |
| 951 | config.transient_suppression.enabled = true; |
| 952 | apm->ApplyConfig(config); |
| 953 | for (int i = 0; i < kFramesToProcessPerConfiguration; ++i) { |
| 954 | RandomizeSampleVector(&random_generator, buffer); |
| 955 | EXPECT_EQ(apm->ProcessStream(channel_pointers, stream_config, stream_config, |
| 956 | channel_pointers), |
| 957 | kNoErr); |
| 958 | } |
| 959 | } |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 960 | |
Alessio Bazzica | 352f38c | 2022-12-07 16:13:35 +0100 | [diff] [blame] | 961 | TEST(AudioProcessingImplTest, CanDisableTransientSuppressor) { |
| 962 | // Do not explicitly disable "WebRTC-ApmTransientSuppressorKillSwitch" since |
| 963 | // to check that, by default, it is disabled. |
| 964 | auto apm = AudioProcessingBuilder() |
| 965 | .SetConfig({.transient_suppression = {.enabled = false}}) |
| 966 | .Create(); |
| 967 | EXPECT_FALSE(apm->GetConfig().transient_suppression.enabled); |
| 968 | } |
| 969 | |
| 970 | TEST(AudioProcessingImplTest, CanEnableTransientSuppressor) { |
| 971 | // Do not explicitly disable "WebRTC-ApmTransientSuppressorKillSwitch" since |
| 972 | // to check that, by default, it is disabled. |
| 973 | auto apm = AudioProcessingBuilder() |
| 974 | .SetConfig({.transient_suppression = {.enabled = true}}) |
| 975 | .Create(); |
| 976 | EXPECT_TRUE(apm->GetConfig().transient_suppression.enabled); |
| 977 | } |
| 978 | |
| 979 | TEST(AudioProcessingImplTest, CanDisableTransientSuppressorIfUsageAllowed) { |
| 980 | // Disable the field trial that disallows to enable transient suppression. |
| 981 | test::ScopedFieldTrials field_trials( |
| 982 | "WebRTC-ApmTransientSuppressorKillSwitch/Disabled/"); |
| 983 | auto apm = AudioProcessingBuilder() |
| 984 | .SetConfig({.transient_suppression = {.enabled = false}}) |
| 985 | .Create(); |
| 986 | EXPECT_FALSE(apm->GetConfig().transient_suppression.enabled); |
| 987 | } |
| 988 | |
| 989 | TEST(AudioProcessingImplTest, CanEnableTransientSuppressorIfUsageAllowed) { |
| 990 | // Disable the field trial that disallows to enable transient suppression. |
| 991 | test::ScopedFieldTrials field_trials( |
| 992 | "WebRTC-ApmTransientSuppressorKillSwitch/Disabled/"); |
| 993 | auto apm = AudioProcessingBuilder() |
| 994 | .SetConfig({.transient_suppression = {.enabled = true}}) |
| 995 | .Create(); |
| 996 | EXPECT_TRUE(apm->GetConfig().transient_suppression.enabled); |
| 997 | } |
| 998 | |
| 999 | TEST(AudioProcessingImplTest, |
| 1000 | CannotEnableTransientSuppressorIfUsageDisallowed) { |
| 1001 | // Enable the field trial that disallows to enable transient suppression. |
| 1002 | test::ScopedFieldTrials field_trials( |
| 1003 | "WebRTC-ApmTransientSuppressorKillSwitch/Enabled/"); |
| 1004 | auto apm = AudioProcessingBuilder() |
| 1005 | .SetConfig({.transient_suppression = {.enabled = true}}) |
| 1006 | .Create(); |
| 1007 | EXPECT_FALSE(apm->GetConfig().transient_suppression.enabled); |
| 1008 | } |
| 1009 | |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1010 | // Tests that the minimum startup volume is applied at the startup. |
| 1011 | TEST_P(InputVolumeStartupParameterizedTest, |
| 1012 | VerifyStartupMinVolumeAppliedAtStartup) { |
| 1013 | const int applied_startup_input_volume = GetStartupVolume(); |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1014 | const int expected_volume = |
Alessio Bazzica | 9ea5381 | 2022-10-13 17:09:15 +0200 | [diff] [blame] | 1015 | std::max(applied_startup_input_volume, GetMinVolume()); |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1016 | const bool agc1_analog_controller_enabled = GetAgc1AnalogControllerEnabled(); |
| 1017 | const bool agc2_input_volume_controller_enabled = |
| 1018 | GetAgc2InputVolumeControllerEnabled(); |
| 1019 | auto apm = CreateApmForInputVolumeTest(agc1_analog_controller_enabled, |
| 1020 | agc2_input_volume_controller_enabled); |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1021 | |
| 1022 | const int recommended_input_volume = |
| 1023 | ProcessInputVolume(*apm, /*num_frames=*/1, applied_startup_input_volume); |
| 1024 | |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1025 | if (!agc1_analog_controller_enabled && |
| 1026 | !agc2_input_volume_controller_enabled) { |
| 1027 | // No input volume changes if none of the analog controllers is enabled. |
| 1028 | ASSERT_EQ(recommended_input_volume, applied_startup_input_volume); |
| 1029 | } else { |
| 1030 | ASSERT_EQ(recommended_input_volume, expected_volume); |
| 1031 | } |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | // Tests that the minimum input volume is applied if the volume is manually |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1035 | // adjusted to a non-zero value 1) always for AGC2 input volume controller and |
| 1036 | // 2) only if "WebRTC-Audio-2ndAgcMinMicLevelExperiment" is enabled for AGC1 |
| 1037 | // analog controller. |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1038 | TEST_P(InputVolumeNotZeroParameterizedTest, |
| 1039 | VerifyMinVolumeMaybeAppliedAfterManualVolumeAdjustments) { |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1040 | const int applied_startup_input_volume = GetStartupVolume(); |
| 1041 | const int applied_input_volume = GetVolume(); |
| 1042 | const int expected_volume = std::max(applied_input_volume, GetMinVolume()); |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1043 | const bool agc1_analog_controller_enabled = GetAgc1AnalogControllerEnabled(); |
| 1044 | const bool agc2_input_volume_controller_enabled = |
| 1045 | GetAgc2InputVolumeControllerEnabled(); |
| 1046 | auto apm = CreateApmForInputVolumeTest(agc1_analog_controller_enabled, |
| 1047 | agc2_input_volume_controller_enabled); |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1048 | |
| 1049 | ProcessInputVolume(*apm, /*num_frames=*/1, applied_startup_input_volume); |
| 1050 | const int recommended_input_volume = |
| 1051 | ProcessInputVolume(*apm, /*num_frames=*/1, applied_input_volume); |
| 1052 | |
| 1053 | ASSERT_NE(applied_input_volume, 0); |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1054 | |
| 1055 | if (!agc1_analog_controller_enabled && |
| 1056 | !agc2_input_volume_controller_enabled) { |
| 1057 | // No input volume changes if none of the analog controllers is enabled. |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1058 | ASSERT_EQ(recommended_input_volume, applied_input_volume); |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1059 | } else { |
| 1060 | if (GetMinMicLevelExperimentEnabled() || |
| 1061 | (!agc1_analog_controller_enabled && |
| 1062 | agc2_input_volume_controller_enabled)) { |
| 1063 | ASSERT_EQ(recommended_input_volume, expected_volume); |
| 1064 | } else { |
| 1065 | ASSERT_EQ(recommended_input_volume, applied_input_volume); |
| 1066 | } |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | // Tests that the minimum input volume is not applied if the volume is manually |
| 1071 | // adjusted to zero. |
| 1072 | TEST_P(InputVolumeZeroParameterizedTest, |
| 1073 | VerifyMinVolumeNotAppliedAfterManualVolumeAdjustments) { |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1074 | constexpr int kZeroVolume = 0; |
| 1075 | const int applied_startup_input_volume = GetStartupVolume(); |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1076 | const bool agc1_analog_controller_enabled = GetAgc1AnalogControllerEnabled(); |
| 1077 | const bool agc2_input_volume_controller_enabled = |
| 1078 | GetAgc2InputVolumeControllerEnabled(); |
| 1079 | auto apm = CreateApmForInputVolumeTest(agc1_analog_controller_enabled, |
| 1080 | agc2_input_volume_controller_enabled); |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1081 | |
| 1082 | const int recommended_input_volume_after_startup = |
| 1083 | ProcessInputVolume(*apm, /*num_frames=*/1, applied_startup_input_volume); |
| 1084 | const int recommended_input_volume = |
| 1085 | ProcessInputVolume(*apm, /*num_frames=*/1, kZeroVolume); |
| 1086 | |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1087 | if (!agc1_analog_controller_enabled && |
| 1088 | !agc2_input_volume_controller_enabled) { |
| 1089 | // No input volume changes if none of the analog controllers is enabled. |
| 1090 | ASSERT_EQ(recommended_input_volume, kZeroVolume); |
| 1091 | } else { |
| 1092 | ASSERT_NE(recommended_input_volume, recommended_input_volume_after_startup); |
| 1093 | ASSERT_EQ(recommended_input_volume, kZeroVolume); |
| 1094 | } |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | // Tests that the minimum input volume is applied if the volume is not zero |
| 1098 | // before it is automatically adjusted. |
| 1099 | TEST_P(InputVolumeNotZeroParameterizedTest, |
| 1100 | VerifyMinVolumeAppliedAfterAutomaticVolumeAdjustments) { |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1101 | const int applied_startup_input_volume = GetStartupVolume(); |
| 1102 | const int applied_input_volume = GetVolume(); |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1103 | const bool agc1_analog_controller_enabled = GetAgc1AnalogControllerEnabled(); |
| 1104 | const bool agc2_input_volume_controller_enabled = |
| 1105 | GetAgc2InputVolumeControllerEnabled(); |
| 1106 | auto apm = CreateApmForInputVolumeTest(agc1_analog_controller_enabled, |
| 1107 | agc2_input_volume_controller_enabled); |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1108 | |
| 1109 | ProcessInputVolume(*apm, /*num_frames=*/1, applied_startup_input_volume); |
| 1110 | const int recommended_input_volume = |
| 1111 | ProcessInputVolume(*apm, /*num_frames=*/400, applied_input_volume); |
| 1112 | |
| 1113 | ASSERT_NE(applied_input_volume, 0); |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1114 | |
| 1115 | if (!agc1_analog_controller_enabled && |
| 1116 | !agc2_input_volume_controller_enabled) { |
| 1117 | // No input volume changes if none of the analog controllers is enabled. |
| 1118 | ASSERT_EQ(recommended_input_volume, applied_input_volume); |
| 1119 | } else { |
| 1120 | if (recommended_input_volume != applied_input_volume) { |
| 1121 | ASSERT_GE(recommended_input_volume, GetMinVolume()); |
| 1122 | } |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | // Tests that the minimum input volume is not applied if the volume is zero |
| 1127 | // before it is automatically adjusted. |
| 1128 | TEST_P(InputVolumeZeroParameterizedTest, |
| 1129 | VerifyMinVolumeNotAppliedAfterAutomaticVolumeAdjustments) { |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1130 | constexpr int kZeroVolume = 0; |
| 1131 | const int applied_startup_input_volume = GetStartupVolume(); |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1132 | const bool agc1_analog_controller_enabled = GetAgc1AnalogControllerEnabled(); |
| 1133 | const bool agc2_input_volume_controller_enabled = |
| 1134 | GetAgc2InputVolumeControllerEnabled(); |
| 1135 | auto apm = CreateApmForInputVolumeTest(agc1_analog_controller_enabled, |
| 1136 | agc2_input_volume_controller_enabled); |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1137 | |
| 1138 | const int recommended_input_volume_after_startup = |
| 1139 | ProcessInputVolume(*apm, /*num_frames=*/1, applied_startup_input_volume); |
| 1140 | const int recommended_input_volume = |
| 1141 | ProcessInputVolume(*apm, /*num_frames=*/400, kZeroVolume); |
| 1142 | |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1143 | if (!agc1_analog_controller_enabled && |
| 1144 | !agc2_input_volume_controller_enabled) { |
| 1145 | // No input volume changes if none of the analog controllers is enabled. |
| 1146 | ASSERT_EQ(recommended_input_volume, kZeroVolume); |
| 1147 | } else { |
| 1148 | ASSERT_NE(recommended_input_volume, recommended_input_volume_after_startup); |
| 1149 | ASSERT_EQ(recommended_input_volume, kZeroVolume); |
| 1150 | } |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | INSTANTIATE_TEST_SUITE_P(AudioProcessingImplTest, |
| 1154 | InputVolumeStartupParameterizedTest, |
Alessio Bazzica | 9ea5381 | 2022-10-13 17:09:15 +0200 | [diff] [blame] | 1155 | ::testing::Combine(::testing::Values(0, 5, 30), |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1156 | ::testing::Values(absl::nullopt, |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1157 | 20), |
| 1158 | ::testing::Bool(), |
| 1159 | ::testing::Bool())); |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1160 | |
| 1161 | INSTANTIATE_TEST_SUITE_P(AudioProcessingImplTest, |
| 1162 | InputVolumeNotZeroParameterizedTest, |
| 1163 | ::testing::Combine(::testing::Values(0, 5, 15), |
| 1164 | ::testing::Values(1, 5, 30), |
| 1165 | ::testing::Values(absl::nullopt, |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1166 | 20), |
| 1167 | ::testing::Bool(), |
| 1168 | ::testing::Bool())); |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1169 | |
| 1170 | INSTANTIATE_TEST_SUITE_P(AudioProcessingImplTest, |
| 1171 | InputVolumeZeroParameterizedTest, |
| 1172 | ::testing::Combine(::testing::Values(0, 5, 15), |
| 1173 | ::testing::Values(absl::nullopt, |
Hanna Silen | d4dbe45 | 2022-11-30 15:16:21 +0100 | [diff] [blame] | 1174 | 20), |
| 1175 | ::testing::Bool(), |
| 1176 | ::testing::Bool())); |
Hanna Silen | c69188d | 2022-09-16 11:38:56 +0200 | [diff] [blame] | 1177 | |
Alessio Bazzica | 79beaa7 | 2022-10-31 16:42:34 +0100 | [diff] [blame] | 1178 | // When the input volume is not emulated and no input volume controller is |
| 1179 | // active, the recommended volume must always be the applied volume. |
| 1180 | TEST(AudioProcessingImplTest, |
| 1181 | RecommendAppliedInputVolumeWithNoAgcWithNoEmulation) { |
| 1182 | auto apm = AudioProcessingBuilder() |
| 1183 | .SetConfig({.capture_level_adjustment = {.enabled = false}, |
| 1184 | .gain_controller1 = {.enabled = false}}) |
| 1185 | .Create(); |
| 1186 | |
| 1187 | constexpr int kOneFrame = 1; |
| 1188 | EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/123), 123); |
| 1189 | EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/59), 59); |
| 1190 | EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/135), 135); |
| 1191 | } |
| 1192 | |
| 1193 | // When the input volume is emulated, the recommended volume must always be the |
| 1194 | // applied volume and at any time it must not be that set in the input volume |
| 1195 | // emulator. |
| 1196 | // TODO(bugs.webrtc.org/14581): Enable when APM fixed to let this test pass. |
| 1197 | TEST(AudioProcessingImplTest, |
| 1198 | DISABLED_RecommendAppliedInputVolumeWithNoAgcWithEmulation) { |
| 1199 | auto apm = |
| 1200 | AudioProcessingBuilder() |
| 1201 | .SetConfig({.capture_level_adjustment = {.enabled = true, |
| 1202 | .analog_mic_gain_emulation{ |
| 1203 | .enabled = true, |
| 1204 | .initial_level = 255}}, |
| 1205 | .gain_controller1 = {.enabled = false}}) |
| 1206 | .Create(); |
| 1207 | |
| 1208 | constexpr int kOneFrame = 1; |
| 1209 | EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/123), 123); |
| 1210 | EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/59), 59); |
| 1211 | EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/135), 135); |
| 1212 | } |
| 1213 | |
| 1214 | // Even if there is an enabled input volume controller, when the input volume is |
| 1215 | // emulated, the recommended volume is always the applied volume because the |
| 1216 | // active controller must only adjust the internally emulated volume and leave |
| 1217 | // the externally applied volume unchanged. |
| 1218 | // TODO(bugs.webrtc.org/14581): Enable when APM fixed to let this test pass. |
| 1219 | TEST(AudioProcessingImplTest, |
| 1220 | DISABLED_RecommendAppliedInputVolumeWithAgcWithEmulation) { |
| 1221 | auto apm = |
| 1222 | AudioProcessingBuilder() |
| 1223 | .SetConfig({.capture_level_adjustment = {.enabled = true, |
| 1224 | .analog_mic_gain_emulation{ |
| 1225 | .enabled = true}}, |
| 1226 | .gain_controller1 = {.enabled = true, |
| 1227 | .analog_gain_controller{ |
| 1228 | .enabled = true, |
| 1229 | }}}) |
| 1230 | .Create(); |
| 1231 | |
| 1232 | constexpr int kOneFrame = 1; |
| 1233 | EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/123), 123); |
| 1234 | EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/59), 59); |
| 1235 | EXPECT_EQ(ProcessInputVolume(*apm, kOneFrame, /*initial_volume=*/135), 135); |
| 1236 | } |
| 1237 | |
Hanna Silen | a657490 | 2022-11-30 16:59:05 +0100 | [diff] [blame] | 1238 | TEST(AudioProcessingImplInputVolumeControllerExperimentTest, |
| 1239 | ConfigAdjustedWhenExperimentEnabledAndAgc1AnalogEnabled) { |
| 1240 | webrtc::test::ScopedFieldTrials field_trials( |
| 1241 | "WebRTC-Audio-InputVolumeControllerExperiment/" |
| 1242 | "Enabled," |
| 1243 | "enable_clipping_predictor:true," |
| 1244 | "clipped_level_min:20," |
| 1245 | "clipped_level_step:30," |
| 1246 | "clipped_ratio_threshold:0.4," |
| 1247 | "clipped_wait_frames:50," |
| 1248 | "target_range_max_dbfs:-6," |
| 1249 | "target_range_min_dbfs:-70," |
| 1250 | "update_input_volume_wait_frames:80," |
| 1251 | "speech_probability_threshold:0.9," |
| 1252 | "speech_ratio_threshold:1.0/"); |
| 1253 | |
| 1254 | AudioProcessingBuilderForTesting apm_builder; |
| 1255 | |
| 1256 | // Set a config with analog AGC1 enabled. |
| 1257 | AudioProcessing::Config config; |
| 1258 | config.gain_controller1.enabled = true; |
| 1259 | config.gain_controller1.analog_gain_controller.enabled = true; |
| 1260 | config.gain_controller1.analog_gain_controller.enable_digital_adaptive = true; |
| 1261 | config.gain_controller2.enabled = false; |
| 1262 | config.gain_controller1.mode = |
| 1263 | AudioProcessing::Config::GainController1::kAdaptiveAnalog; |
| 1264 | |
| 1265 | EXPECT_FALSE(config.gain_controller2.input_volume_controller.enabled); |
| 1266 | |
| 1267 | apm_builder.SetConfig(config); |
| 1268 | |
| 1269 | auto apm = apm_builder.Create(); |
| 1270 | auto adjusted_config = apm->GetConfig(); |
| 1271 | |
| 1272 | // Expect the config to be adjusted. |
| 1273 | EXPECT_FALSE(adjusted_config.gain_controller1.enabled); |
| 1274 | EXPECT_FALSE(adjusted_config.gain_controller1.analog_gain_controller.enabled); |
| 1275 | EXPECT_TRUE(adjusted_config.gain_controller2.enabled); |
| 1276 | EXPECT_TRUE(adjusted_config.gain_controller2.adaptive_digital.enabled); |
| 1277 | EXPECT_TRUE(adjusted_config.gain_controller2.input_volume_controller.enabled); |
| 1278 | |
| 1279 | // Change config back and compare. |
| 1280 | adjusted_config.gain_controller1.enabled = config.gain_controller1.enabled; |
| 1281 | adjusted_config.gain_controller1.analog_gain_controller.enabled = |
| 1282 | config.gain_controller1.analog_gain_controller.enabled; |
| 1283 | adjusted_config.gain_controller2.enabled = config.gain_controller2.enabled; |
| 1284 | adjusted_config.gain_controller2.adaptive_digital.enabled = |
| 1285 | config.gain_controller2.adaptive_digital.enabled; |
| 1286 | adjusted_config.gain_controller2.input_volume_controller.enabled = |
| 1287 | config.gain_controller2.input_volume_controller.enabled; |
| 1288 | |
| 1289 | EXPECT_THAT(adjusted_config.ToString(), ::testing::StrEq(config.ToString())); |
| 1290 | } |
| 1291 | |
| 1292 | TEST(AudioProcessingImplInputVolumeControllerExperimentTest, |
| 1293 | ConfigAdjustedWhenExperimentEnabledAndHybridAgcEnabled) { |
| 1294 | webrtc::test::ScopedFieldTrials field_trials( |
| 1295 | "WebRTC-Audio-InputVolumeControllerExperiment/" |
| 1296 | "Enabled," |
| 1297 | "enable_clipping_predictor:true," |
| 1298 | "clipped_level_min:20," |
| 1299 | "clipped_level_step:30," |
| 1300 | "clipped_ratio_threshold:0.4," |
| 1301 | "clipped_wait_frames:50," |
| 1302 | "target_range_max_dbfs:-6," |
| 1303 | "target_range_min_dbfs:-70," |
| 1304 | "update_input_volume_wait_frames:80," |
| 1305 | "speech_probability_threshold:0.9," |
| 1306 | "speech_ratio_threshold:1.0/"); |
| 1307 | |
| 1308 | AudioProcessingBuilderForTesting apm_builder; |
| 1309 | |
| 1310 | // Set a config with hybrid AGC enabled. |
| 1311 | AudioProcessing::Config config; |
| 1312 | config.gain_controller1.enabled = true; |
| 1313 | config.gain_controller1.analog_gain_controller.enabled = true; |
| 1314 | config.gain_controller1.analog_gain_controller.enable_digital_adaptive = |
| 1315 | false; |
| 1316 | config.gain_controller2.enabled = true; |
| 1317 | config.gain_controller2.adaptive_digital.enabled = true; |
| 1318 | config.gain_controller1.mode = |
| 1319 | AudioProcessing::Config::GainController1::kAdaptiveAnalog; |
| 1320 | |
| 1321 | EXPECT_FALSE(config.gain_controller2.input_volume_controller.enabled); |
| 1322 | |
| 1323 | apm_builder.SetConfig(config); |
| 1324 | |
| 1325 | auto apm = apm_builder.Create(); |
| 1326 | auto adjusted_config = apm->GetConfig(); |
| 1327 | |
| 1328 | // Expect the config to be adjusted. |
| 1329 | EXPECT_FALSE(adjusted_config.gain_controller1.enabled); |
| 1330 | EXPECT_FALSE(adjusted_config.gain_controller1.analog_gain_controller.enabled); |
| 1331 | EXPECT_TRUE(adjusted_config.gain_controller2.enabled); |
| 1332 | EXPECT_TRUE(adjusted_config.gain_controller2.adaptive_digital.enabled); |
| 1333 | EXPECT_TRUE(adjusted_config.gain_controller2.input_volume_controller.enabled); |
| 1334 | |
| 1335 | // Change config back and compare. |
| 1336 | adjusted_config.gain_controller1.enabled = config.gain_controller1.enabled; |
| 1337 | adjusted_config.gain_controller1.analog_gain_controller.enabled = |
| 1338 | config.gain_controller1.analog_gain_controller.enabled; |
| 1339 | adjusted_config.gain_controller2.enabled = config.gain_controller2.enabled; |
| 1340 | adjusted_config.gain_controller2.adaptive_digital.enabled = |
| 1341 | config.gain_controller2.adaptive_digital.enabled; |
| 1342 | adjusted_config.gain_controller2.input_volume_controller.enabled = |
| 1343 | config.gain_controller2.input_volume_controller.enabled; |
| 1344 | |
| 1345 | EXPECT_THAT(adjusted_config.ToString(), ::testing::StrEq(config.ToString())); |
| 1346 | } |
| 1347 | |
| 1348 | TEST(AudioProcessingImplInputVolumeControllerExperimentTest, |
| 1349 | ConfigNotAdjustedWhenExperimentEnabledAndAgc1AnalogNotEnabled) { |
| 1350 | webrtc::test::ScopedFieldTrials field_trials( |
| 1351 | "WebRTC-Audio-InputVolumeControllerExperiment/" |
| 1352 | "Enabled," |
| 1353 | "enable_clipping_predictor:true," |
| 1354 | "clipped_level_min:20," |
| 1355 | "clipped_level_step:30," |
| 1356 | "clipped_ratio_threshold:0.4," |
| 1357 | "clipped_wait_frames:50," |
| 1358 | "target_range_max_dbfs:-6," |
| 1359 | "target_range_min_dbfs:-70," |
| 1360 | "update_input_volume_wait_frames:80," |
| 1361 | "speech_probability_threshold:0.9," |
| 1362 | "speech_ratio_threshold:1.0/"); |
| 1363 | |
| 1364 | AudioProcessingBuilderForTesting apm_builder; |
| 1365 | |
| 1366 | // Set a config with analog AGC1 not enabled. |
| 1367 | AudioProcessing::Config config; |
| 1368 | config.gain_controller1.enabled = false; |
| 1369 | config.gain_controller1.analog_gain_controller.enabled = true; |
| 1370 | config.gain_controller1.analog_gain_controller.enable_digital_adaptive = true; |
| 1371 | config.gain_controller2.enabled = false; |
| 1372 | config.gain_controller1.mode = |
| 1373 | AudioProcessing::Config::GainController1::kAdaptiveAnalog; |
| 1374 | |
| 1375 | EXPECT_FALSE(config.gain_controller2.input_volume_controller.enabled); |
| 1376 | |
| 1377 | apm_builder.SetConfig(config); |
| 1378 | |
| 1379 | auto apm = apm_builder.Create(); |
| 1380 | auto adjusted_config = apm->GetConfig(); |
| 1381 | |
| 1382 | EXPECT_EQ(config.gain_controller1.enabled, |
| 1383 | adjusted_config.gain_controller1.enabled); |
| 1384 | EXPECT_EQ(config.gain_controller1.analog_gain_controller.enabled, |
| 1385 | adjusted_config.gain_controller1.analog_gain_controller.enabled); |
| 1386 | EXPECT_EQ(config.gain_controller2.enabled, |
| 1387 | adjusted_config.gain_controller2.enabled); |
| 1388 | EXPECT_EQ(config.gain_controller2.adaptive_digital.enabled, |
| 1389 | adjusted_config.gain_controller2.adaptive_digital.enabled); |
| 1390 | EXPECT_FALSE( |
| 1391 | adjusted_config.gain_controller2.input_volume_controller.enabled); |
| 1392 | |
| 1393 | EXPECT_THAT(adjusted_config.ToString(), ::testing::StrEq(config.ToString())); |
| 1394 | } |
| 1395 | |
| 1396 | TEST(AudioProcessingImplInputVolumeControllerExperimentTest, |
| 1397 | ConfigNotAdjustedWhenExperimentEnabledAndHybridAgcNotEnabled) { |
| 1398 | webrtc::test::ScopedFieldTrials field_trials( |
| 1399 | "WebRTC-Audio-InputVolumeControllerExperiment/" |
| 1400 | "Enabled," |
| 1401 | "enable_clipping_predictor:true," |
| 1402 | "clipped_level_min:20," |
| 1403 | "clipped_level_step:30," |
| 1404 | "clipped_ratio_threshold:0.4," |
| 1405 | "clipped_wait_frames:50," |
| 1406 | "target_range_max_dbfs:-6," |
| 1407 | "target_range_min_dbfs:-70," |
| 1408 | "update_input_volume_wait_frames:80," |
| 1409 | "speech_probability_threshold:0.9," |
| 1410 | "speech_ratio_threshold:1.0/"); |
| 1411 | |
| 1412 | AudioProcessingBuilderForTesting apm_builder; |
| 1413 | |
| 1414 | // Set a config with hybrid AGC analog not enabled. |
| 1415 | AudioProcessing::Config config; |
| 1416 | config.gain_controller1.enabled = false; |
| 1417 | config.gain_controller1.analog_gain_controller.enabled = true; |
| 1418 | config.gain_controller1.analog_gain_controller.enable_digital_adaptive = |
| 1419 | false; |
| 1420 | config.gain_controller2.enabled = true; |
| 1421 | config.gain_controller2.adaptive_digital.enabled = true; |
| 1422 | config.gain_controller1.mode = |
| 1423 | AudioProcessing::Config::GainController1::kAdaptiveAnalog; |
| 1424 | |
| 1425 | EXPECT_FALSE(config.gain_controller2.input_volume_controller.enabled); |
| 1426 | |
| 1427 | apm_builder.SetConfig(config); |
| 1428 | |
| 1429 | auto apm = apm_builder.Create(); |
| 1430 | auto adjusted_config = apm->GetConfig(); |
| 1431 | |
| 1432 | EXPECT_EQ(config.gain_controller1.enabled, |
| 1433 | adjusted_config.gain_controller1.enabled); |
| 1434 | EXPECT_EQ(config.gain_controller1.analog_gain_controller.enabled, |
| 1435 | adjusted_config.gain_controller1.analog_gain_controller.enabled); |
| 1436 | EXPECT_EQ(config.gain_controller2.enabled, |
| 1437 | adjusted_config.gain_controller2.enabled); |
| 1438 | EXPECT_EQ(config.gain_controller2.adaptive_digital.enabled, |
| 1439 | adjusted_config.gain_controller2.adaptive_digital.enabled); |
| 1440 | EXPECT_FALSE( |
| 1441 | adjusted_config.gain_controller2.input_volume_controller.enabled); |
| 1442 | |
| 1443 | EXPECT_THAT(adjusted_config.ToString(), ::testing::StrEq(config.ToString())); |
| 1444 | } |
| 1445 | |
| 1446 | TEST(AudioProcessingImplInputVolumeControllerExperimentTest, |
| 1447 | ConfigNotAdjustedWhenExperimentNotEnabledAndAgc1AnalogEnabled) { |
| 1448 | AudioProcessingBuilderForTesting apm_builder; |
| 1449 | |
| 1450 | // Set a config with analog AGC1 analog enabled. |
| 1451 | AudioProcessing::Config config; |
| 1452 | config.gain_controller1.enabled = true; |
| 1453 | config.gain_controller1.analog_gain_controller.enabled = true; |
| 1454 | config.gain_controller1.analog_gain_controller.enable_digital_adaptive = true; |
| 1455 | config.gain_controller2.enabled = false; |
| 1456 | config.gain_controller1.mode = |
| 1457 | AudioProcessing::Config::GainController1::kAdaptiveAnalog; |
| 1458 | |
| 1459 | EXPECT_FALSE(config.gain_controller2.input_volume_controller.enabled); |
| 1460 | |
| 1461 | apm_builder.SetConfig(config); |
| 1462 | |
| 1463 | auto apm = apm_builder.Create(); |
| 1464 | auto adjusted_config = apm->GetConfig(); |
| 1465 | |
| 1466 | EXPECT_EQ(config.gain_controller1.enabled, |
| 1467 | adjusted_config.gain_controller1.enabled); |
| 1468 | EXPECT_EQ(config.gain_controller1.analog_gain_controller.enabled, |
| 1469 | adjusted_config.gain_controller1.analog_gain_controller.enabled); |
| 1470 | EXPECT_EQ(config.gain_controller2.enabled, |
| 1471 | adjusted_config.gain_controller2.enabled); |
| 1472 | EXPECT_EQ(config.gain_controller2.adaptive_digital.enabled, |
| 1473 | adjusted_config.gain_controller2.adaptive_digital.enabled); |
| 1474 | EXPECT_FALSE( |
| 1475 | adjusted_config.gain_controller2.input_volume_controller.enabled); |
| 1476 | |
| 1477 | EXPECT_THAT(adjusted_config.ToString(), ::testing::StrEq(config.ToString())); |
| 1478 | } |
| 1479 | |
| 1480 | TEST(AudioProcessingImplInputVolumeControllerExperimentTest, |
| 1481 | ConfigNotAdjustedWhenExperimentNotEnabledAndHybridAgcEnabled) { |
| 1482 | AudioProcessingBuilderForTesting apm_builder; |
| 1483 | |
| 1484 | // Set a config with hybrid AGC enabled. |
| 1485 | AudioProcessing::Config config; |
| 1486 | config.gain_controller1.enabled = true; |
| 1487 | config.gain_controller1.analog_gain_controller.enabled = true; |
| 1488 | config.gain_controller1.analog_gain_controller.enable_digital_adaptive = |
| 1489 | false; |
| 1490 | config.gain_controller2.enabled = true; |
| 1491 | config.gain_controller2.adaptive_digital.enabled = true; |
| 1492 | config.gain_controller1.mode = |
| 1493 | AudioProcessing::Config::GainController1::kAdaptiveAnalog; |
| 1494 | |
| 1495 | EXPECT_FALSE(config.gain_controller2.input_volume_controller.enabled); |
| 1496 | |
| 1497 | apm_builder.SetConfig(config); |
| 1498 | |
| 1499 | auto apm = apm_builder.Create(); |
| 1500 | auto adjusted_config = apm->GetConfig(); |
| 1501 | |
| 1502 | EXPECT_EQ(config.gain_controller1.enabled, |
| 1503 | adjusted_config.gain_controller1.enabled); |
| 1504 | EXPECT_EQ(config.gain_controller1.analog_gain_controller.enabled, |
| 1505 | adjusted_config.gain_controller1.analog_gain_controller.enabled); |
| 1506 | EXPECT_EQ(config.gain_controller2.enabled, |
| 1507 | adjusted_config.gain_controller2.enabled); |
| 1508 | EXPECT_EQ(config.gain_controller2.adaptive_digital.enabled, |
| 1509 | adjusted_config.gain_controller2.adaptive_digital.enabled); |
| 1510 | EXPECT_FALSE( |
| 1511 | adjusted_config.gain_controller2.input_volume_controller.enabled); |
| 1512 | |
| 1513 | EXPECT_THAT(adjusted_config.ToString(), ::testing::StrEq(config.ToString())); |
| 1514 | } |
| 1515 | |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 1516 | } // namespace webrtc |