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 |
| 28 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { | 30 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { |
| 29 RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); | 31 RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { | 73 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { |
| 72 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { | 74 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { |
| 73 dest->data_[sample * dest->num_channels_ + ch] = | 75 dest->data_[sample * dest->num_channels_ + ch] = |
| 74 src.channels()[ch][sample] * 32767; | 76 src.channels()[ch][sample] * 32767; |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 | 80 |
| 79 AudioProcessingSimulator::AudioProcessingSimulator( | 81 AudioProcessingSimulator::AudioProcessingSimulator( |
| 80 const SimulationSettings& settings) | 82 const SimulationSettings& settings) |
| 81 : settings_(settings) { | 83 : settings_(settings), |
| 84 fake_recording_device_(settings_.simulate_mic_gain ? | |
| 85 static_cast<FakeRecordingDevice::LevelToScalingMappingKind>( | |
| 86 *settings.simulated_mic_kind) : kDefaultMicKind) { | |
| 87 if (settings_.simulate_mic_gain) { | |
| 88 fake_recording_device_.set_analog_level(kInitialMicrophoneGainLevel); | |
| 89 } | |
| 82 if (settings_.ed_graph_output_filename && | 90 if (settings_.ed_graph_output_filename && |
| 83 settings_.ed_graph_output_filename->size() > 0) { | 91 settings_.ed_graph_output_filename->size() > 0) { |
| 84 residual_echo_likelihood_graph_writer_.open( | 92 residual_echo_likelihood_graph_writer_.open( |
| 85 *settings_.ed_graph_output_filename); | 93 *settings_.ed_graph_output_filename); |
| 86 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); | 94 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); |
| 87 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); | 95 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); |
| 88 } | 96 } |
| 89 } | 97 } |
| 90 | 98 |
| 91 AudioProcessingSimulator::~AudioProcessingSimulator() { | 99 AudioProcessingSimulator::~AudioProcessingSimulator() { |
| 92 if (residual_echo_likelihood_graph_writer_.is_open()) { | 100 if (residual_echo_likelihood_graph_writer_.is_open()) { |
| 93 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); | 101 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); |
| 94 residual_echo_likelihood_graph_writer_.close(); | 102 residual_echo_likelihood_graph_writer_.close(); |
| 95 } | 103 } |
| 96 } | 104 } |
| 97 | 105 |
| 98 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { | 106 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { |
| 99 int64_t interval = rtc::TimeNanos() - start_time_; | 107 int64_t interval = rtc::TimeNanos() - start_time_; |
| 100 proc_time_->sum += interval; | 108 proc_time_->sum += interval; |
| 101 proc_time_->max = std::max(proc_time_->max, interval); | 109 proc_time_->max = std::max(proc_time_->max, interval); |
| 102 proc_time_->min = std::min(proc_time_->min, interval); | 110 proc_time_->min = std::min(proc_time_->min, interval); |
| 103 } | 111 } |
| 104 | 112 |
| 105 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { | 113 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { |
| 114 LOG(LS_VERBOSE) << "AGC set_stream_analog_level set to " | |
|
peah-webrtc
2017/05/05 06:28:41
Too verbose logging.
AleBzk
2017/05/05 12:20:17
I only removed the log below (namely, LOG(LS_VERBO
peah-webrtc
2017/05/05 20:25:20
I would not analyze the AGC suggested values like
| |
| 115 << fake_recording_device_.analog_level(); | |
| 116 RTC_CHECK_EQ(AudioProcessing::kNoError, | |
| 117 ap_->gain_control()->set_stream_analog_level( | |
|
peah-webrtc
2017/05/05 06:28:41
I'd prefer a decoupling between the stored stream
AleBzk
2017/05/05 12:20:17
Done.
| |
| 118 fake_recording_device_.analog_level())); | |
| 119 | |
| 106 if (fixed_interface) { | 120 if (fixed_interface) { |
| 107 { | 121 { |
| 108 const auto st = ScopedTimer(mutable_proc_time()); | 122 const auto st = ScopedTimer(mutable_proc_time()); |
| 123 // TODO(alessiob): Simulate application gain. | |
| 124 if (settings_.simulate_mic_gain) { | |
| 125 fake_recording_device_.ProcessStream(&fwd_frame_, &fwd_frame_); | |
| 126 } | |
| 109 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); | 127 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); |
| 110 } | 128 } |
| 111 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); | 129 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); |
| 112 } else { | 130 } else { |
| 113 const auto st = ScopedTimer(mutable_proc_time()); | 131 const auto st = ScopedTimer(mutable_proc_time()); |
| 132 // TODO(alessiob): Simulate application gain. | |
| 133 if (settings_.simulate_mic_gain) { | |
| 134 const size_t channel_size = in_config_.num_frames(); | |
| 135 | |
| 136 std::vector<rtc::ArrayView<const float>> data_view; | |
| 137 std::vector<rtc::ArrayView<float>> after_scaling_view; | |
| 138 for (size_t i = 0; i < in_config_.num_channels(); ++i) { | |
| 139 data_view.emplace_back(in_buf_->channels()[i], channel_size); | |
| 140 after_scaling_view.emplace_back(in_buf_->channels()[i], channel_size); | |
| 141 } | |
| 142 | |
| 143 fake_recording_device_.ProcessStream(data_view, after_scaling_view); | |
| 144 } | |
| 114 RTC_CHECK_EQ(AudioProcessing::kNoError, | 145 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 115 ap_->ProcessStream(in_buf_->channels(), in_config_, | 146 ap_->ProcessStream(in_buf_->channels(), in_config_, |
| 116 out_config_, out_buf_->channels())); | 147 out_config_, out_buf_->channels())); |
| 117 } | 148 } |
| 118 | 149 |
| 150 // Store the mic gain level suggested by AGC if required. | |
| 151 fake_recording_device_.set_analog_level( | |
| 152 ap_->gain_control()->stream_analog_level()); | |
| 153 LOG(LS_VERBOSE) << "AGC stream_analog_level() returned " | |
|
peah-webrtc
2017/05/05 06:28:41
This will become too much logging.
AleBzk
2017/05/05 12:20:17
Done.
| |
| 154 << fake_recording_device_.analog_level(); | |
| 155 | |
| 119 if (buffer_writer_) { | 156 if (buffer_writer_) { |
| 120 buffer_writer_->Write(*out_buf_); | 157 buffer_writer_->Write(*out_buf_); |
| 121 } | 158 } |
| 122 | 159 |
| 123 if (residual_echo_likelihood_graph_writer_.is_open()) { | 160 if (residual_echo_likelihood_graph_writer_.is_open()) { |
| 124 auto stats = ap_->GetStatistics(); | 161 auto stats = ap_->GetStatistics(); |
| 125 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood | 162 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood |
| 126 << ", "; | 163 << ", "; |
| 127 } | 164 } |
| 128 | 165 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 fwd_frame_.samples_per_channel_ = | 223 fwd_frame_.samples_per_channel_ = |
| 187 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); | 224 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); |
| 188 fwd_frame_.num_channels_ = input_num_channels; | 225 fwd_frame_.num_channels_ = input_num_channels; |
| 189 | 226 |
| 190 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; | 227 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; |
| 191 rev_frame_.samples_per_channel_ = | 228 rev_frame_.samples_per_channel_ = |
| 192 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); | 229 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); |
| 193 rev_frame_.num_channels_ = reverse_input_num_channels; | 230 rev_frame_.num_channels_ = reverse_input_num_channels; |
| 194 | 231 |
| 195 if (settings_.use_verbose_logging) { | 232 if (settings_.use_verbose_logging) { |
| 233 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); | |
| 234 | |
| 196 std::cout << "Sample rates:" << std::endl; | 235 std::cout << "Sample rates:" << std::endl; |
| 197 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; | 236 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; |
| 198 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; | 237 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; |
| 199 std::cout << " Reverse input: " << reverse_input_sample_rate_hz | 238 std::cout << " Reverse input: " << reverse_input_sample_rate_hz |
| 200 << std::endl; | 239 << std::endl; |
| 201 std::cout << " Reverse output: " << reverse_output_sample_rate_hz | 240 std::cout << " Reverse output: " << reverse_output_sample_rate_hz |
| 202 << std::endl; | 241 << std::endl; |
| 203 std::cout << "Number of channels: " << std::endl; | 242 std::cout << "Number of channels: " << std::endl; |
| 204 std::cout << " Forward input: " << input_num_channels << std::endl; | 243 std::cout << " Forward input: " << input_num_channels << std::endl; |
| 205 std::cout << " Forward output: " << output_num_channels << std::endl; | 244 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; | 427 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize; |
| 389 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); | 428 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); |
| 390 RTC_CHECK_EQ(AudioProcessing::kNoError, | 429 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 391 ap_->StartDebugRecording( | 430 ap_->StartDebugRecording( |
| 392 settings_.aec_dump_output_filename->c_str(), -1)); | 431 settings_.aec_dump_output_filename->c_str(), -1)); |
| 393 } | 432 } |
| 394 } | 433 } |
| 395 | 434 |
| 396 } // namespace test | 435 } // namespace test |
| 397 } // namespace webrtc | 436 } // namespace webrtc |
| OLD | NEW |