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" |
| 23 | 25 |
| 24 namespace webrtc { | 26 namespace webrtc { |
| 25 namespace test { | 27 namespace test { |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 30 constexpr FakeRecordingDevice::LevelToScalingMappingKind kDefaultMicKind = | |
| 31 FakeRecordingDevice::LevelToScalingMappingKind::kIdentity; | |
| 32 | |
| 28 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { | 33 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { |
| 29 RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); | 34 RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); |
| 30 RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames()); | 35 RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames()); |
| 31 // Copy the data from the input buffer. | 36 // Copy the data from the input buffer. |
| 32 std::vector<float> tmp(src.samples_per_channel_ * src.num_channels_); | 37 std::vector<float> tmp(src.samples_per_channel_ * src.num_channels_); |
| 33 S16ToFloat(src.data_, tmp.size(), tmp.data()); | 38 S16ToFloat(src.data_, tmp.size(), tmp.data()); |
| 34 Deinterleave(tmp.data(), src.samples_per_channel_, src.num_channels_, | 39 Deinterleave(tmp.data(), src.samples_per_channel_, src.num_channels_, |
| 35 dest->channels()); | 40 dest->channels()); |
| 36 } | 41 } |
| 37 | 42 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { | 76 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { |
| 72 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { | 77 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { |
| 73 dest->data_[sample * dest->num_channels_ + ch] = | 78 dest->data_[sample * dest->num_channels_ + ch] = |
| 74 src.channels()[ch][sample] * 32767; | 79 src.channels()[ch][sample] * 32767; |
| 75 } | 80 } |
| 76 } | 81 } |
| 77 } | 82 } |
| 78 | 83 |
| 79 AudioProcessingSimulator::AudioProcessingSimulator( | 84 AudioProcessingSimulator::AudioProcessingSimulator( |
| 80 const SimulationSettings& settings) | 85 const SimulationSettings& settings) |
| 81 : settings_(settings) { | 86 : settings_(settings), |
| 87 last_specified_microphone_level_(settings.initial_mic_gain), | |
| 88 fake_recording_device_(settings_.simulate_mic_gain ? | |
| 89 static_cast<FakeRecordingDevice::LevelToScalingMappingKind>( | |
| 90 *settings.simulated_mic_kind) : kDefaultMicKind) { | |
| 82 if (settings_.ed_graph_output_filename && | 91 if (settings_.ed_graph_output_filename && |
| 83 settings_.ed_graph_output_filename->size() > 0) { | 92 settings_.ed_graph_output_filename->size() > 0) { |
| 84 residual_echo_likelihood_graph_writer_.open( | 93 residual_echo_likelihood_graph_writer_.open( |
| 85 *settings_.ed_graph_output_filename); | 94 *settings_.ed_graph_output_filename); |
| 86 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); | 95 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); |
| 87 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); | 96 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); |
| 88 } | 97 } |
| 89 } | 98 } |
| 90 | 99 |
| 91 AudioProcessingSimulator::~AudioProcessingSimulator() { | 100 AudioProcessingSimulator::~AudioProcessingSimulator() { |
| 92 if (residual_echo_likelihood_graph_writer_.is_open()) { | 101 if (residual_echo_likelihood_graph_writer_.is_open()) { |
| 93 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); | 102 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); |
| 94 residual_echo_likelihood_graph_writer_.close(); | 103 residual_echo_likelihood_graph_writer_.close(); |
| 95 } | 104 } |
| 96 } | 105 } |
| 97 | 106 |
| 98 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { | 107 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { |
| 99 int64_t interval = rtc::TimeNanos() - start_time_; | 108 int64_t interval = rtc::TimeNanos() - start_time_; |
| 100 proc_time_->sum += interval; | 109 proc_time_->sum += interval; |
| 101 proc_time_->max = std::max(proc_time_->max, interval); | 110 proc_time_->max = std::max(proc_time_->max, interval); |
| 102 proc_time_->min = std::min(proc_time_->min, interval); | 111 proc_time_->min = std::min(proc_time_->min, interval); |
| 103 } | 112 } |
| 104 | 113 |
| 105 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { | 114 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { |
| 115 // Optionally use the fake recording device to simulate analog gain. | |
| 116 if (settings_.simulate_mic_gain) { | |
| 117 if (fixed_interface) { | |
| 118 fake_recording_device_.SimulateAnalogGain( | |
| 119 &fwd_frame_, &fwd_frame_, last_specified_microphone_level_, | |
| 120 real_recording_device_level_); | |
| 121 } else { | |
| 122 const size_t channel_size = in_config_.num_frames(); | |
| 123 | |
| 124 std::vector<rtc::ArrayView<const float>> data_view; | |
|
peah-webrtc
2017/05/05 20:25:21
The lines 122-129 are only there to conform to the
AleBzk
2017/05/16 08:53:03
Done.
| |
| 125 std::vector<rtc::ArrayView<float>> after_scaling_view; | |
| 126 for (size_t i = 0; i < in_config_.num_channels(); ++i) { | |
| 127 data_view.emplace_back(in_buf_->channels()[i], channel_size); | |
| 128 after_scaling_view.emplace_back(in_buf_->channels()[i], channel_size); | |
| 129 } | |
| 130 | |
| 131 fake_recording_device_.SimulateAnalogGain( | |
| 132 data_view, after_scaling_view, last_specified_microphone_level_, | |
| 133 real_recording_device_level_); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 // Notify the mic gain level to AGC. | |
| 138 LOG(LS_VERBOSE) << "AGC set_stream_analog_level set to " | |
| 139 << last_specified_microphone_level_; | |
| 140 RTC_CHECK_EQ(AudioProcessing::kNoError, | |
| 141 ap_->gain_control()->set_stream_analog_level( | |
| 142 last_specified_microphone_level_)); | |
| 143 | |
| 144 // Process the current audio frame. | |
| 106 if (fixed_interface) { | 145 if (fixed_interface) { |
| 107 { | 146 { |
| 108 const auto st = ScopedTimer(mutable_proc_time()); | 147 const auto st = ScopedTimer(mutable_proc_time()); |
| 109 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); | 148 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); |
| 110 } | 149 } |
| 111 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); | 150 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); |
| 112 } else { | 151 } else { |
| 113 const auto st = ScopedTimer(mutable_proc_time()); | 152 const auto st = ScopedTimer(mutable_proc_time()); |
| 114 RTC_CHECK_EQ(AudioProcessing::kNoError, | 153 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 115 ap_->ProcessStream(in_buf_->channels(), in_config_, | 154 ap_->ProcessStream(in_buf_->channels(), in_config_, |
| 116 out_config_, out_buf_->channels())); | 155 out_config_, out_buf_->channels())); |
| 117 } | 156 } |
| 118 | 157 |
| 158 // Store the mic gain level suggested by AGC if required. | |
| 159 last_specified_microphone_level_ = ap_->gain_control()->stream_analog_level(); | |
|
peah-webrtc
2017/05/05 20:25:21
With the changes done in this CL, I think last_spe
AleBzk
2017/05/16 08:53:03
Done.
| |
| 160 | |
| 119 if (buffer_writer_) { | 161 if (buffer_writer_) { |
| 120 buffer_writer_->Write(*out_buf_); | 162 buffer_writer_->Write(*out_buf_); |
| 121 } | 163 } |
| 122 | 164 |
| 123 if (residual_echo_likelihood_graph_writer_.is_open()) { | 165 if (residual_echo_likelihood_graph_writer_.is_open()) { |
| 124 auto stats = ap_->GetStatistics(); | 166 auto stats = ap_->GetStatistics(); |
| 125 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood | 167 residual_echo_likelihood_graph_writer_ |
| 126 << ", "; | 168 << stats.residual_echo_likelihood << ", "; |
|
peah-webrtc
2017/05/05 20:25:21
Unrelated change?
AleBzk
2017/05/16 08:53:03
yup, sorry. I switched back.
| |
| 127 } | 169 } |
| 128 | 170 |
| 129 ++num_process_stream_calls_; | 171 ++num_process_stream_calls_; |
| 130 } | 172 } |
| 131 | 173 |
| 132 void AudioProcessingSimulator::ProcessReverseStream(bool fixed_interface) { | 174 void AudioProcessingSimulator::ProcessReverseStream(bool fixed_interface) { |
| 133 if (fixed_interface) { | 175 if (fixed_interface) { |
| 134 const auto st = ScopedTimer(mutable_proc_time()); | 176 const auto st = ScopedTimer(mutable_proc_time()); |
| 135 RTC_CHECK_EQ(AudioProcessing::kNoError, | 177 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 136 ap_->ProcessReverseStream(&rev_frame_)); | 178 ap_->ProcessReverseStream(&rev_frame_)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 fwd_frame_.samples_per_channel_ = | 228 fwd_frame_.samples_per_channel_ = |
| 187 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); | 229 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); |
| 188 fwd_frame_.num_channels_ = input_num_channels; | 230 fwd_frame_.num_channels_ = input_num_channels; |
| 189 | 231 |
| 190 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; | 232 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; |
| 191 rev_frame_.samples_per_channel_ = | 233 rev_frame_.samples_per_channel_ = |
| 192 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); | 234 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); |
| 193 rev_frame_.num_channels_ = reverse_input_num_channels; | 235 rev_frame_.num_channels_ = reverse_input_num_channels; |
| 194 | 236 |
| 195 if (settings_.use_verbose_logging) { | 237 if (settings_.use_verbose_logging) { |
| 238 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); | |
| 239 | |
| 196 std::cout << "Sample rates:" << std::endl; | 240 std::cout << "Sample rates:" << std::endl; |
| 197 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; | 241 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; |
| 198 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; | 242 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; |
| 199 std::cout << " Reverse input: " << reverse_input_sample_rate_hz | 243 std::cout << " Reverse input: " << reverse_input_sample_rate_hz |
| 200 << std::endl; | 244 << std::endl; |
| 201 std::cout << " Reverse output: " << reverse_output_sample_rate_hz | 245 std::cout << " Reverse output: " << reverse_output_sample_rate_hz |
| 202 << std::endl; | 246 << std::endl; |
| 203 std::cout << "Number of channels: " << std::endl; | 247 std::cout << "Number of channels: " << std::endl; |
| 204 std::cout << " Forward input: " << input_num_channels << std::endl; | 248 std::cout << " Forward input: " << input_num_channels << std::endl; |
| 205 std::cout << " Forward output: " << output_num_channels << std::endl; | 249 std::cout << " Forward output: " << output_num_channels << std::endl; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize; | 432 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize; |
| 389 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); | 433 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); |
| 390 RTC_CHECK_EQ(AudioProcessing::kNoError, | 434 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 391 ap_->StartDebugRecording( | 435 ap_->StartDebugRecording( |
| 392 settings_.aec_dump_output_filename->c_str(), -1)); | 436 settings_.aec_dump_output_filename->c_str(), -1)); |
| 393 } | 437 } |
| 394 } | 438 } |
| 395 | 439 |
| 396 } // namespace test | 440 } // namespace test |
| 397 } // namespace webrtc | 441 } // namespace webrtc |
| OLD | NEW |