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" |
| 25 #include "webrtc/modules/audio_processing/test/fake_recording_device.h" |
23 | 26 |
24 namespace webrtc { | 27 namespace webrtc { |
25 namespace test { | 28 namespace test { |
26 namespace { | 29 namespace { |
27 | 30 |
| 31 constexpr FakeRecordingDevice::DeviceKind kDefaultFakeRecDeviceKind = |
| 32 FakeRecordingDevice::DeviceKind::IDENTITY; |
| 33 |
28 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { | 34 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { |
29 RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); | 35 RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); |
30 RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames()); | 36 RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames()); |
31 // Copy the data from the input buffer. | 37 // Copy the data from the input buffer. |
32 std::vector<float> tmp(src.samples_per_channel_ * src.num_channels_); | 38 std::vector<float> tmp(src.samples_per_channel_ * src.num_channels_); |
33 S16ToFloat(src.data_, tmp.size(), tmp.data()); | 39 S16ToFloat(src.data_, tmp.size(), tmp.data()); |
34 Deinterleave(tmp.data(), src.samples_per_channel_, src.num_channels_, | 40 Deinterleave(tmp.data(), src.samples_per_channel_, src.num_channels_, |
35 dest->channels()); | 41 dest->channels()); |
36 } | 42 } |
37 | 43 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { | 77 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { |
72 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { | 78 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { |
73 dest->data_[sample * dest->num_channels_ + ch] = | 79 dest->data_[sample * dest->num_channels_ + ch] = |
74 src.channels()[ch][sample] * 32767; | 80 src.channels()[ch][sample] * 32767; |
75 } | 81 } |
76 } | 82 } |
77 } | 83 } |
78 | 84 |
79 AudioProcessingSimulator::AudioProcessingSimulator( | 85 AudioProcessingSimulator::AudioProcessingSimulator( |
80 const SimulationSettings& settings) | 86 const SimulationSettings& settings) |
81 : settings_(settings) { | 87 : settings_(settings), |
| 88 fake_recording_device_(FakeRecordingDevice::GetFakeRecDevice( |
| 89 settings_.simulate_mic_gain ? static_cast< |
| 90 FakeRecordingDevice::DeviceKind>(*settings.simulated_mic_kind) |
| 91 : kDefaultFakeRecDeviceKind, |
| 92 settings.initial_mic_level)) { |
| 93 RTC_DCHECK(fake_recording_device_); |
82 if (settings_.ed_graph_output_filename && | 94 if (settings_.ed_graph_output_filename && |
83 settings_.ed_graph_output_filename->size() > 0) { | 95 settings_.ed_graph_output_filename->size() > 0) { |
84 residual_echo_likelihood_graph_writer_.open( | 96 residual_echo_likelihood_graph_writer_.open( |
85 *settings_.ed_graph_output_filename); | 97 *settings_.ed_graph_output_filename); |
86 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); | 98 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); |
87 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); | 99 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); |
88 } | 100 } |
89 } | 101 } |
90 | 102 |
91 AudioProcessingSimulator::~AudioProcessingSimulator() { | 103 AudioProcessingSimulator::~AudioProcessingSimulator() { |
92 if (residual_echo_likelihood_graph_writer_.is_open()) { | 104 if (residual_echo_likelihood_graph_writer_.is_open()) { |
93 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); | 105 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); |
94 residual_echo_likelihood_graph_writer_.close(); | 106 residual_echo_likelihood_graph_writer_.close(); |
95 } | 107 } |
96 } | 108 } |
97 | 109 |
98 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { | 110 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { |
99 int64_t interval = rtc::TimeNanos() - start_time_; | 111 int64_t interval = rtc::TimeNanos() - start_time_; |
100 proc_time_->sum += interval; | 112 proc_time_->sum += interval; |
101 proc_time_->max = std::max(proc_time_->max, interval); | 113 proc_time_->max = std::max(proc_time_->max, interval); |
102 proc_time_->min = std::min(proc_time_->min, interval); | 114 proc_time_->min = std::min(proc_time_->min, interval); |
103 } | 115 } |
104 | 116 |
105 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { | 117 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { |
| 118 // Optionally use the fake recording device to simulate analog gain. |
| 119 RTC_DCHECK(fake_recording_device_); |
| 120 if (settings_.simulate_mic_gain) { |
| 121 if (fixed_interface) { |
| 122 fake_recording_device_->SimulateAnalogGain(&fwd_frame_); |
| 123 } else { |
| 124 fake_recording_device_->SimulateAnalogGain(in_buf_.get()); |
| 125 } |
| 126 } |
| 127 |
| 128 // Notify the current mic level to AGC. |
| 129 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 130 ap_->gain_control()->set_stream_analog_level( |
| 131 fake_recording_device_->mic_level())); |
| 132 |
| 133 // Process the current audio frame. |
106 if (fixed_interface) { | 134 if (fixed_interface) { |
107 { | 135 { |
108 const auto st = ScopedTimer(mutable_proc_time()); | 136 const auto st = ScopedTimer(mutable_proc_time()); |
109 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); | 137 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); |
110 } | 138 } |
111 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); | 139 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); |
112 } else { | 140 } else { |
113 const auto st = ScopedTimer(mutable_proc_time()); | 141 const auto st = ScopedTimer(mutable_proc_time()); |
114 RTC_CHECK_EQ(AudioProcessing::kNoError, | 142 RTC_CHECK_EQ(AudioProcessing::kNoError, |
115 ap_->ProcessStream(in_buf_->channels(), in_config_, | 143 ap_->ProcessStream(in_buf_->channels(), in_config_, |
116 out_config_, out_buf_->channels())); | 144 out_config_, out_buf_->channels())); |
117 } | 145 } |
118 | 146 |
| 147 // Store the mic level suggested by AGC if required. |
| 148 fake_recording_device_->set_mic_level( |
| 149 ap_->gain_control()->stream_analog_level()); |
| 150 |
119 if (buffer_writer_) { | 151 if (buffer_writer_) { |
120 buffer_writer_->Write(*out_buf_); | 152 buffer_writer_->Write(*out_buf_); |
121 } | 153 } |
122 | 154 |
123 if (residual_echo_likelihood_graph_writer_.is_open()) { | 155 if (residual_echo_likelihood_graph_writer_.is_open()) { |
124 auto stats = ap_->GetStatistics(); | 156 auto stats = ap_->GetStatistics(); |
125 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood | 157 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood |
126 << ", "; | 158 << ", "; |
127 } | 159 } |
128 | 160 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 fwd_frame_.samples_per_channel_ = | 218 fwd_frame_.samples_per_channel_ = |
187 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); | 219 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); |
188 fwd_frame_.num_channels_ = input_num_channels; | 220 fwd_frame_.num_channels_ = input_num_channels; |
189 | 221 |
190 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; | 222 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; |
191 rev_frame_.samples_per_channel_ = | 223 rev_frame_.samples_per_channel_ = |
192 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); | 224 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); |
193 rev_frame_.num_channels_ = reverse_input_num_channels; | 225 rev_frame_.num_channels_ = reverse_input_num_channels; |
194 | 226 |
195 if (settings_.use_verbose_logging) { | 227 if (settings_.use_verbose_logging) { |
| 228 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); |
| 229 |
196 std::cout << "Sample rates:" << std::endl; | 230 std::cout << "Sample rates:" << std::endl; |
197 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; | 231 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; |
198 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; | 232 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; |
199 std::cout << " Reverse input: " << reverse_input_sample_rate_hz | 233 std::cout << " Reverse input: " << reverse_input_sample_rate_hz |
200 << std::endl; | 234 << std::endl; |
201 std::cout << " Reverse output: " << reverse_output_sample_rate_hz | 235 std::cout << " Reverse output: " << reverse_output_sample_rate_hz |
202 << std::endl; | 236 << std::endl; |
203 std::cout << "Number of channels: " << std::endl; | 237 std::cout << "Number of channels: " << std::endl; |
204 std::cout << " Forward input: " << input_num_channels << std::endl; | 238 std::cout << " Forward input: " << input_num_channels << std::endl; |
205 std::cout << " Forward output: " << output_num_channels << std::endl; | 239 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; | 422 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize; |
389 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); | 423 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); |
390 RTC_CHECK_EQ(AudioProcessing::kNoError, | 424 RTC_CHECK_EQ(AudioProcessing::kNoError, |
391 ap_->StartDebugRecording( | 425 ap_->StartDebugRecording( |
392 settings_.aec_dump_output_filename->c_str(), -1)); | 426 settings_.aec_dump_output_filename->c_str(), -1)); |
393 } | 427 } |
394 } | 428 } |
395 | 429 |
396 } // namespace test | 430 } // namespace test |
397 } // namespace webrtc | 431 } // namespace webrtc |
OLD | NEW |