Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: webrtc/modules/audio_processing/test/audio_processing_simulator.cc

Issue 2846853002: audioproc_f with fake microphone. (Closed)
Patch Set: Initialized FakeRecordingDevice, added 'kind' command line flag, fixed bugs. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { 73 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) {
74 dest->data_[sample * dest->num_channels_ + ch] = 74 dest->data_[sample * dest->num_channels_ + ch] =
75 src.channels()[ch][sample] * 32767; 75 src.channels()[ch][sample] * 32767;
76 } 76 }
77 } 77 }
78 } 78 }
79 79
80 AudioProcessingSimulator::AudioProcessingSimulator( 80 AudioProcessingSimulator::AudioProcessingSimulator(
81 const SimulationSettings& settings) 81 const SimulationSettings& settings)
82 : settings_(settings) { 82 : settings_(settings) {
83 if (settings_.simulate_mic_gain) {
84 fake_recording_device_.emplace(
85 static_cast<FakeRecordingDevice::LevelToScalingMappingKind>(
86 *settings_.simulated_mic_kind));
87 }
83 if (settings_.ed_graph_output_filename && 88 if (settings_.ed_graph_output_filename &&
84 settings_.ed_graph_output_filename->size() > 0) { 89 settings_.ed_graph_output_filename->size() > 0) {
85 residual_echo_likelihood_graph_writer_.open( 90 residual_echo_likelihood_graph_writer_.open(
86 *settings_.ed_graph_output_filename); 91 *settings_.ed_graph_output_filename);
87 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); 92 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open());
88 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); 93 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_);
89 } 94 }
90 } 95 }
91 96
92 AudioProcessingSimulator::~AudioProcessingSimulator() { 97 AudioProcessingSimulator::~AudioProcessingSimulator() {
93 if (residual_echo_likelihood_graph_writer_.is_open()) { 98 if (residual_echo_likelihood_graph_writer_.is_open()) {
94 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); 99 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_);
95 residual_echo_likelihood_graph_writer_.close(); 100 residual_echo_likelihood_graph_writer_.close();
96 } 101 }
97 } 102 }
98 103
99 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { 104 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() {
100 int64_t interval = rtc::TimeNanos() - start_time_; 105 int64_t interval = rtc::TimeNanos() - start_time_;
101 proc_time_->sum += interval; 106 proc_time_->sum += interval;
102 proc_time_->max = std::max(proc_time_->max, interval); 107 proc_time_->max = std::max(proc_time_->max, interval);
103 proc_time_->min = std::min(proc_time_->min, interval); 108 proc_time_->min = std::min(proc_time_->min, interval);
104 } 109 }
105 110
106 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { 111 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) {
107 if (fixed_interface) { 112 if (fixed_interface) {
108 { 113 {
109 const auto st = ScopedTimer(mutable_proc_time()); 114 const auto st = ScopedTimer(mutable_proc_time());
110 // TODO(alessiob): Change fwd_frame_ simulating a mic with analog gain and 115 if (fake_recording_device_) {
111 // an application gain. 116 fake_recording_device_->ProcessStream(&fwd_frame_, &fwd_frame_);
117 }
112 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); 118 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_));
113 } 119 }
114 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); 120 CopyFromAudioFrame(fwd_frame_, out_buf_.get());
115 } else { 121 } else {
116 const auto st = ScopedTimer(mutable_proc_time()); 122 const auto st = ScopedTimer(mutable_proc_time());
117 // TODO(alessiob): Change in_buf_->channels() simulating a mic with analog 123 if (fake_recording_device_) {
118 // gain and an application gain. 124 const size_t channel_size = in_config_.num_frames();
125
126 std::vector<rtc::ArrayView<const float>> data_view;
127 std::vector<rtc::ArrayView<float>> after_scaling_view;
128 for (size_t i = 0; i < in_config_.num_channels(); ++i) {
129 data_view.emplace_back(in_buf_->channels()[i], channel_size);
130 after_scaling_view.emplace_back(in_buf_->channels()[i], channel_size);
131 }
132
133 fake_recording_device_->ProcessStream(data_view, after_scaling_view);
134 }
119 RTC_CHECK_EQ(AudioProcessing::kNoError, 135 RTC_CHECK_EQ(AudioProcessing::kNoError,
120 ap_->ProcessStream(in_buf_->channels(), in_config_, 136 ap_->ProcessStream(in_buf_->channels(), in_config_,
121 out_config_, out_buf_->channels())); 137 out_config_, out_buf_->channels()));
122 } 138 }
123 139
124 if (buffer_writer_) { 140 if (buffer_writer_) {
125 buffer_writer_->Write(*out_buf_); 141 buffer_writer_->Write(*out_buf_);
126 } 142 }
127 143
128 if (residual_echo_likelihood_graph_writer_.is_open()) { 144 if (residual_echo_likelihood_graph_writer_.is_open()) {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize; 409 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize;
394 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); 410 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize);
395 RTC_CHECK_EQ(AudioProcessing::kNoError, 411 RTC_CHECK_EQ(AudioProcessing::kNoError,
396 ap_->StartDebugRecording( 412 ap_->StartDebugRecording(
397 settings_.aec_dump_output_filename->c_str(), -1)); 413 settings_.aec_dump_output_filename->c_str(), -1));
398 } 414 }
399 } 415 }
400 416
401 } // namespace test 417 } // namespace test
402 } // namespace webrtc 418 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698