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

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: comments addressed 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
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"
23 25
24 namespace webrtc { 26 namespace webrtc {
25 namespace test { 27 namespace test {
26 namespace { 28 namespace {
27 29
30 constexpr FakeRecordingDevice::MicrophoneKind kDefaultMicKind =
31 FakeRecordingDevice::MicrophoneKind::kIdentity;
32
28 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { 33 void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) {
29 RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); 34 RTC_CHECK_EQ(src.num_channels_, dest->num_channels());
30 RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames()); 35 RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames());
31 // Copy the data from the input buffer. 36 // Copy the data from the input buffer.
32 std::vector<float> tmp(src.samples_per_channel_ * src.num_channels_); 37 std::vector<float> tmp(src.samples_per_channel_ * src.num_channels_);
33 S16ToFloat(src.data_, tmp.size(), tmp.data()); 38 S16ToFloat(src.data_, tmp.size(), tmp.data());
34 Deinterleave(tmp.data(), src.samples_per_channel_, src.num_channels_, 39 Deinterleave(tmp.data(), src.samples_per_channel_, src.num_channels_,
35 dest->channels()); 40 dest->channels());
36 } 41 }
37 42
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { 76 for (size_t ch = 0; ch < dest->num_channels_; ++ch) {
72 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { 77 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) {
73 dest->data_[sample * dest->num_channels_ + ch] = 78 dest->data_[sample * dest->num_channels_ + ch] =
74 src.channels()[ch][sample] * 32767; 79 src.channels()[ch][sample] * 32767;
75 } 80 }
76 } 81 }
77 } 82 }
78 83
79 AudioProcessingSimulator::AudioProcessingSimulator( 84 AudioProcessingSimulator::AudioProcessingSimulator(
80 const SimulationSettings& settings) 85 const SimulationSettings& settings)
81 : settings_(settings) { 86 : settings_(settings),
87 new_analog_level_(settings.initial_mic_gain),
peah-webrtc 2017/05/16 12:19:35 There is a naming confusion between level and gain
AleBzk 2017/05/17 11:52:23 Right, i should have been consistent.
88 fake_recording_device_(settings_.simulate_mic_gain ?
89 static_cast<FakeRecordingDevice::MicrophoneKind>(
90 *settings.simulated_mic_kind) : kDefaultMicKind) {
82 if (settings_.ed_graph_output_filename && 91 if (settings_.ed_graph_output_filename &&
83 settings_.ed_graph_output_filename->size() > 0) { 92 settings_.ed_graph_output_filename->size() > 0) {
84 residual_echo_likelihood_graph_writer_.open( 93 residual_echo_likelihood_graph_writer_.open(
85 *settings_.ed_graph_output_filename); 94 *settings_.ed_graph_output_filename);
86 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open()); 95 RTC_CHECK(residual_echo_likelihood_graph_writer_.is_open());
87 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_); 96 WriteEchoLikelihoodGraphFileHeader(&residual_echo_likelihood_graph_writer_);
88 } 97 }
89 } 98 }
90 99
91 AudioProcessingSimulator::~AudioProcessingSimulator() { 100 AudioProcessingSimulator::~AudioProcessingSimulator() {
92 if (residual_echo_likelihood_graph_writer_.is_open()) { 101 if (residual_echo_likelihood_graph_writer_.is_open()) {
93 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_); 102 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_);
94 residual_echo_likelihood_graph_writer_.close(); 103 residual_echo_likelihood_graph_writer_.close();
95 } 104 }
96 } 105 }
97 106
98 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { 107 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() {
99 int64_t interval = rtc::TimeNanos() - start_time_; 108 int64_t interval = rtc::TimeNanos() - start_time_;
100 proc_time_->sum += interval; 109 proc_time_->sum += interval;
101 proc_time_->max = std::max(proc_time_->max, interval); 110 proc_time_->max = std::max(proc_time_->max, interval);
102 proc_time_->min = std::min(proc_time_->min, interval); 111 proc_time_->min = std::min(proc_time_->min, interval);
103 } 112 }
104 113
105 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 (fixed_interface) {
118 fake_recording_device_.SimulateAnalogGain(
119 new_analog_level_, real_recording_device_level_, &fwd_frame_);
120 } else {
121 // TODO(alessiob): Remove DCHECKs below once Per has reviewed.
122 RTC_DCHECK_EQ(in_config_.num_channels(), in_buf_->num_channels());
peah-webrtc 2017/05/16 12:19:35 Why are these DCHECK-s needed here now? There shou
AleBzk 2017/05/17 11:52:23 Sorry, I should have added a comment for you here
123 RTC_DCHECK_EQ(in_config_.num_frames(), in_buf_->num_frames());
124 fake_recording_device_.SimulateAnalogGain(
125 new_analog_level_, real_recording_device_level_, in_buf_.get());
126 }
127 }
128
129 // Notify the mic gain level to AGC.
peah-webrtc 2017/05/16 12:19:35 Both using gain and level here sounds like duplic
AleBzk 2017/05/17 11:52:23 Done.
130 RTC_CHECK_EQ(AudioProcessing::kNoError,
131 ap_->gain_control()->set_stream_analog_level(new_analog_level_));
peah-webrtc 2017/05/16 12:19:35 This is not correct I think. There is nothing in t
AleBzk 2017/05/17 11:52:23 I completely agree with this point. In fact, a use
peah-webrtc 2017/05/17 14:52:12 What I stated was that "I'd prefer a decoupling be
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 gain level suggested by AGC if required.
peah-webrtc 2017/05/16 12:19:35 Both using gain and level here sounds like duplic
AleBzk 2017/05/17 11:52:23 Right, thanks for the comment. I only left level.
148 new_analog_level_ = ap_->gain_control()->stream_analog_level();
149
119 if (buffer_writer_) { 150 if (buffer_writer_) {
120 buffer_writer_->Write(*out_buf_); 151 buffer_writer_->Write(*out_buf_);
121 } 152 }
122 153
123 if (residual_echo_likelihood_graph_writer_.is_open()) { 154 if (residual_echo_likelihood_graph_writer_.is_open()) {
124 auto stats = ap_->GetStatistics(); 155 auto stats = ap_->GetStatistics();
125 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood 156 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood
126 << ", "; 157 << ", ";
127 } 158 }
128 159
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 fwd_frame_.samples_per_channel_ = 217 fwd_frame_.samples_per_channel_ =
187 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond); 218 rtc::CheckedDivExact(fwd_frame_.sample_rate_hz_, kChunksPerSecond);
188 fwd_frame_.num_channels_ = input_num_channels; 219 fwd_frame_.num_channels_ = input_num_channels;
189 220
190 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz; 221 rev_frame_.sample_rate_hz_ = reverse_input_sample_rate_hz;
191 rev_frame_.samples_per_channel_ = 222 rev_frame_.samples_per_channel_ =
192 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond); 223 rtc::CheckedDivExact(rev_frame_.sample_rate_hz_, kChunksPerSecond);
193 rev_frame_.num_channels_ = reverse_input_num_channels; 224 rev_frame_.num_channels_ = reverse_input_num_channels;
194 225
195 if (settings_.use_verbose_logging) { 226 if (settings_.use_verbose_logging) {
227 rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE);
228
196 std::cout << "Sample rates:" << std::endl; 229 std::cout << "Sample rates:" << std::endl;
197 std::cout << " Forward input: " << input_sample_rate_hz << std::endl; 230 std::cout << " Forward input: " << input_sample_rate_hz << std::endl;
198 std::cout << " Forward output: " << output_sample_rate_hz << std::endl; 231 std::cout << " Forward output: " << output_sample_rate_hz << std::endl;
199 std::cout << " Reverse input: " << reverse_input_sample_rate_hz 232 std::cout << " Reverse input: " << reverse_input_sample_rate_hz
200 << std::endl; 233 << std::endl;
201 std::cout << " Reverse output: " << reverse_output_sample_rate_hz 234 std::cout << " Reverse output: " << reverse_output_sample_rate_hz
202 << std::endl; 235 << std::endl;
203 std::cout << "Number of channels: " << std::endl; 236 std::cout << "Number of channels: " << std::endl;
204 std::cout << " Forward input: " << input_num_channels << std::endl; 237 std::cout << " Forward input: " << input_num_channels << std::endl;
205 std::cout << " Forward output: " << output_num_channels << std::endl; 238 std::cout << " Forward output: " << output_num_channels << std::endl;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize; 421 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize;
389 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); 422 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize);
390 RTC_CHECK_EQ(AudioProcessing::kNoError, 423 RTC_CHECK_EQ(AudioProcessing::kNoError,
391 ap_->StartDebugRecording( 424 ap_->StartDebugRecording(
392 settings_.aec_dump_output_filename->c_str(), -1)); 425 settings_.aec_dump_output_filename->c_str(), -1));
393 } 426 }
394 } 427 }
395 428
396 } // namespace test 429 } // namespace test
397 } // namespace webrtc 430 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698