minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <stddef.h> // size_t |
kwiberg | 62eaacf | 2016-02-17 14:39:05 | [diff] [blame] | 12 | |
kwiberg | 84be511 | 2016-04-27 08:19:58 | [diff] [blame] | 13 | #include <memory> |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Ali Tofigh | f3592cb | 2022-08-16 12:44:38 | [diff] [blame] | 17 | #include "absl/strings/string_view.h" |
Gustaf Ullberg | 0efa941 | 2018-02-27 12:58:45 | [diff] [blame] | 18 | #include "api/audio/echo_canceller3_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 19 | #include "modules/audio_coding/neteq/tools/resample_input_audio_file.h" |
| 20 | #include "modules/audio_processing/aec_dump/aec_dump_factory.h" |
Per Åhgren | cc73ed3 | 2020-04-26 21:56:17 | [diff] [blame] | 21 | #include "modules/audio_processing/test/audio_processing_builder_for_testing.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 22 | #include "modules/audio_processing/test/debug_dump_replayer.h" |
| 23 | #include "modules/audio_processing/test/test_utils.h" |
Danil Chapovalov | 07122bc | 2019-03-26 13:37:01 | [diff] [blame] | 24 | #include "rtc_base/task_queue_for_test.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 25 | #include "test/gtest.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 26 | #include "test/testsupport/file_utils.h" |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | namespace test { |
| 30 | |
| 31 | namespace { |
| 32 | |
kwiberg | 62eaacf | 2016-02-17 14:39:05 | [diff] [blame] | 33 | void MaybeResetBuffer(std::unique_ptr<ChannelBuffer<float>>* buffer, |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 34 | const StreamConfig& config) { |
| 35 | auto& buffer_ref = *buffer; |
| 36 | if (!buffer_ref.get() || buffer_ref->num_frames() != config.num_frames() || |
| 37 | buffer_ref->num_channels() != config.num_channels()) { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 38 | buffer_ref.reset( |
| 39 | new ChannelBuffer<float>(config.num_frames(), config.num_channels())); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | |
| 43 | class DebugDumpGenerator { |
| 44 | public: |
Ali Tofigh | f3592cb | 2022-08-16 12:44:38 | [diff] [blame] | 45 | DebugDumpGenerator(absl::string_view input_file_name, |
Alex Loiko | 890988c | 2017-08-31 08:25:48 | [diff] [blame] | 46 | int input_rate_hz, |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 47 | int input_channels, |
Ali Tofigh | f3592cb | 2022-08-16 12:44:38 | [diff] [blame] | 48 | absl::string_view reverse_file_name, |
Alex Loiko | 890988c | 2017-08-31 08:25:48 | [diff] [blame] | 49 | int reverse_rate_hz, |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 50 | int reverse_channels, |
Ali Tofigh | f3592cb | 2022-08-16 12:44:38 | [diff] [blame] | 51 | absl::string_view dump_file_name, |
Alex Loiko | 6234722 | 2018-09-10 08:18:07 | [diff] [blame] | 52 | bool enable_pre_amplifier); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 53 | |
| 54 | // Constructor that uses default input files. |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 55 | explicit DebugDumpGenerator(const AudioProcessing::Config& apm_config); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 56 | |
| 57 | ~DebugDumpGenerator(); |
| 58 | |
| 59 | // Changes the sample rate of the input audio to the APM. |
| 60 | void SetInputRate(int rate_hz); |
| 61 | |
| 62 | // Sets if converts stereo input signal to mono by discarding other channels. |
| 63 | void ForceInputMono(bool mono); |
| 64 | |
| 65 | // Changes the sample rate of the reverse audio to the APM. |
| 66 | void SetReverseRate(int rate_hz); |
| 67 | |
| 68 | // Sets if converts stereo reverse signal to mono by discarding other |
| 69 | // channels. |
| 70 | void ForceReverseMono(bool mono); |
| 71 | |
| 72 | // Sets the required sample rate of the APM output. |
| 73 | void SetOutputRate(int rate_hz); |
| 74 | |
| 75 | // Sets the required channels of the APM output. |
| 76 | void SetOutputChannels(int channels); |
| 77 | |
| 78 | std::string dump_file_name() const { return dump_file_name_; } |
| 79 | |
| 80 | void StartRecording(); |
| 81 | void Process(size_t num_blocks); |
| 82 | void StopRecording(); |
| 83 | AudioProcessing* apm() const { return apm_.get(); } |
| 84 | |
| 85 | private: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 86 | static void ReadAndDeinterleave(ResampleInputAudioFile* audio, |
| 87 | int channels, |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 88 | const StreamConfig& config, |
| 89 | float* const* buffer); |
| 90 | |
| 91 | // APM input/output settings. |
| 92 | StreamConfig input_config_; |
| 93 | StreamConfig reverse_config_; |
| 94 | StreamConfig output_config_; |
| 95 | |
| 96 | // Input file format. |
| 97 | const std::string input_file_name_; |
| 98 | ResampleInputAudioFile input_audio_; |
| 99 | const int input_file_channels_; |
| 100 | |
| 101 | // Reverse file format. |
| 102 | const std::string reverse_file_name_; |
| 103 | ResampleInputAudioFile reverse_audio_; |
| 104 | const int reverse_file_channels_; |
| 105 | |
| 106 | // Buffer for APM input/output. |
kwiberg | 62eaacf | 2016-02-17 14:39:05 | [diff] [blame] | 107 | std::unique_ptr<ChannelBuffer<float>> input_; |
| 108 | std::unique_ptr<ChannelBuffer<float>> reverse_; |
| 109 | std::unique_ptr<ChannelBuffer<float>> output_; |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 110 | |
Alex Loiko | 6234722 | 2018-09-10 08:18:07 | [diff] [blame] | 111 | bool enable_pre_amplifier_; |
| 112 | |
Danil Chapovalov | 07122bc | 2019-03-26 13:37:01 | [diff] [blame] | 113 | TaskQueueForTest worker_queue_; |
Niels Möller | 4f776ac | 2021-07-02 09:30:54 | [diff] [blame] | 114 | rtc::scoped_refptr<AudioProcessing> apm_; |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 115 | |
| 116 | const std::string dump_file_name_; |
| 117 | }; |
| 118 | |
Ali Tofigh | f3592cb | 2022-08-16 12:44:38 | [diff] [blame] | 119 | DebugDumpGenerator::DebugDumpGenerator(absl::string_view input_file_name, |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 120 | int input_rate_hz, |
| 121 | int input_channels, |
Ali Tofigh | f3592cb | 2022-08-16 12:44:38 | [diff] [blame] | 122 | absl::string_view reverse_file_name, |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 123 | int reverse_rate_hz, |
| 124 | int reverse_channels, |
Ali Tofigh | f3592cb | 2022-08-16 12:44:38 | [diff] [blame] | 125 | absl::string_view dump_file_name, |
Alex Loiko | 6234722 | 2018-09-10 08:18:07 | [diff] [blame] | 126 | bool enable_pre_amplifier) |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 127 | : input_config_(input_rate_hz, input_channels), |
| 128 | reverse_config_(reverse_rate_hz, reverse_channels), |
| 129 | output_config_(input_rate_hz, input_channels), |
| 130 | input_audio_(input_file_name, input_rate_hz, input_rate_hz), |
| 131 | input_file_channels_(input_channels), |
| 132 | reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz), |
| 133 | reverse_file_channels_(reverse_channels), |
| 134 | input_(new ChannelBuffer<float>(input_config_.num_frames(), |
| 135 | input_config_.num_channels())), |
| 136 | reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(), |
| 137 | reverse_config_.num_channels())), |
| 138 | output_(new ChannelBuffer<float>(output_config_.num_frames(), |
| 139 | output_config_.num_channels())), |
Alex Loiko | 6234722 | 2018-09-10 08:18:07 | [diff] [blame] | 140 | enable_pre_amplifier_(enable_pre_amplifier), |
aleloi | f4dd191 | 2017-06-15 08:55:38 | [diff] [blame] | 141 | worker_queue_("debug_dump_generator_worker_queue"), |
Ivo Creusen | 62337e5 | 2018-01-09 13:17:33 | [diff] [blame] | 142 | dump_file_name_(dump_file_name) { |
Per Åhgren | cc73ed3 | 2020-04-26 21:56:17 | [diff] [blame] | 143 | AudioProcessingBuilderForTesting apm_builder; |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 144 | apm_ = apm_builder.Create(); |
Ivo Creusen | 62337e5 | 2018-01-09 13:17:33 | [diff] [blame] | 145 | } |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 146 | |
peah | 88ac853 | 2016-09-12 23:47:25 | [diff] [blame] | 147 | DebugDumpGenerator::DebugDumpGenerator( |
Per Åhgren | 200feba1c | 2019-03-06 03:16:46 | [diff] [blame] | 148 | const AudioProcessing::Config& apm_config) |
peah | 88ac853 | 2016-09-12 23:47:25 | [diff] [blame] | 149 | : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"), |
| 150 | 32000, |
| 151 | 2, |
| 152 | ResourcePath("far32_stereo", "pcm"), |
| 153 | 32000, |
| 154 | 2, |
Gustaf Ullberg | bd83b91 | 2017-10-18 10:32:42 | [diff] [blame] | 155 | TempFilename(OutputPath(), "debug_aec"), |
Alex Loiko | 6234722 | 2018-09-10 08:18:07 | [diff] [blame] | 156 | apm_config.pre_amplifier.enabled) { |
Gustaf Ullberg | bd83b91 | 2017-10-18 10:32:42 | [diff] [blame] | 157 | apm_->ApplyConfig(apm_config); |
| 158 | } |
| 159 | |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 160 | DebugDumpGenerator::~DebugDumpGenerator() { |
| 161 | remove(dump_file_name_.c_str()); |
| 162 | } |
| 163 | |
| 164 | void DebugDumpGenerator::SetInputRate(int rate_hz) { |
| 165 | input_audio_.set_output_rate_hz(rate_hz); |
| 166 | input_config_.set_sample_rate_hz(rate_hz); |
| 167 | MaybeResetBuffer(&input_, input_config_); |
| 168 | } |
| 169 | |
| 170 | void DebugDumpGenerator::ForceInputMono(bool mono) { |
| 171 | const int channels = mono ? 1 : input_file_channels_; |
| 172 | input_config_.set_num_channels(channels); |
| 173 | MaybeResetBuffer(&input_, input_config_); |
| 174 | } |
| 175 | |
| 176 | void DebugDumpGenerator::SetReverseRate(int rate_hz) { |
| 177 | reverse_audio_.set_output_rate_hz(rate_hz); |
| 178 | reverse_config_.set_sample_rate_hz(rate_hz); |
| 179 | MaybeResetBuffer(&reverse_, reverse_config_); |
| 180 | } |
| 181 | |
| 182 | void DebugDumpGenerator::ForceReverseMono(bool mono) { |
| 183 | const int channels = mono ? 1 : reverse_file_channels_; |
| 184 | reverse_config_.set_num_channels(channels); |
| 185 | MaybeResetBuffer(&reverse_, reverse_config_); |
| 186 | } |
| 187 | |
| 188 | void DebugDumpGenerator::SetOutputRate(int rate_hz) { |
| 189 | output_config_.set_sample_rate_hz(rate_hz); |
| 190 | MaybeResetBuffer(&output_, output_config_); |
| 191 | } |
| 192 | |
| 193 | void DebugDumpGenerator::SetOutputChannels(int channels) { |
| 194 | output_config_.set_num_channels(channels); |
| 195 | MaybeResetBuffer(&output_, output_config_); |
| 196 | } |
| 197 | |
| 198 | void DebugDumpGenerator::StartRecording() { |
aleloi | f4dd191 | 2017-06-15 08:55:38 | [diff] [blame] | 199 | apm_->AttachAecDump( |
| 200 | AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_)); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | void DebugDumpGenerator::Process(size_t num_blocks) { |
| 204 | for (size_t i = 0; i < num_blocks; ++i) { |
| 205 | ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_, |
| 206 | reverse_config_, reverse_->channels()); |
| 207 | ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_, |
| 208 | input_->channels()); |
| 209 | RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100)); |
Per Åhgren | 0695df1 | 2020-01-13 13:43:13 | [diff] [blame] | 210 | apm_->set_stream_analog_level(100); |
Alex Loiko | 6234722 | 2018-09-10 08:18:07 | [diff] [blame] | 211 | if (enable_pre_amplifier_) { |
| 212 | apm_->SetRuntimeSetting( |
| 213 | AudioProcessing::RuntimeSetting::CreateCapturePreGain(1 + i % 10)); |
| 214 | } |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 215 | apm_->set_stream_key_pressed(i % 10 == 9); |
| 216 | RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 217 | apm_->ProcessStream(input_->channels(), input_config_, |
| 218 | output_config_, output_->channels())); |
| 219 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 220 | RTC_CHECK_EQ( |
| 221 | AudioProcessing::kNoError, |
| 222 | apm_->ProcessReverseStream(reverse_->channels(), reverse_config_, |
| 223 | reverse_config_, reverse_->channels())); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
| 227 | void DebugDumpGenerator::StopRecording() { |
aleloi | f4dd191 | 2017-06-15 08:55:38 | [diff] [blame] | 228 | apm_->DetachAecDump(); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio, |
| 232 | int channels, |
| 233 | const StreamConfig& config, |
| 234 | float* const* buffer) { |
| 235 | const size_t num_frames = config.num_frames(); |
| 236 | const int out_channels = config.num_channels(); |
| 237 | |
| 238 | std::vector<int16_t> signal(channels * num_frames); |
| 239 | |
| 240 | audio->Read(num_frames * channels, &signal[0]); |
| 241 | |
| 242 | // We only allow reducing number of channels by discarding some channels. |
| 243 | RTC_CHECK_LE(out_channels, channels); |
| 244 | for (int channel = 0; channel < out_channels; ++channel) { |
| 245 | for (size_t i = 0; i < num_frames; ++i) { |
| 246 | buffer[channel][i] = S16ToFloat(signal[i * channels + channel]); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | } // namespace |
| 252 | |
| 253 | class DebugDumpTest : public ::testing::Test { |
| 254 | public: |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 255 | // VerifyDebugDump replays a debug dump using APM and verifies that the result |
| 256 | // is bit-exact-identical to the output channel in the dump. This is only |
| 257 | // guaranteed if the debug dump is started on the first frame. |
Ali Tofigh | f3592cb | 2022-08-16 12:44:38 | [diff] [blame] | 258 | void VerifyDebugDump(absl::string_view in_filename); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 259 | |
| 260 | private: |
minyue | 0de1c13 | 2016-03-17 09:39:30 | [diff] [blame] | 261 | DebugDumpReplayer debug_dump_replayer_; |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 262 | }; |
| 263 | |
Ali Tofigh | f3592cb | 2022-08-16 12:44:38 | [diff] [blame] | 264 | void DebugDumpTest::VerifyDebugDump(absl::string_view in_filename) { |
minyue | 0de1c13 | 2016-03-17 09:39:30 | [diff] [blame] | 265 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename)); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 266 | |
Danil Chapovalov | db9f7ab | 2018-06-19 08:50:11 | [diff] [blame] | 267 | while (const absl::optional<audioproc::Event> event = |
| 268 | debug_dump_replayer_.GetNextEvent()) { |
minyue | 0de1c13 | 2016-03-17 09:39:30 | [diff] [blame] | 269 | debug_dump_replayer_.RunNextEvent(); |
| 270 | if (event->type() == audioproc::Event::STREAM) { |
| 271 | const audioproc::Stream* msg = &event->stream(); |
| 272 | const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig(); |
| 273 | const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput(); |
| 274 | // Check that output of APM is bit-exact to the output in the dump. |
| 275 | ASSERT_EQ(output_config.num_channels(), |
| 276 | static_cast<size_t>(msg->output_channel_size())); |
| 277 | ASSERT_EQ(output_config.num_frames() * sizeof(float), |
| 278 | msg->output_channel(0).size()); |
| 279 | for (int i = 0; i < msg->output_channel_size(); ++i) { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 280 | ASSERT_EQ(0, |
| 281 | memcmp(output->channels()[i], msg->output_channel(i).data(), |
| 282 | msg->output_channel(i).size())); |
minyue | 0de1c13 | 2016-03-17 09:39:30 | [diff] [blame] | 283 | } |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 284 | } |
| 285 | } |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | TEST_F(DebugDumpTest, SimpleCase) { |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 289 | DebugDumpGenerator generator(/*apm_config=*/{}); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 290 | generator.StartRecording(); |
| 291 | generator.Process(100); |
| 292 | generator.StopRecording(); |
| 293 | VerifyDebugDump(generator.dump_file_name()); |
| 294 | } |
| 295 | |
| 296 | TEST_F(DebugDumpTest, ChangeInputFormat) { |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 297 | DebugDumpGenerator generator(/*apm_config=*/{}); |
peah | 88ac853 | 2016-09-12 23:47:25 | [diff] [blame] | 298 | |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 299 | generator.StartRecording(); |
| 300 | generator.Process(100); |
| 301 | generator.SetInputRate(48000); |
| 302 | |
| 303 | generator.ForceInputMono(true); |
| 304 | // Number of output channel should not be larger than that of input. APM will |
| 305 | // fail otherwise. |
| 306 | generator.SetOutputChannels(1); |
| 307 | |
| 308 | generator.Process(100); |
| 309 | generator.StopRecording(); |
| 310 | VerifyDebugDump(generator.dump_file_name()); |
| 311 | } |
| 312 | |
| 313 | TEST_F(DebugDumpTest, ChangeReverseFormat) { |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 314 | DebugDumpGenerator generator(/*apm_config=*/{}); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 315 | generator.StartRecording(); |
| 316 | generator.Process(100); |
| 317 | generator.SetReverseRate(48000); |
| 318 | generator.ForceReverseMono(true); |
| 319 | generator.Process(100); |
| 320 | generator.StopRecording(); |
| 321 | VerifyDebugDump(generator.dump_file_name()); |
| 322 | } |
| 323 | |
| 324 | TEST_F(DebugDumpTest, ChangeOutputFormat) { |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 325 | DebugDumpGenerator generator(/*apm_config=*/{}); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 326 | generator.StartRecording(); |
| 327 | generator.Process(100); |
| 328 | generator.SetOutputRate(48000); |
| 329 | generator.SetOutputChannels(1); |
| 330 | generator.Process(100); |
| 331 | generator.StopRecording(); |
| 332 | VerifyDebugDump(generator.dump_file_name()); |
| 333 | } |
| 334 | |
| 335 | TEST_F(DebugDumpTest, ToggleAec) { |
Sam Zackrisson | cdf0e6d | 2018-09-17 09:05:17 | [diff] [blame] | 336 | AudioProcessing::Config apm_config; |
Sam Zackrisson | cdf0e6d | 2018-09-17 09:05:17 | [diff] [blame] | 337 | apm_config.echo_canceller.enabled = true; |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 338 | DebugDumpGenerator generator(apm_config); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 339 | generator.StartRecording(); |
| 340 | generator.Process(100); |
| 341 | |
Per Åhgren | b810646 | 2019-12-04 07:34:12 | [diff] [blame] | 342 | apm_config.echo_canceller.enabled = false; |
Sam Zackrisson | cdf0e6d | 2018-09-17 09:05:17 | [diff] [blame] | 343 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 344 | |
| 345 | generator.Process(100); |
| 346 | generator.StopRecording(); |
| 347 | VerifyDebugDump(generator.dump_file_name()); |
| 348 | } |
| 349 | |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 350 | TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) { |
peah | e0eae3c | 2016-12-14 09:16:23 | [diff] [blame] | 351 | AudioProcessing::Config apm_config; |
Sam Zackrisson | b3b47ad | 2018-08-17 14:26:14 | [diff] [blame] | 352 | apm_config.echo_canceller.enabled = true; |
Per Åhgren | 0695df1 | 2020-01-13 13:43:13 | [diff] [blame] | 353 | apm_config.gain_controller1.analog_gain_controller.enabled = true; |
| 354 | apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0; |
henrik.lundin | bd681b9 | 2016-12-05 17:08:42 | [diff] [blame] | 355 | // Arbitrarily set clipping gain to 17, which will never be the default. |
Per Åhgren | 0695df1 | 2020-01-13 13:43:13 | [diff] [blame] | 356 | apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17; |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 357 | DebugDumpGenerator generator(apm_config); |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 358 | generator.StartRecording(); |
| 359 | generator.Process(100); |
| 360 | generator.StopRecording(); |
| 361 | |
| 362 | DebugDumpReplayer debug_dump_replayer_; |
| 363 | |
| 364 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name())); |
| 365 | |
Danil Chapovalov | db9f7ab | 2018-06-19 08:50:11 | [diff] [blame] | 366 | while (const absl::optional<audioproc::Event> event = |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 367 | debug_dump_replayer_.GetNextEvent()) { |
| 368 | debug_dump_replayer_.RunNextEvent(); |
| 369 | if (event->type() == audioproc::Event::CONFIG) { |
| 370 | const audioproc::Config* msg = &event->config(); |
| 371 | ASSERT_TRUE(msg->has_experiments_description()); |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 372 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController", |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 373 | msg->experiments_description().c_str()); |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 374 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment", |
henrik.lundin | bd681b9 | 2016-12-05 17:08:42 | [diff] [blame] | 375 | msg->experiments_description().c_str()); |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) { |
Per Åhgren | 200feba1c | 2019-03-06 03:16:46 | [diff] [blame] | 381 | AudioProcessing::Config apm_config; |
| 382 | apm_config.echo_canceller.enabled = true; |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 383 | DebugDumpGenerator generator(apm_config); |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 384 | generator.StartRecording(); |
| 385 | generator.Process(100); |
| 386 | generator.StopRecording(); |
| 387 | |
| 388 | DebugDumpReplayer debug_dump_replayer_; |
| 389 | |
| 390 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name())); |
| 391 | |
Danil Chapovalov | db9f7ab | 2018-06-19 08:50:11 | [diff] [blame] | 392 | while (const absl::optional<audioproc::Event> event = |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 393 | debug_dump_replayer_.GetNextEvent()) { |
| 394 | debug_dump_replayer_.RunNextEvent(); |
| 395 | if (event->type() == audioproc::Event::CONFIG) { |
| 396 | const audioproc::Config* msg = &event->config(); |
| 397 | ASSERT_TRUE(msg->has_experiments_description()); |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 398 | EXPECT_PRED_FORMAT2(::testing::IsNotSubstring, |
| 399 | "AgcClippingLevelExperiment", |
henrik.lundin | bd681b9 | 2016-12-05 17:08:42 | [diff] [blame] | 400 | msg->experiments_description().c_str()); |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
peah | 7789fe7 | 2016-04-15 08:19:44 | [diff] [blame] | 405 | TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) { |
peah | e0eae3c | 2016-12-14 09:16:23 | [diff] [blame] | 406 | AudioProcessing::Config apm_config; |
Sam Zackrisson | b3b47ad | 2018-08-17 14:26:14 | [diff] [blame] | 407 | apm_config.echo_canceller.enabled = true; |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 408 | DebugDumpGenerator generator(apm_config); |
peah | 7789fe7 | 2016-04-15 08:19:44 | [diff] [blame] | 409 | generator.StartRecording(); |
| 410 | generator.Process(100); |
| 411 | generator.StopRecording(); |
| 412 | |
| 413 | DebugDumpReplayer debug_dump_replayer_; |
| 414 | |
| 415 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name())); |
| 416 | |
Danil Chapovalov | db9f7ab | 2018-06-19 08:50:11 | [diff] [blame] | 417 | while (const absl::optional<audioproc::Event> event = |
peah | 7789fe7 | 2016-04-15 08:19:44 | [diff] [blame] | 418 | debug_dump_replayer_.GetNextEvent()) { |
| 419 | debug_dump_replayer_.RunNextEvent(); |
| 420 | if (event->type() == audioproc::Event::CONFIG) { |
| 421 | const audioproc::Config* msg = &event->config(); |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 422 | ASSERT_TRUE(msg->has_experiments_description()); |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 423 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController", |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 424 | msg->experiments_description().c_str()); |
peah | 7789fe7 | 2016-04-15 08:19:44 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
henrik.lundin | bd681b9 | 2016-12-05 17:08:42 | [diff] [blame] | 429 | TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) { |
Per Åhgren | 0695df1 | 2020-01-13 13:43:13 | [diff] [blame] | 430 | AudioProcessing::Config apm_config; |
| 431 | apm_config.gain_controller1.analog_gain_controller.enabled = true; |
| 432 | apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0; |
henrik.lundin | bd681b9 | 2016-12-05 17:08:42 | [diff] [blame] | 433 | // Arbitrarily set clipping gain to 17, which will never be the default. |
Per Åhgren | 0695df1 | 2020-01-13 13:43:13 | [diff] [blame] | 434 | apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17; |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 435 | DebugDumpGenerator generator(apm_config); |
henrik.lundin | bd681b9 | 2016-12-05 17:08:42 | [diff] [blame] | 436 | generator.StartRecording(); |
| 437 | generator.Process(100); |
| 438 | generator.StopRecording(); |
| 439 | |
| 440 | DebugDumpReplayer debug_dump_replayer_; |
| 441 | |
| 442 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name())); |
| 443 | |
Danil Chapovalov | db9f7ab | 2018-06-19 08:50:11 | [diff] [blame] | 444 | while (const absl::optional<audioproc::Event> event = |
henrik.lundin | bd681b9 | 2016-12-05 17:08:42 | [diff] [blame] | 445 | debug_dump_replayer_.GetNextEvent()) { |
| 446 | debug_dump_replayer_.RunNextEvent(); |
| 447 | if (event->type() == audioproc::Event::CONFIG) { |
| 448 | const audioproc::Config* msg = &event->config(); |
| 449 | ASSERT_TRUE(msg->has_experiments_description()); |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 450 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment", |
henrik.lundin | bd681b9 | 2016-12-05 17:08:42 | [diff] [blame] | 451 | msg->experiments_description().c_str()); |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
peah | 7789fe7 | 2016-04-15 08:19:44 | [diff] [blame] | 456 | TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) { |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 457 | DebugDumpGenerator generator(/*apm_config=*/{}); |
peah | 7789fe7 | 2016-04-15 08:19:44 | [diff] [blame] | 458 | generator.StartRecording(); |
| 459 | generator.Process(100); |
| 460 | generator.StopRecording(); |
| 461 | |
| 462 | DebugDumpReplayer debug_dump_replayer_; |
| 463 | |
| 464 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name())); |
| 465 | |
Danil Chapovalov | db9f7ab | 2018-06-19 08:50:11 | [diff] [blame] | 466 | while (const absl::optional<audioproc::Event> event = |
peah | 7789fe7 | 2016-04-15 08:19:44 | [diff] [blame] | 467 | debug_dump_replayer_.GetNextEvent()) { |
| 468 | debug_dump_replayer_.RunNextEvent(); |
| 469 | if (event->type() == audioproc::Event::CONFIG) { |
| 470 | const audioproc::Config* msg = &event->config(); |
peah | 0332c2d | 2016-04-15 18:23:33 | [diff] [blame] | 471 | ASSERT_TRUE(msg->has_experiments_description()); |
peah | 7789fe7 | 2016-04-15 08:19:44 | [diff] [blame] | 472 | EXPECT_EQ(0u, msg->experiments_description().size()); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
Kári Tristan Helgason | 470c088 | 2016-10-03 11:13:29 | [diff] [blame] | 477 | // AGC is not supported on Android or iOS. |
| 478 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 479 | #define MAYBE_ToggleAgc DISABLED_ToggleAgc |
| 480 | #else |
| 481 | #define MAYBE_ToggleAgc ToggleAgc |
| 482 | #endif |
| 483 | TEST_F(DebugDumpTest, MAYBE_ToggleAgc) { |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 484 | DebugDumpGenerator generator(/*apm_config=*/{}); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 485 | generator.StartRecording(); |
| 486 | generator.Process(100); |
| 487 | |
Sam Zackrisson | 41478c7 | 2019-10-15 08:10:26 | [diff] [blame] | 488 | AudioProcessing::Config apm_config = generator.apm()->GetConfig(); |
| 489 | apm_config.gain_controller1.enabled = !apm_config.gain_controller1.enabled; |
| 490 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 491 | |
| 492 | generator.Process(100); |
| 493 | generator.StopRecording(); |
| 494 | VerifyDebugDump(generator.dump_file_name()); |
| 495 | } |
| 496 | |
| 497 | TEST_F(DebugDumpTest, ToggleNs) { |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 498 | DebugDumpGenerator generator(/*apm_config=*/{}); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 499 | generator.StartRecording(); |
| 500 | generator.Process(100); |
| 501 | |
Sam Zackrisson | 2351313 | 2019-01-11 14:10:32 | [diff] [blame] | 502 | AudioProcessing::Config apm_config = generator.apm()->GetConfig(); |
| 503 | apm_config.noise_suppression.enabled = !apm_config.noise_suppression.enabled; |
| 504 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 505 | |
| 506 | generator.Process(100); |
| 507 | generator.StopRecording(); |
| 508 | VerifyDebugDump(generator.dump_file_name()); |
| 509 | } |
| 510 | |
| 511 | TEST_F(DebugDumpTest, TransientSuppressionOn) { |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 512 | DebugDumpGenerator generator(/*apm_config=*/{}); |
Per Åhgren | c073471 | 2020-01-02 14:15:36 | [diff] [blame] | 513 | |
| 514 | AudioProcessing::Config apm_config = generator.apm()->GetConfig(); |
| 515 | apm_config.transient_suppression.enabled = true; |
| 516 | generator.apm()->ApplyConfig(apm_config); |
| 517 | |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 518 | generator.StartRecording(); |
| 519 | generator.Process(100); |
| 520 | generator.StopRecording(); |
| 521 | VerifyDebugDump(generator.dump_file_name()); |
| 522 | } |
| 523 | |
Alex Loiko | 6234722 | 2018-09-10 08:18:07 | [diff] [blame] | 524 | TEST_F(DebugDumpTest, PreAmplifierIsOn) { |
Alex Loiko | 6234722 | 2018-09-10 08:18:07 | [diff] [blame] | 525 | AudioProcessing::Config apm_config; |
| 526 | apm_config.pre_amplifier.enabled = true; |
Alessio Bazzica | be1b898 | 2021-09-17 06:26:10 | [diff] [blame] | 527 | DebugDumpGenerator generator(apm_config); |
Alex Loiko | 6234722 | 2018-09-10 08:18:07 | [diff] [blame] | 528 | generator.StartRecording(); |
| 529 | generator.Process(100); |
| 530 | generator.StopRecording(); |
| 531 | VerifyDebugDump(generator.dump_file_name()); |
| 532 | } |
| 533 | |
minyue | 275d255 | 2015-11-04 14:23:54 | [diff] [blame] | 534 | } // namespace test |
| 535 | } // namespace webrtc |