Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/audio_processing/test/audio_processing_simulator.h" | 11 #include "webrtc/modules/audio_processing/test/audio_processing_simulator.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <iostream> | 14 #include <iostream> |
| 15 #include <sstream> | 15 #include <sstream> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <utility> | |
| 17 #include <vector> | 18 #include <vector> |
| 18 | 19 |
| 19 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
| 21 #include "webrtc/base/logging.h" | |
| 20 #include "webrtc/base/stringutils.h" | 22 #include "webrtc/base/stringutils.h" |
| 21 #include "webrtc/common_audio/include/audio_util.h" | 23 #include "webrtc/common_audio/include/audio_util.h" |
| 22 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 24 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 25 #include "webrtc/modules/audio_processing/test/fake_recording_device.h" | |
| 23 | 26 |
| 24 namespace webrtc { | 27 namespace webrtc { |
| 25 namespace test { | 28 namespace test { |
| 26 namespace { | 29 namespace { |
| 27 | 30 |
| 31 constexpr FakeRecordingDevice::DeviceKind kDefaultFakeRecDeviceKind = | |
| 32 FakeRecordingDevice::DeviceKind::IDENTITY; | |
| 33 | |
| 28 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { | 34 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { |
| 29 RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); | 35 RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); |
| 30 RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames()); | 36 RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames()); |
| 31 // Copy the data from the input buffer. | 37 // Copy the data from the input buffer. |
| 32 std::vector<float> tmp(src.samples_per_channel_ * src.num_channels_); | 38 std::vector<float> tmp(src.samples_per_channel_ * src.num_channels_); |
| 33 S16ToFloat(src.data(), tmp.size(), tmp.data()); | 39 S16ToFloat(src.data(), tmp.size(), tmp.data()); |
| 34 Deinterleave(tmp.data(), src.samples_per_channel_, src.num_channels_, | 40 Deinterleave(tmp.data(), src.samples_per_channel_, src.num_channels_, |
| 35 dest->channels()); | 41 dest->channels()); |
| 36 } | 42 } |
| 37 | 43 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { | 78 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { |
| 73 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { | 79 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { |
| 74 dest_data[sample * dest->num_channels_ + ch] = | 80 dest_data[sample * dest->num_channels_ + ch] = |
| 75 src.channels()[ch][sample] * 32767; | 81 src.channels()[ch][sample] * 32767; |
| 76 } | 82 } |
| 77 } | 83 } |
| 78 } | 84 } |
| 79 | 85 |
| 80 AudioProcessingSimulator::AudioProcessingSimulator( | 86 AudioProcessingSimulator::AudioProcessingSimulator( |
| 81 const SimulationSettings& settings) | 87 const SimulationSettings& settings) |
| 82 : settings_(settings) { | 88 : settings_(settings), |
| 89 fake_recording_device_(new FakeRecordingDevice( | |
|
peah-webrtc
2017/06/29 05:45:27
You don't need to create this dynamically. Since y
AleBzk
2017/06/29 11:43:35
Thanks. I recalled why I added the member as a uni
| |
| 90 settings.initial_mic_level, | |
| 91 settings_.simulate_mic_gain ? static_cast< | |
| 92 FakeRecordingDevice::DeviceKind>(*settings.simulated_mic_kind) | |
| 93 : kDefaultFakeRecDeviceKind)) { | |
| 94 RTC_DCHECK(fake_recording_device_); | |
| 83 if (settings_.ed_graph_output_filename && | 95 if (settings_.ed_graph_output_filename && |
| 84 settings_.ed_graph_output_filename->size() > 0) { | 96 settings_.ed_graph_output_filename->size() > 0) { |
| 85 residual_echo_likelihood_graph_writer_.open( | 97 residual_echo_likelihood_graph_writer_.open( |
| 86 *settings_.ed_graph_output_filename); | 98 *settings_.ed_graph_output_filename); |
| 87 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); | 99 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); |
| 88 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); | 100 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); |
| 89 } | 101 } |
| 90 } | 102 } |
| 91 | 103 |
| 92 AudioProcessingSimulator::~AudioProcessingSimulator() { | 104 AudioProcessingSimulator::~AudioProcessingSimulator() { |
| 93 if (residual_echo_likelihood_graph_writer_.is_open()) { | 105 if (residual_echo_likelihood_graph_writer_.is_open()) { |
| 94 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); | 106 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); |
| 95 residual_echo_likelihood_graph_writer_.close(); | 107 residual_echo_likelihood_graph_writer_.close(); |
| 96 } | 108 } |
| 97 } | 109 } |
| 98 | 110 |
| 99 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { | 111 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { |
| 100 int64_t interval = rtc::TimeNanos() - start_time_; | 112 int64_t interval = rtc::TimeNanos() - start_time_; |
| 101 proc_time_->sum += interval; | 113 proc_time_->sum += interval; |
| 102 proc_time_->max = std::max(proc_time_->max, interval); | 114 proc_time_->max = std::max(proc_time_->max, interval); |
| 103 proc_time_->min = std::min(proc_time_->min, interval); | 115 proc_time_->min = std::min(proc_time_->min, interval); |
| 104 } | 116 } |
| 105 | 117 |
| 106 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { | 118 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { |
| 119 if (settings_.aec_dump_input_filename) { | |
| 120 RTC_DCHECK(aec_dump_mic_level_); | |
| 121 if (settings_.simulate_mic_gain) { | |
| 122 // When the analog gain is sumulated and an AEC dump is used as input, set | |
| 123 // the undo level to |aec_dump_mic_level_| to virtually restore the | |
| 124 // unmodified microphone signal level. | |
| 125 fake_recording_device_->set_undo_mic_level(aec_dump_mic_level_); | |
| 126 } else { | |
| 127 // When the analog gain is not simulated, the AEC dump level must to be | |
| 128 // used to override the value set from the gain controller in the | |
| 129 // previously analyzed audio frame. | |
| 130 fake_recording_device_->set_mic_level(*aec_dump_mic_level_); | |
|
AleBzk
2017/06/22 10:16:01
Line 130 overrides what is set in lines 145-147.
peah-webrtc
2017/06/29 05:45:26
As I commented on a previous patch, I definitely d
AleBzk
2017/06/29 11:43:35
Thanks. Sorry for having kept this. It's up to us
| |
| 131 } | |
| 132 } | |
|
AleBzk
2017/06/22 10:16:01
About lines 119-132: the AEC dump analog gain simu
| |
| 133 | |
| 134 // Optionally use the fake recording device to simulate analog gain. | |
| 135 RTC_DCHECK(fake_recording_device_); | |
| 136 if (settings_.simulate_mic_gain) { | |
| 137 if (fixed_interface) { | |
| 138 fake_recording_device_->SimulateAnalogGain(&fwd_frame_); | |
|
peah-webrtc
2017/06/29 05:45:26
Why not just add the optional aec_dump_mic_level_
AleBzk
2017/06/29 11:43:35
I'd prefer as it is now, otherwise we have to add
peah-webrtc
2017/06/29 22:03:59
I would personally prefer to have it as one single
| |
| 139 } else { | |
| 140 fake_recording_device_->SimulateAnalogGain(in_buf_.get()); | |
| 141 } | |
| 142 } | |
| 143 | |
| 144 // Notify the current mic level to AGC. | |
| 145 RTC_CHECK_EQ(AudioProcessing::kNoError, | |
| 146 ap_->gain_control()->set_stream_analog_level( | |
| 147 fake_recording_device_->mic_level())); | |
|
peah-webrtc
2017/06/29 05:45:27
This is something that I think complicates the cod
AleBzk
2017/06/29 11:43:35
What happens during a call is that AGC suggests a
peah-webrtc
2017/06/29 22:03:59
You definitely need to pass the mic gain to the fa
| |
| 148 | |
| 149 // Process the current audio frame. | |
| 107 if (fixed_interface) { | 150 if (fixed_interface) { |
| 108 { | 151 { |
| 109 const auto st = ScopedTimer(mutable_proc_time()); | 152 const auto st = ScopedTimer(mutable_proc_time()); |
| 110 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); | 153 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); |
| 111 } | 154 } |
| 112 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); | 155 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); |
| 113 } else { | 156 } else { |
| 114 const auto st = ScopedTimer(mutable_proc_time()); | 157 const auto st = ScopedTimer(mutable_proc_time()); |
| 115 RTC_CHECK_EQ(AudioProcessing::kNoError, | 158 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 116 ap_->ProcessStream(in_buf_->channels(), in_config_, | 159 ap_->ProcessStream(in_buf_->channels(), in_config_, |
| 117 out_config_, out_buf_->channels())); | 160 out_config_, out_buf_->channels())); |
| 118 } | 161 } |
| 119 | 162 |
| 163 // Store the mic level suggested by AGC if required. | |
|
peah-webrtc
2017/06/29 05:45:27
The comment "if required" seems out of place. Coul
AleBzk
2017/06/29 11:43:35
Done.
| |
| 164 fake_recording_device_->set_mic_level( | |
| 165 ap_->gain_control()->stream_analog_level()); | |
| 166 | |
| 120 if (buffer_writer_) { | 167 if (buffer_writer_) { |
| 121 buffer_writer_->Write(*out_buf_); | 168 buffer_writer_->Write(*out_buf_); |
| 122 } | 169 } |
| 123 | 170 |
| 124 if (residual_echo_likelihood_graph_writer_.is_open()) { | 171 if (residual_echo_likelihood_graph_writer_.is_open()) { |
| 125 auto stats = ap_->GetStatistics(); | 172 auto stats = ap_->GetStatistics(); |
| 126 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood | 173 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood |
| 127 << ", "; | 174 << ", "; |
| 128 } | 175 } |
| 129 | 176 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 fwd_frame_.samples_per_channel_ = | 234 fwd_frame_.samples_per_channel_ = |
| 188 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); | 235 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); |
| 189 fwd_frame_.num_channels_ = input_num_channels; | 236 fwd_frame_.num_channels_ = input_num_channels; |
| 190 | 237 |
| 191 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; | 238 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; |
| 192 rev_frame_.samples_per_channel_ = | 239 rev_frame_.samples_per_channel_ = |
| 193 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); | 240 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); |
| 194 rev_frame_.num_channels_ = reverse_input_num_channels; | 241 rev_frame_.num_channels_ = reverse_input_num_channels; |
| 195 | 242 |
| 196 if (settings_.use_verbose_logging) { | 243 if (settings_.use_verbose_logging) { |
| 244 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); | |
| 245 | |
| 197 std::cout << "Sample rates:" << std::endl; | 246 std::cout << "Sample rates:" << std::endl; |
| 198 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; | 247 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; |
| 199 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; | 248 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; |
| 200 std::cout << " Reverse input: " << reverse_input_sample_rate_hz | 249 std::cout << " Reverse input: " << reverse_input_sample_rate_hz |
| 201 << std::endl; | 250 << std::endl; |
| 202 std::cout << " Reverse output: " << reverse_output_sample_rate_hz | 251 std::cout << " Reverse output: " << reverse_output_sample_rate_hz |
| 203 << std::endl; | 252 << std::endl; |
| 204 std::cout << "Number of channels: " << std::endl; | 253 std::cout << "Number of channels: " << std::endl; |
| 205 std::cout << " Forward input: " << input_num_channels << std::endl; | 254 std::cout << " Forward input: " << input_num_channels << std::endl; |
| 206 std::cout << " Forward output: " << output_num_channels << std::endl; | 255 std::cout << " Forward output: " << output_num_channels << std::endl; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize; | 441 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize; |
| 393 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); | 442 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); |
| 394 RTC_CHECK_EQ(AudioProcessing::kNoError, | 443 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 395 ap_->StartDebugRecording( | 444 ap_->StartDebugRecording( |
| 396 settings_.aec_dump_output_filename->c_str(), -1)); | 445 settings_.aec_dump_output_filename->c_str(), -1)); |
| 397 } | 446 } |
| 398 } | 447 } |
| 399 | 448 |
| 400 } // namespace test | 449 } // namespace test |
| 401 } // namespace webrtc | 450 } // namespace webrtc |
| OLD | NEW |