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

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

Issue 2834643002: audioproc_f with simulated mic analog gain (Closed)
Patch Set: AEC dump + fake rec device bugfix Created 3 years, 3 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
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/common_audio/include/audio_util.h" 20 #include "webrtc/common_audio/include/audio_util.h"
20 #include "webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h" 21 #include "webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h"
21 #include "webrtc/modules/audio_processing/include/audio_processing.h" 22 #include "webrtc/modules/audio_processing/include/audio_processing.h"
23 #include "webrtc/modules/audio_processing/test/fake_recording_device.h"
22 #include "webrtc/rtc_base/checks.h" 24 #include "webrtc/rtc_base/checks.h"
25 #include "webrtc/rtc_base/logging.h"
23 #include "webrtc/rtc_base/stringutils.h" 26 #include "webrtc/rtc_base/stringutils.h"
24 27
25 namespace webrtc { 28 namespace webrtc {
26 namespace test { 29 namespace test {
27 namespace { 30 namespace {
28 31
29 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { 32 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) {
30 RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); 33 RTC_CHECK_EQ(src.num_channels_, dest->num_channels());
31 RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames()); 34 RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames());
32 // Copy the data from the input buffer. 35 // Copy the data from the input buffer.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { 76 for (size_t ch = 0; ch < dest->num_channels_; ++ch) {
74 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { 77 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) {
75 dest_data[sample * dest->num_channels_ + ch] = 78 dest_data[sample * dest->num_channels_ + ch] =
76 src.channels()[ch][sample] * 32767; 79 src.channels()[ch][sample] * 32767;
77 } 80 }
78 } 81 }
79 } 82 }
80 83
81 AudioProcessingSimulator::AudioProcessingSimulator( 84 AudioProcessingSimulator::AudioProcessingSimulator(
82 const SimulationSettings& settings) 85 const SimulationSettings& settings)
83 : settings_(settings), worker_queue_("file_writer_task_queue") { 86 : settings_(settings),
87 analog_mic_level_(settings.initial_mic_level),
88 fake_recording_device_(
89 settings.initial_mic_level,
90 settings_.simulate_mic_gain ? *settings.simulated_mic_kind : 0),
91 worker_queue_("file_writer_task_queue") {
84 if (settings_.ed_graph_output_filename && 92 if (settings_.ed_graph_output_filename &&
85 settings_.ed_graph_output_filename->size() > 0) { 93 settings_.ed_graph_output_filename->size() > 0) {
86 residual_echo_likelihood_graph_writer_.open( 94 residual_echo_likelihood_graph_writer_.open(
87 *settings_.ed_graph_output_filename); 95 *settings_.ed_graph_output_filename);
88 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); 96 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open());
89 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); 97 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_);
90 } 98 }
91 } 99 }
92 100
93 AudioProcessingSimulator::~AudioProcessingSimulator() { 101 AudioProcessingSimulator::~AudioProcessingSimulator() {
94 if (residual_echo_likelihood_graph_writer_.is_open()) { 102 if (residual_echo_likelihood_graph_writer_.is_open()) {
95 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); 103 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_);
96 residual_echo_likelihood_graph_writer_.close(); 104 residual_echo_likelihood_graph_writer_.close();
97 } 105 }
98 } 106 }
99 107
100 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { 108 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() {
101 int64_t interval = rtc::TimeNanos() - start_time_; 109 int64_t interval = rtc::TimeNanos() - start_time_;
102 proc_time_->sum += interval; 110 proc_time_->sum += interval;
103 proc_time_->max = std::max(proc_time_->max, interval); 111 proc_time_->max = std::max(proc_time_->max, interval);
104 proc_time_->min = std::min(proc_time_->min, interval); 112 proc_time_->min = std::min(proc_time_->min, interval);
105 } 113 }
106 114
107 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { 115 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) {
116 // Optionally use the fake recording device to simulate analog gain.
117 if (settings_.simulate_mic_gain) {
118 if (settings_.aec_dump_input_filename) {
119 // When the analog gain is simulated and an AEC dump is used as input, set
120 // the undo level to |aec_dump_mic_level_| to virtually restore the
121 // unmodified microphone signal level.
122 RTC_DCHECK(aec_dump_mic_level_);
123 fake_recording_device_.SetUndoMicLevel(aec_dump_mic_level_);
124 }
125
126 if (fixed_interface) {
127 fake_recording_device_.SimulateAnalogGain(&fwd_frame_);
128 } else {
129 fake_recording_device_.SimulateAnalogGain(in_buf_.get());
130 }
131
132 // Notify the current mic level to AGC.
133 RTC_CHECK_EQ(AudioProcessing::kNoError,
134 ap_->gain_control()->set_stream_analog_level(
135 fake_recording_device_.MicLevel()));
136 } else {
137 // Notify the current mic level to AGC.
138 if (settings_.aec_dump_input_filename) {
139 // AEC dump case.
140 RTC_DCHECK(aec_dump_mic_level_);
141 RTC_CHECK_EQ(
142 AudioProcessing::kNoError,
143 ap_->gain_control()->set_stream_analog_level(*aec_dump_mic_level_));
144 } else {
145 // Wav input file case.
146 RTC_CHECK_EQ(
147 AudioProcessing::kNoError,
148 ap_->gain_control()->set_stream_analog_level(analog_mic_level_));
peah-webrtc 2017/09/15 09:36:20 What about bundling line 148 with 143 using a cond
AleBzk 2017/09/22 12:33:55 Done.
149 }
150 }
151
152 // Process the current audio frame.
108 if (fixed_interface) { 153 if (fixed_interface) {
109 { 154 {
110 const auto st = ScopedTimer(mutable_proc_time()); 155 const auto st = ScopedTimer(mutable_proc_time());
111 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); 156 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_));
112 } 157 }
113 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); 158 CopyFromAudioFrame(fwd_frame_, out_buf_.get());
114 } else { 159 } else {
115 const auto st = ScopedTimer(mutable_proc_time()); 160 const auto st = ScopedTimer(mutable_proc_time());
116 RTC_CHECK_EQ(AudioProcessing::kNoError, 161 RTC_CHECK_EQ(AudioProcessing::kNoError,
117 ap_->ProcessStream(in_buf_->channels(), in_config_, 162 ap_->ProcessStream(in_buf_->channels(), in_config_,
118 out_config_, out_buf_->channels())); 163 out_config_, out_buf_->channels()));
119 } 164 }
120 165
166 // Store the mic level suggested by AGC.
167 // Note that when the analog gain is simulated and an AEC dump is used as
168 // input, |analog_mic_level_| will not be used with set_stream_analog_level().
169 analog_mic_level_ = ap_->gain_control()->stream_analog_level();
170 if (settings_.simulate_mic_gain) {
171 fake_recording_device_.SetMicLevel(analog_mic_level_);
172 }
173
121 if (buffer_writer_) { 174 if (buffer_writer_) {
122 buffer_writer_->Write(*out_buf_); 175 buffer_writer_->Write(*out_buf_);
123 } 176 }
124 177
125 if (residual_echo_likelihood_graph_writer_.is_open()) { 178 if (residual_echo_likelihood_graph_writer_.is_open()) {
126 auto stats = ap_->GetStatistics(); 179 auto stats = ap_->GetStatistics();
127 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood 180 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood
128 << ", "; 181 << ", ";
129 } 182 }
130 183
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 fwd_frame_.samples_per_channel_ = 241 fwd_frame_.samples_per_channel_ =
189 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); 242 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond);
190 fwd_frame_.num_channels_ = input_num_channels; 243 fwd_frame_.num_channels_ = input_num_channels;
191 244
192 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; 245 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz;
193 rev_frame_.samples_per_channel_ = 246 rev_frame_.samples_per_channel_ =
194 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); 247 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond);
195 rev_frame_.num_channels_ = reverse_input_num_channels; 248 rev_frame_.num_channels_ = reverse_input_num_channels;
196 249
197 if (settings_.use_verbose_logging) { 250 if (settings_.use_verbose_logging) {
251 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE);
252
198 std::cout << "Sample rates:" << std::endl; 253 std::cout << "Sample rates:" << std::endl;
199 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; 254 std::cout << " Forward input: " << input_sample_rate_hz << std::endl;
200 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; 255 std::cout << " Forward output: " << output_sample_rate_hz << std::endl;
201 std::cout << " Reverse input: " << reverse_input_sample_rate_hz 256 std::cout << " Reverse input: " << reverse_input_sample_rate_hz
202 << std::endl; 257 << std::endl;
203 std::cout << " Reverse output: " << reverse_output_sample_rate_hz 258 std::cout << " Reverse output: " << reverse_output_sample_rate_hz
204 << std::endl; 259 << std::endl;
205 std::cout << "Number of channels: " << std::endl; 260 std::cout << "Number of channels: " << std::endl;
206 std::cout << " Forward input: " << input_num_channels << std::endl; 261 std::cout << " Forward input: " << input_num_channels << std::endl;
207 std::cout << " Forward output: " << output_num_channels << std::endl; 262 std::cout << " Forward output: " << output_num_channels << std::endl;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } 445 }
391 446
392 if (settings_.aec_dump_output_filename) { 447 if (settings_.aec_dump_output_filename) {
393 ap_->AttachAecDump(AecDumpFactory::Create( 448 ap_->AttachAecDump(AecDumpFactory::Create(
394 *settings_.aec_dump_output_filename, -1, &worker_queue_)); 449 *settings_.aec_dump_output_filename, -1, &worker_queue_));
395 } 450 }
396 } 451 }
397 452
398 } // namespace test 453 } // namespace test
399 } // namespace webrtc 454 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698