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 35e2d2c4d8c4e289105e9455f860932b83ad5ef4..f4737e69555bfa811dd305a97958675063622989 100644 |
--- a/webrtc/modules/audio_processing/test/audio_processing_simulator.cc |
+++ b/webrtc/modules/audio_processing/test/audio_processing_simulator.cc |
@@ -14,18 +14,24 @@ |
#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/aec_dump/aec_dump_factory.h" |
AleBzk
2017/06/29 11:43:36
Unrelated (merge)
|
#include "webrtc/modules/audio_processing/include/audio_processing.h" |
+#include "webrtc/modules/audio_processing/test/fake_recording_device.h" |
namespace webrtc { |
namespace test { |
namespace { |
+constexpr FakeRecordingDevice::DeviceKind kDefaultFakeRecDeviceKind = |
+ FakeRecordingDevice::DeviceKind::IDENTITY; |
+ |
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()); |
@@ -80,7 +86,13 @@ void CopyToAudioFrame(const ChannelBuffer<float>& src, AudioFrame* dest) { |
AudioProcessingSimulator::AudioProcessingSimulator( |
const SimulationSettings& settings) |
- : settings_(settings), worker_queue_("file_writer_task_queue") { |
+ : settings_(settings), |
+ fake_recording_device_(settings.initial_mic_level, |
+ settings_.simulate_mic_gain |
+ ? static_cast<FakeRecordingDevice::DeviceKind>( |
peah-webrtc
2017/06/29 22:04:00
I think you should move the selection of DeviceKin
AleBzk
2017/07/26 13:42:30
Done.
|
+ *settings.simulated_mic_kind) |
+ : kDefaultFakeRecDeviceKind), |
+ worker_queue_("file_writer_task_queue") { |
AleBzk
2017/06/29 11:43:36
last line is unrelated (merge)
|
if (settings_.ed_graph_output_filename && |
settings_.ed_graph_output_filename->size() > 0) { |
residual_echo_likelihood_graph_writer_.open( |
@@ -105,6 +117,31 @@ AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { |
} |
void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { |
+ if (settings_.aec_dump_input_filename && settings_.simulate_mic_gain) { |
peah-webrtc
2017/06/29 22:04:00
This is better, but I'd rephrase it as
if (sett
AleBzk
2017/07/26 13:42:30
Done.
|
+ // When the analog gain is sumulated and an AEC dump is used as input, set |
+ // the undo level to |aec_dump_mic_level_| to virtually restore the |
+ // unmodified microphone signal level. |
+ RTC_DCHECK(aec_dump_mic_level_); |
+ fake_recording_device_.set_undo_mic_level(aec_dump_mic_level_); |
+ } |
+ |
+ // Optionally use the fake recording device to simulate analog gain. |
+ if (settings_.simulate_mic_gain) { |
+ if (fixed_interface) { |
+ fake_recording_device_.SimulateAnalogGain(&fwd_frame_); |
+ } else { |
+ fake_recording_device_.SimulateAnalogGain(in_buf_.get()); |
+ } |
+ } |
+ |
+ // Notify the current mic level to AGC. |
+ if (settings_.simulate_mic_gain) { |
+ RTC_CHECK_EQ(AudioProcessing::kNoError, |
+ ap_->gain_control()->set_stream_analog_level( |
peah-webrtc
2017/06/29 22:04:00
No, I don't think this is ok. The fake recording d
AleBzk
2017/07/26 13:42:30
The code below is executed only when the mic gain
|
+ fake_recording_device_.mic_level())); |
+ } |
+ |
+ // Process the current audio frame. |
if (fixed_interface) { |
{ |
const auto st = ScopedTimer(mutable_proc_time()); |
@@ -118,6 +155,10 @@ void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { |
out_config_, out_buf_->channels())); |
} |
+ // Store the mic level suggested by AGC. |
+ fake_recording_device_.set_mic_level( |
+ ap_->gain_control()->stream_analog_level()); |
+ |
if (buffer_writer_) { |
buffer_writer_->Write(*out_buf_); |
} |
@@ -195,6 +236,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; |