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/aec_dump/aec_dump_factory.h" | 24 #include "webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h" |
23 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 25 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
26 #include "webrtc/modules/audio_processing/test/fake_recording_device.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. |
33 std::vector<float> tmp(src.samples_per_channel_ * src.num_channels_); | 36 std::vector<float> tmp(src.samples_per_channel_ * src.num_channels_); |
(...skipping 39 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 fake_recording_device_( | |
88 settings.initial_mic_level, | |
89 settings_.simulate_mic_gain ? *settings.simulated_mic_kind : 0), | |
90 worker_queue_("file_writer_task_queue") { | |
84 if (settings_.ed_graph_output_filename && | 91 if (settings_.ed_graph_output_filename && |
85 settings_.ed_graph_output_filename->size() > 0) { | 92 settings_.ed_graph_output_filename->size() > 0) { |
86 residual_echo_likelihood_graph_writer_.open( | 93 residual_echo_likelihood_graph_writer_.open( |
87 *settings_.ed_graph_output_filename); | 94 *settings_.ed_graph_output_filename); |
88 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); | 95 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); |
89 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); | 96 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); |
90 } | 97 } |
91 } | 98 } |
92 | 99 |
93 AudioProcessingSimulator::~AudioProcessingSimulator() { | 100 AudioProcessingSimulator::~AudioProcessingSimulator() { |
94 if (residual_echo_likelihood_graph_writer_.is_open()) { | 101 if (residual_echo_likelihood_graph_writer_.is_open()) { |
95 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); | 102 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); |
96 residual_echo_likelihood_graph_writer_.close(); | 103 residual_echo_likelihood_graph_writer_.close(); |
97 } | 104 } |
98 } | 105 } |
99 | 106 |
100 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { | 107 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { |
101 int64_t interval = rtc::TimeNanos() - start_time_; | 108 int64_t interval = rtc::TimeNanos() - start_time_; |
102 proc_time_->sum += interval; | 109 proc_time_->sum += interval; |
103 proc_time_->max = std::max(proc_time_->max, interval); | 110 proc_time_->max = std::max(proc_time_->max, interval); |
104 proc_time_->min = std::min(proc_time_->min, interval); | 111 proc_time_->min = std::min(proc_time_->min, interval); |
105 } | 112 } |
106 | 113 |
107 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 (settings_.aec_dump_input_filename) { | |
118 // When the analog gain is sumulated and an AEC dump is used as input, set | |
peah-webrtc
2017/08/18 04:27:00
typo: sumulated
AleBzk
2017/08/18 07:49:46
Done.
| |
119 // the undo level to |aec_dump_mic_level_| to virtually restore the | |
120 // unmodified microphone signal level. | |
121 RTC_DCHECK(aec_dump_mic_level_); | |
122 fake_recording_device_.set_undo_mic_level(aec_dump_mic_level_); | |
123 } | |
124 | |
125 if (fixed_interface) { | |
126 fake_recording_device_.SimulateAnalogGain(&fwd_frame_); | |
127 } else { | |
128 fake_recording_device_.SimulateAnalogGain(in_buf_.get()); | |
129 } | |
130 | |
131 // Notify the current mic level to AGC. | |
132 RTC_CHECK_EQ(AudioProcessing::kNoError, | |
133 ap_->gain_control()->set_stream_analog_level( | |
peah-webrtc
2017/08/18 04:27:00
As discussed offline, set_stream_analog_level must
AleBzk
2017/08/18 07:49:46
Done.
| |
134 fake_recording_device_.mic_level())); | |
135 } | |
136 | |
137 // Process the current audio frame. | |
108 if (fixed_interface) { | 138 if (fixed_interface) { |
109 { | 139 { |
110 const auto st = ScopedTimer(mutable_proc_time()); | 140 const auto st = ScopedTimer(mutable_proc_time()); |
111 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); | 141 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); |
112 } | 142 } |
113 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); | 143 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); |
114 } else { | 144 } else { |
115 const auto st = ScopedTimer(mutable_proc_time()); | 145 const auto st = ScopedTimer(mutable_proc_time()); |
116 RTC_CHECK_EQ(AudioProcessing::kNoError, | 146 RTC_CHECK_EQ(AudioProcessing::kNoError, |
117 ap_->ProcessStream(in_buf_->channels(), in_config_, | 147 ap_->ProcessStream(in_buf_->channels(), in_config_, |
118 out_config_, out_buf_->channels())); | 148 out_config_, out_buf_->channels())); |
119 } | 149 } |
120 | 150 |
151 if (settings_.simulate_mic_gain) { | |
152 // Store the mic level suggested by AGC. | |
153 fake_recording_device_.set_mic_level( | |
154 ap_->gain_control()->stream_analog_level()); | |
155 } | |
AleBzk
2017/07/26 13:42:31
As you pointed out, fake_recording_device should o
| |
156 | |
121 if (buffer_writer_) { | 157 if (buffer_writer_) { |
122 buffer_writer_->Write(*out_buf_); | 158 buffer_writer_->Write(*out_buf_); |
123 } | 159 } |
124 | 160 |
125 if (residual_echo_likelihood_graph_writer_.is_open()) { | 161 if (residual_echo_likelihood_graph_writer_.is_open()) { |
126 auto stats = ap_->GetStatistics(); | 162 auto stats = ap_->GetStatistics(); |
127 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood | 163 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood |
128 << ", "; | 164 << ", "; |
129 } | 165 } |
130 | 166 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 fwd_frame_.samples_per_channel_ = | 224 fwd_frame_.samples_per_channel_ = |
189 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); | 225 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); |
190 fwd_frame_.num_channels_ = input_num_channels; | 226 fwd_frame_.num_channels_ = input_num_channels; |
191 | 227 |
192 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; | 228 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; |
193 rev_frame_.samples_per_channel_ = | 229 rev_frame_.samples_per_channel_ = |
194 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); | 230 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); |
195 rev_frame_.num_channels_ = reverse_input_num_channels; | 231 rev_frame_.num_channels_ = reverse_input_num_channels; |
196 | 232 |
197 if (settings_.use_verbose_logging) { | 233 if (settings_.use_verbose_logging) { |
234 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); | |
235 | |
198 std::cout << "Sample rates:" << std::endl; | 236 std::cout << "Sample rates:" << std::endl; |
199 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; | 237 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; |
200 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; | 238 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; |
201 std::cout << " Reverse input: " << reverse_input_sample_rate_hz | 239 std::cout << " Reverse input: " << reverse_input_sample_rate_hz |
202 << std::endl; | 240 << std::endl; |
203 std::cout << " Reverse output: " << reverse_output_sample_rate_hz | 241 std::cout << " Reverse output: " << reverse_output_sample_rate_hz |
204 << std::endl; | 242 << std::endl; |
205 std::cout << "Number of channels: " << std::endl; | 243 std::cout << "Number of channels: " << std::endl; |
206 std::cout << " Forward input: " << input_num_channels << std::endl; | 244 std::cout << " Forward input: " << input_num_channels << std::endl; |
207 std::cout << " Forward output: " << output_num_channels << std::endl; | 245 std::cout << " Forward output: " << output_num_channels << std::endl; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 } | 428 } |
391 | 429 |
392 if (settings_.aec_dump_output_filename) { | 430 if (settings_.aec_dump_output_filename) { |
393 ap_->AttachAecDump(AecDumpFactory::Create( | 431 ap_->AttachAecDump(AecDumpFactory::Create( |
394 *settings_.aec_dump_output_filename, -1, &worker_queue_)); | 432 *settings_.aec_dump_output_filename, -1, &worker_queue_)); |
395 } | 433 } |
396 } | 434 } |
397 | 435 |
398 } // namespace test | 436 } // namespace test |
399 } // namespace webrtc | 437 } // namespace webrtc |
OLD | NEW |