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/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 Loading... |
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 sumulated 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 analog_mic_level_ = fake_recording_device_.MicLevel(); |
| 133 } |
| 134 |
| 135 // Notify the current mic level to AGC. |
| 136 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 137 ap_->gain_control()->set_stream_analog_level(analog_mic_level_)); |
| 138 |
| 139 // Process the current audio frame. |
108 if (fixed_interface) { | 140 if (fixed_interface) { |
109 { | 141 { |
110 const auto st = ScopedTimer(mutable_proc_time()); | 142 const auto st = ScopedTimer(mutable_proc_time()); |
111 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); | 143 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); |
112 } | 144 } |
113 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); | 145 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); |
114 } else { | 146 } else { |
115 const auto st = ScopedTimer(mutable_proc_time()); | 147 const auto st = ScopedTimer(mutable_proc_time()); |
116 RTC_CHECK_EQ(AudioProcessing::kNoError, | 148 RTC_CHECK_EQ(AudioProcessing::kNoError, |
117 ap_->ProcessStream(in_buf_->channels(), in_config_, | 149 ap_->ProcessStream(in_buf_->channels(), in_config_, |
118 out_config_, out_buf_->channels())); | 150 out_config_, out_buf_->channels())); |
119 } | 151 } |
120 | 152 |
| 153 // Store the mic level suggested by AGC. |
| 154 analog_mic_level_ = ap_->gain_control()->stream_analog_level(); |
| 155 if (settings_.simulate_mic_gain) { |
| 156 fake_recording_device_.SetMicLevel(analog_mic_level_); |
| 157 } |
| 158 |
121 if (buffer_writer_) { | 159 if (buffer_writer_) { |
122 buffer_writer_->Write(*out_buf_); | 160 buffer_writer_->Write(*out_buf_); |
123 } | 161 } |
124 | 162 |
125 if (residual_echo_likelihood_graph_writer_.is_open()) { | 163 if (residual_echo_likelihood_graph_writer_.is_open()) { |
126 auto stats = ap_->GetStatistics(); | 164 auto stats = ap_->GetStatistics(); |
127 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood | 165 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood |
128 << ", "; | 166 << ", "; |
129 } | 167 } |
130 | 168 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 fwd_frame_.samples_per_channel_ = | 226 fwd_frame_.samples_per_channel_ = |
189 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); | 227 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); |
190 fwd_frame_.num_channels_ = input_num_channels; | 228 fwd_frame_.num_channels_ = input_num_channels; |
191 | 229 |
192 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; | 230 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; |
193 rev_frame_.samples_per_channel_ = | 231 rev_frame_.samples_per_channel_ = |
194 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); | 232 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); |
195 rev_frame_.num_channels_ = reverse_input_num_channels; | 233 rev_frame_.num_channels_ = reverse_input_num_channels; |
196 | 234 |
197 if (settings_.use_verbose_logging) { | 235 if (settings_.use_verbose_logging) { |
| 236 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); |
| 237 |
198 std::cout << "Sample rates:" << std::endl; | 238 std::cout << "Sample rates:" << std::endl; |
199 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; | 239 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; |
200 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; | 240 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; |
201 std::cout << " Reverse input: " << reverse_input_sample_rate_hz | 241 std::cout << " Reverse input: " << reverse_input_sample_rate_hz |
202 << std::endl; | 242 << std::endl; |
203 std::cout << " Reverse output: " << reverse_output_sample_rate_hz | 243 std::cout << " Reverse output: " << reverse_output_sample_rate_hz |
204 << std::endl; | 244 << std::endl; |
205 std::cout << "Number of channels: " << std::endl; | 245 std::cout << "Number of channels: " << std::endl; |
206 std::cout << " Forward input: " << input_num_channels << std::endl; | 246 std::cout << " Forward input: " << input_num_channels << std::endl; |
207 std::cout << " Forward output: " << output_num_channels << std::endl; | 247 std::cout << " Forward output: " << output_num_channels << std::endl; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 } | 430 } |
391 | 431 |
392 if (settings_.aec_dump_output_filename) { | 432 if (settings_.aec_dump_output_filename) { |
393 ap_->AttachAecDump(AecDumpFactory::Create( | 433 ap_->AttachAecDump(AecDumpFactory::Create( |
394 *settings_.aec_dump_output_filename, -1, &worker_queue_)); | 434 *settings_.aec_dump_output_filename, -1, &worker_queue_)); |
395 } | 435 } |
396 } | 436 } |
397 | 437 |
398 } // namespace test | 438 } // namespace test |
399 } // namespace webrtc | 439 } // namespace webrtc |
OLD | NEW |