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

Unified Diff: webrtc/modules/audio_processing/test/audio_processing_simulator.cc

Issue 2834643002: audioproc_f with simulated mic analog gain (Closed)
Patch Set: fake rec device boilerplate reduced, aec dump simulated analog gain logic moved Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
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 58b47e221316191fb6f5c19004ba25576c83719b..9a42152ad40718a65de265904cbaaaa4f0b237bd 100644
--- a/webrtc/modules/audio_processing/test/audio_processing_simulator.cc
+++ b/webrtc/modules/audio_processing/test/audio_processing_simulator.cc
@@ -14,17 +14,23 @@
#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"
+#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());
@@ -79,7 +85,13 @@ void CopyToAudioFrame(const ChannelBuffer<float>& src, AudioFrame* dest) {
AudioProcessingSimulator::AudioProcessingSimulator(
const SimulationSettings& settings)
- : settings_(settings) {
+ : settings_(settings),
+ fake_recording_device_(new FakeRecordingDevice(
peah-webrtc 2017/06/29 05:45:27 You don't need to create this dynamically. Since y
AleBzk 2017/06/29 11:43:35 Thanks. I recalled why I added the member as a uni
+ settings.initial_mic_level,
+ settings_.simulate_mic_gain ? static_cast<
+ FakeRecordingDevice::DeviceKind>(*settings.simulated_mic_kind)
+ : kDefaultFakeRecDeviceKind)) {
+ RTC_DCHECK(fake_recording_device_);
if (settings_.ed_graph_output_filename &&
settings_.ed_graph_output_filename->size() > 0) {
residual_echo_likelihood_graph_writer_.open(
@@ -104,6 +116,37 @@ AudioProcessingSimulator::ScopedTimer::~ScopedTimer() {
}
void AudioProcessingSimulator::ProcessStream(bool fixed_interface) {
+ if (settings_.aec_dump_input_filename) {
+ RTC_DCHECK(aec_dump_mic_level_);
+ if (settings_.simulate_mic_gain) {
+ // 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.
+ fake_recording_device_->set_undo_mic_level(aec_dump_mic_level_);
+ } else {
+ // When the analog gain is not simulated, the AEC dump level must to be
+ // used to override the value set from the gain controller in the
+ // previously analyzed audio frame.
+ fake_recording_device_->set_mic_level(*aec_dump_mic_level_);
AleBzk 2017/06/22 10:16:01 Line 130 overrides what is set in lines 145-147.
peah-webrtc 2017/06/29 05:45:26 As I commented on a previous patch, I definitely d
AleBzk 2017/06/29 11:43:35 Thanks. Sorry for having kept this. It's up to us
+ }
+ }
AleBzk 2017/06/22 10:16:01 About lines 119-132: the AEC dump analog gain simu
+
+ // Optionally use the fake recording device to simulate analog gain.
+ RTC_DCHECK(fake_recording_device_);
+ if (settings_.simulate_mic_gain) {
+ if (fixed_interface) {
+ fake_recording_device_->SimulateAnalogGain(&fwd_frame_);
peah-webrtc 2017/06/29 05:45:26 Why not just add the optional aec_dump_mic_level_
AleBzk 2017/06/29 11:43:35 I'd prefer as it is now, otherwise we have to add
peah-webrtc 2017/06/29 22:03:59 I would personally prefer to have it as one single
+ } 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_->mic_level()));
peah-webrtc 2017/06/29 05:45:27 This is something that I think complicates the cod
AleBzk 2017/06/29 11:43:35 What happens during a call is that AGC suggests a
peah-webrtc 2017/06/29 22:03:59 You definitely need to pass the mic gain to the fa
+
+ // Process the current audio frame.
if (fixed_interface) {
{
const auto st = ScopedTimer(mutable_proc_time());
@@ -117,6 +160,10 @@ void AudioProcessingSimulator::ProcessStream(bool fixed_interface) {
out_config_, out_buf_->channels()));
}
+ // Store the mic level suggested by AGC if required.
peah-webrtc 2017/06/29 05:45:27 The comment "if required" seems out of place. Coul
AleBzk 2017/06/29 11:43:35 Done.
+ fake_recording_device_->set_mic_level(
+ ap_->gain_control()->stream_analog_level());
+
if (buffer_writer_) {
buffer_writer_->Write(*out_buf_);
}
@@ -194,6 +241,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;

Powered by Google App Engine
This is Rietveld 408576698