Index: webrtc/modules/audio_processing/test/audio_processing_simulator.cc |
diff --git a/webrtc/modules/audio_processing/test/audio_processing_simulator.cc b/webrtc/modules/audio_processing/test/audio_processing_simulator.cc |
index d2c274f460010af7976fc2a2f1032c8bb72ecc8a..e2df73b3a42eb9f04d8318c69ddc51e871e95ad9 100644 |
--- a/webrtc/modules/audio_processing/test/audio_processing_simulator.cc |
+++ b/webrtc/modules/audio_processing/test/audio_processing_simulator.cc |
@@ -14,9 +14,11 @@ |
#include <iostream> |
#include <sstream> |
#include <string> |
+#include <utility> |
#include <vector> |
#include "webrtc/base/checks.h" |
+#include "webrtc/base/logging.h" |
#include "webrtc/base/stringutils.h" |
#include "webrtc/common_audio/include/audio_util.h" |
#include "webrtc/modules/audio_processing/include/audio_processing.h" |
@@ -25,6 +27,9 @@ namespace webrtc { |
namespace test { |
namespace { |
+constexpr FakeRecordingDevice::LevelToScalingMappingKind kDefaultMicKind = |
+ FakeRecordingDevice::LevelToScalingMappingKind::kIdentity; |
+ |
void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer<float>* dest) { |
RTC_CHECK_EQ(src.num_channels_, dest->num_channels()); |
RTC_CHECK_EQ(src.samples_per_channel_, dest->num_frames()); |
@@ -78,7 +83,11 @@ void CopyToAudioFrame(const ChannelBuffer<float>& src, AudioFrame* dest) { |
AudioProcessingSimulator::AudioProcessingSimulator( |
const SimulationSettings& settings) |
- : settings_(settings) { |
+ : settings_(settings), |
+ last_specified_microphone_level_(settings.initial_mic_gain), |
+ fake_recording_device_(settings_.simulate_mic_gain ? |
+ static_cast<FakeRecordingDevice::LevelToScalingMappingKind>( |
+ *settings.simulated_mic_kind) : kDefaultMicKind) { |
if (settings_.ed_graph_output_filename && |
settings_.ed_graph_output_filename->size() > 0) { |
residual_echo_likelihood_graph_writer_.open( |
@@ -103,6 +112,36 @@ AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { |
} |
void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { |
+ // Optionally use the fake recording device to simulate analog gain. |
+ if (settings_.simulate_mic_gain) { |
+ if (fixed_interface) { |
+ fake_recording_device_.SimulateAnalogGain( |
+ &fwd_frame_, &fwd_frame_, last_specified_microphone_level_, |
+ real_recording_device_level_); |
+ } else { |
+ const size_t channel_size = in_config_.num_frames(); |
+ |
+ std::vector<rtc::ArrayView<const float>> data_view; |
peah-webrtc
2017/05/05 20:25:21
The lines 122-129 are only there to conform to the
AleBzk
2017/05/16 08:53:03
Done.
|
+ std::vector<rtc::ArrayView<float>> after_scaling_view; |
+ for (size_t i = 0; i < in_config_.num_channels(); ++i) { |
+ data_view.emplace_back(in_buf_->channels()[i], channel_size); |
+ after_scaling_view.emplace_back(in_buf_->channels()[i], channel_size); |
+ } |
+ |
+ fake_recording_device_.SimulateAnalogGain( |
+ data_view, after_scaling_view, last_specified_microphone_level_, |
+ real_recording_device_level_); |
+ } |
+ } |
+ |
+ // Notify the mic gain level to AGC. |
+ LOG(LS_VERBOSE) << "AGC set_stream_analog_level set to " |
+ << last_specified_microphone_level_; |
+ RTC_CHECK_EQ(AudioProcessing::kNoError, |
+ ap_->gain_control()->set_stream_analog_level( |
+ last_specified_microphone_level_)); |
+ |
+ // Process the current audio frame. |
if (fixed_interface) { |
{ |
const auto st = ScopedTimer(mutable_proc_time()); |
@@ -116,14 +155,17 @@ void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { |
out_config_, out_buf_->channels())); |
} |
+ // Store the mic gain level suggested by AGC if required. |
+ last_specified_microphone_level_ = ap_->gain_control()->stream_analog_level(); |
peah-webrtc
2017/05/05 20:25:21
With the changes done in this CL, I think last_spe
AleBzk
2017/05/16 08:53:03
Done.
|
+ |
if (buffer_writer_) { |
buffer_writer_->Write(*out_buf_); |
} |
if (residual_echo_likelihood_graph_writer_.is_open()) { |
auto stats = ap_->GetStatistics(); |
- residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood |
- << ", "; |
+ residual_echo_likelihood_graph_writer_ |
+ << stats.residual_echo_likelihood << ", "; |
peah-webrtc
2017/05/05 20:25:21
Unrelated change?
AleBzk
2017/05/16 08:53:03
yup, sorry. I switched back.
|
} |
++num_process_stream_calls_; |
@@ -193,6 +235,8 @@ void AudioProcessingSimulator::SetupBuffersConfigsOutputs( |
rev_frame_.num_channels_ = reverse_input_num_channels; |
if (settings_.use_verbose_logging) { |
+ rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); |
+ |
std::cout << "Sample rates:" << std::endl; |
std::cout << " Forward input: " << input_sample_rate_hz << std::endl; |
std::cout << " Forward output: " << output_sample_rate_hz << std::endl; |