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..b049115a29e5ecd29e814722927d28a7fd440ef3 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::MicrophoneKind kDefaultMicKind = |
+ FakeRecordingDevice::MicrophoneKind::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), |
+ 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.
|
+ fake_recording_device_(settings_.simulate_mic_gain ? |
+ static_cast<FakeRecordingDevice::MicrophoneKind>( |
+ *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,25 @@ 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( |
+ new_analog_level_, real_recording_device_level_, &fwd_frame_); |
+ } else { |
+ // TODO(alessiob): Remove DCHECKs below once Per has reviewed. |
+ 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
|
+ RTC_DCHECK_EQ(in_config_.num_frames(), in_buf_->num_frames()); |
+ fake_recording_device_.SimulateAnalogGain( |
+ new_analog_level_, real_recording_device_level_, in_buf_.get()); |
+ } |
+ } |
+ |
+ // 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.
|
+ RTC_CHECK_EQ(AudioProcessing::kNoError, |
+ 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
|
+ |
+ // Process the current audio frame. |
if (fixed_interface) { |
{ |
const auto st = ScopedTimer(mutable_proc_time()); |
@@ -116,6 +144,9 @@ void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { |
out_config_, out_buf_->channels())); |
} |
+ // 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.
|
+ new_analog_level_ = ap_->gain_control()->stream_analog_level(); |
+ |
if (buffer_writer_) { |
buffer_writer_->Write(*out_buf_); |
} |
@@ -193,6 +224,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; |