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

Side by Side Diff: webrtc/modules/audio_processing/test/audio_processing_simulator.cc

Issue 2486763002: Add support to audioproc_f for running the residual echo detector and producing an echo likelihood … (Closed)
Patch Set: Review comments by Henrik. Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 36
37 std::string GetIndexedOutputWavFilename(const std::string& wav_name, 37 std::string GetIndexedOutputWavFilename(const std::string& wav_name,
38 int counter) { 38 int counter) {
39 std::stringstream ss; 39 std::stringstream ss;
40 ss << wav_name.substr(0, wav_name.size() - 4) << "_" << counter 40 ss << wav_name.substr(0, wav_name.size() - 4) << "_" << counter
41 << wav_name.substr(wav_name.size() - 4); 41 << wav_name.substr(wav_name.size() - 4);
42 return ss.str(); 42 return ss.str();
43 } 43 }
44 44
45 void WriteEchoLikelihoodGraphFileHeader(std::ofstream* output_file) {
46 (*output_file) << "import numpy as np" << std::endl
47 << "import matplotlib.pyplot as plt" << std::endl
48 << "y = np.array([";
49 }
50
51 void WriteEchoLikelihoodGraphFileFooter(std::ofstream* output_file) {
52 (*output_file) << "])" << std::endl
53 << "x = np.arange(len(y))*.01" << std::endl
54 << "plt.plot(x, y)" << std::endl
55 << "plt.ylabel('Echo likelihood')" << std::endl
56 << "plt.xlabel('Time (s)')" << std::endl
57 << "plt.ylim([0,1])" << std::endl
58 << "plt.show()" << std::endl;
59 }
60
45 } // namespace 61 } // namespace
46 62
47 SimulationSettings::SimulationSettings() = default; 63 SimulationSettings::SimulationSettings() = default;
48 SimulationSettings::SimulationSettings(const SimulationSettings&) = default; 64 SimulationSettings::SimulationSettings(const SimulationSettings&) = default;
49 SimulationSettings::~SimulationSettings() = default; 65 SimulationSettings::~SimulationSettings() = default;
50 66
51 void CopyToAudioFrame(const ChannelBuffer<float>& src, AudioFrame* dest) { 67 void CopyToAudioFrame(const ChannelBuffer<float>& src, AudioFrame* dest) {
52 RTC_CHECK_EQ(src.num_channels(), dest->num_channels_); 68 RTC_CHECK_EQ(src.num_channels(), dest->num_channels_);
53 RTC_CHECK_EQ(src.num_frames(), dest->samples_per_channel_); 69 RTC_CHECK_EQ(src.num_frames(), dest->samples_per_channel_);
54 for (size_t ch = 0; ch < dest->num_channels_; ++ch) { 70 for (size_t ch = 0; ch < dest->num_channels_; ++ch) {
55 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) { 71 for (size_t sample = 0; sample < dest->samples_per_channel_; ++sample) {
56 dest->data_[sample * dest->num_channels_ + ch] = 72 dest->data_[sample * dest->num_channels_ + ch] =
57 src.channels()[ch][sample] * 32767; 73 src.channels()[ch][sample] * 32767;
58 } 74 }
59 } 75 }
60 } 76 }
61 77
62 AudioProcessingSimulator::AudioProcessingSimulator( 78 AudioProcessingSimulator::AudioProcessingSimulator(
63 const SimulationSettings& settings) 79 const SimulationSettings& settings)
64 : settings_(settings) {} 80 : settings_(settings) {
81 if (settings_.red_graph_output_filename &&
82 settings_.red_graph_output_filename->size() > 0) {
83 residual_echo_likelihood_graph_writer_.open(
84 *settings_.red_graph_output_filename);
85 if (residual_echo_likelihood_graph_writer_.is_open()) {
hlundin-webrtc 2016/11/14 12:57:35 Since this is test code, I would argue that you sh
ivoc 2016/11/14 13:27:42 Good point, I changed this into an RTC_CHECK().
86 WriteEchoLikelihoodGraphFileHeader(
87 &residual_echo_likelihood_graph_writer_);
88 }
89 }
90 }
65 91
66 AudioProcessingSimulator::~AudioProcessingSimulator() = default; 92 AudioProcessingSimulator::~AudioProcessingSimulator() {
93 if (residual_echo_likelihood_graph_writer_.is_open()) {
94 WriteEchoLikelihoodGraphFileFooter(&residual_echo_likelihood_graph_writer_);
95 residual_echo_likelihood_graph_writer_.close();
96 }
97 }
67 98
68 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { 99 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() {
69 int64_t interval = rtc::TimeNanos() - start_time_; 100 int64_t interval = rtc::TimeNanos() - start_time_;
70 proc_time_->sum += interval; 101 proc_time_->sum += interval;
71 proc_time_->max = std::max(proc_time_->max, interval); 102 proc_time_->max = std::max(proc_time_->max, interval);
72 proc_time_->min = std::min(proc_time_->min, interval); 103 proc_time_->min = std::min(proc_time_->min, interval);
73 } 104 }
74 105
75 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { 106 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) {
76 if (fixed_interface) { 107 if (fixed_interface) {
77 { 108 {
78 const auto st = ScopedTimer(mutable_proc_time()); 109 const auto st = ScopedTimer(mutable_proc_time());
79 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); 110 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_));
80 } 111 }
81 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); 112 CopyFromAudioFrame(fwd_frame_, out_buf_.get());
82 } else { 113 } else {
83 const auto st = ScopedTimer(mutable_proc_time()); 114 const auto st = ScopedTimer(mutable_proc_time());
84 RTC_CHECK_EQ(AudioProcessing::kNoError, 115 RTC_CHECK_EQ(AudioProcessing::kNoError,
85 ap_->ProcessStream(in_buf_->channels(), in_config_, 116 ap_->ProcessStream(in_buf_->channels(), in_config_,
86 out_config_, out_buf_->channels())); 117 out_config_, out_buf_->channels()));
87 } 118 }
88 119
89 if (buffer_writer_) { 120 if (buffer_writer_) {
90 buffer_writer_->Write(*out_buf_); 121 buffer_writer_->Write(*out_buf_);
91 } 122 }
92 123
124 if (residual_echo_likelihood_graph_writer_.is_open()) {
125 auto stats = ap_->GetStatistics();
126 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood
127 << ", ";
128 }
129
93 ++num_process_stream_calls_; 130 ++num_process_stream_calls_;
94 } 131 }
95 132
96 void AudioProcessingSimulator::ProcessReverseStream(bool fixed_interface) { 133 void AudioProcessingSimulator::ProcessReverseStream(bool fixed_interface) {
97 if (fixed_interface) { 134 if (fixed_interface) {
98 const auto st = ScopedTimer(mutable_proc_time()); 135 const auto st = ScopedTimer(mutable_proc_time());
99 RTC_CHECK_EQ(AudioProcessing::kNoError, 136 RTC_CHECK_EQ(AudioProcessing::kNoError,
100 ap_->ProcessReverseStream(&rev_frame_)); 137 ap_->ProcessReverseStream(&rev_frame_));
101 CopyFromAudioFrame(rev_frame_, reverse_out_buf_.get()); 138 CopyFromAudioFrame(rev_frame_, reverse_out_buf_.get());
102 139
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 apm_config.level_controller.enabled = *settings_.use_lc; 275 apm_config.level_controller.enabled = *settings_.use_lc;
239 } 276 }
240 if (settings_.use_refined_adaptive_filter) { 277 if (settings_.use_refined_adaptive_filter) {
241 config.Set<RefinedAdaptiveFilter>( 278 config.Set<RefinedAdaptiveFilter>(
242 new RefinedAdaptiveFilter(*settings_.use_refined_adaptive_filter)); 279 new RefinedAdaptiveFilter(*settings_.use_refined_adaptive_filter));
243 } 280 }
244 config.Set<ExtendedFilter>(new ExtendedFilter( 281 config.Set<ExtendedFilter>(new ExtendedFilter(
245 !settings_.use_extended_filter || *settings_.use_extended_filter)); 282 !settings_.use_extended_filter || *settings_.use_extended_filter));
246 config.Set<DelayAgnostic>(new DelayAgnostic(!settings_.use_delay_agnostic || 283 config.Set<DelayAgnostic>(new DelayAgnostic(!settings_.use_delay_agnostic ||
247 *settings_.use_delay_agnostic)); 284 *settings_.use_delay_agnostic));
285 if (settings_.use_red) {
286 apm_config.residual_echo_detector.enabled = *settings_.use_red;
287 }
248 288
249 ap_.reset(AudioProcessing::Create(config)); 289 ap_.reset(AudioProcessing::Create(config));
250 RTC_CHECK(ap_); 290 RTC_CHECK(ap_);
251 291
252 ap_->ApplyConfig(apm_config); 292 ap_->ApplyConfig(apm_config);
253 293
254 if (settings_.use_aec) { 294 if (settings_.use_aec) {
255 RTC_CHECK_EQ(AudioProcessing::kNoError, 295 RTC_CHECK_EQ(AudioProcessing::kNoError,
256 ap_->echo_cancellation()->Enable(*settings_.use_aec)); 296 ap_->echo_cancellation()->Enable(*settings_.use_aec));
257 } 297 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize; 383 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize;
344 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); 384 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize);
345 RTC_CHECK_EQ(AudioProcessing::kNoError, 385 RTC_CHECK_EQ(AudioProcessing::kNoError,
346 ap_->StartDebugRecording( 386 ap_->StartDebugRecording(
347 settings_.aec_dump_output_filename->c_str(), -1)); 387 settings_.aec_dump_output_filename->c_str(), -1));
348 } 388 }
349 } 389 }
350 390
351 } // namespace test 391 } // namespace test
352 } // namespace webrtc 392 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698