Chromium Code Reviews| 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 461fc71c5e16d272df8d7a23fb7d8e8eaba0a72f..9776d41745c65b55f661781ee0d55b4f9f5eb640 100644 |
| --- a/webrtc/modules/audio_processing/test/audio_processing_simulator.cc |
| +++ b/webrtc/modules/audio_processing/test/audio_processing_simulator.cc |
| @@ -14,12 +14,15 @@ |
| #include <iostream> |
| #include <sstream> |
| #include <string> |
| +#include <utility> |
| #include <vector> |
| #include "webrtc/common_audio/include/audio_util.h" |
| #include "webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h" |
| #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| +#include "webrtc/modules/audio_processing/test/fake_recording_device.h" |
| #include "webrtc/rtc_base/checks.h" |
| +#include "webrtc/rtc_base/logging.h" |
| #include "webrtc/rtc_base/stringutils.h" |
| namespace webrtc { |
| @@ -80,7 +83,12 @@ void CopyToAudioFrame(const ChannelBuffer<float>& src, AudioFrame* dest) { |
| AudioProcessingSimulator::AudioProcessingSimulator( |
| const SimulationSettings& settings) |
| - : settings_(settings), worker_queue_("file_writer_task_queue") { |
| + : settings_(settings), |
| + analog_mic_level_(settings.initial_mic_level), |
| + fake_recording_device_( |
| + settings.initial_mic_level, |
| + settings_.simulate_mic_gain ? *settings.simulated_mic_kind : 0), |
| + worker_queue_("file_writer_task_queue") { |
| if (settings_.ed_graph_output_filename && |
| settings_.ed_graph_output_filename->size() > 0) { |
| residual_echo_likelihood_graph_writer_.open( |
| @@ -105,6 +113,43 @@ 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 (settings_.aec_dump_input_filename) { |
| + // When the analog gain is simulated 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_.SetUndoMicLevel(aec_dump_mic_level_); |
| + } |
| + |
| + if (fixed_interface) { |
| + fake_recording_device_.SimulateAnalogGain(&fwd_frame_); |
| + } else { |
| + fake_recording_device_.SimulateAnalogGain(in_buf_.get()); |
| + } |
| + |
| + // Notify the current mic level to AGC. |
| + RTC_CHECK_EQ(AudioProcessing::kNoError, |
| + ap_->gain_control()->set_stream_analog_level( |
| + fake_recording_device_.MicLevel())); |
| + } else { |
| + // Notify the current mic level to AGC. |
| + if (settings_.aec_dump_input_filename) { |
| + // AEC dump case. |
| + RTC_DCHECK(aec_dump_mic_level_); |
| + RTC_CHECK_EQ( |
| + AudioProcessing::kNoError, |
| + ap_->gain_control()->set_stream_analog_level(*aec_dump_mic_level_)); |
| + } else { |
| + // Wav input file case. |
| + RTC_CHECK_EQ( |
| + AudioProcessing::kNoError, |
| + ap_->gain_control()->set_stream_analog_level(analog_mic_level_)); |
|
peah-webrtc
2017/09/15 09:36:20
What about bundling line 148 with 143 using a cond
AleBzk
2017/09/22 12:33:55
Done.
|
| + } |
| + } |
| + |
| + // Process the current audio frame. |
| if (fixed_interface) { |
| { |
| const auto st = ScopedTimer(mutable_proc_time()); |
| @@ -118,6 +163,14 @@ void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { |
| out_config_, out_buf_->channels())); |
| } |
| + // Store the mic level suggested by AGC. |
| + // Note that when the analog gain is simulated and an AEC dump is used as |
| + // input, |analog_mic_level_| will not be used with set_stream_analog_level(). |
| + analog_mic_level_ = ap_->gain_control()->stream_analog_level(); |
| + if (settings_.simulate_mic_gain) { |
| + fake_recording_device_.SetMicLevel(analog_mic_level_); |
| + } |
| + |
| if (buffer_writer_) { |
| buffer_writer_->Write(*out_buf_); |
| } |
| @@ -195,6 +248,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; |