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

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 Per. 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) {
hlundin-webrtc 2016/11/14 10:38:28 Non-const reference violates style guide.
ivoc 2016/11/14 12:32:39 Changed this into a pointer.
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(
hlundin-webrtc 2016/11/14 10:38:28 Can open() fail?
ivoc 2016/11/14 12:32:39 Good point, I added a check for this to avoid writ
84 *settings_.red_graph_output_filename);
85 WriteEchoLikelihoodGraphFileHeader(residual_echo_likelihood_graph_writer_);
86 }
87 }
65 88
66 AudioProcessingSimulator::~AudioProcessingSimulator() = default; 89 AudioProcessingSimulator::~AudioProcessingSimulator() {
90 if (residual_echo_likelihood_graph_writer_.is_open()) {
91 WriteEchoLikelihoodGraphFileFooter(residual_echo_likelihood_graph_writer_);
92 residual_echo_likelihood_graph_writer_.close();
93 }
94 }
67 95
68 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() { 96 AudioProcessingSimulator::ScopedTimer::~ScopedTimer() {
69 int64_t interval = rtc::TimeNanos() - start_time_; 97 int64_t interval = rtc::TimeNanos() - start_time_;
70 proc_time_->sum += interval; 98 proc_time_->sum += interval;
71 proc_time_->max = std::max(proc_time_->max, interval); 99 proc_time_->max = std::max(proc_time_->max, interval);
72 proc_time_->min = std::min(proc_time_->min, interval); 100 proc_time_->min = std::min(proc_time_->min, interval);
73 } 101 }
74 102
75 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) { 103 void AudioProcessingSimulator::ProcessStream(bool fixed_interface) {
76 if (fixed_interface) { 104 if (fixed_interface) {
77 { 105 {
78 const auto st = ScopedTimer(mutable_proc_time()); 106 const auto st = ScopedTimer(mutable_proc_time());
79 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_)); 107 RTC_CHECK_EQ(AudioProcessing::kNoError, ap_->ProcessStream(&fwd_frame_));
80 } 108 }
81 CopyFromAudioFrame(fwd_frame_, out_buf_.get()); 109 CopyFromAudioFrame(fwd_frame_, out_buf_.get());
82 } else { 110 } else {
83 const auto st = ScopedTimer(mutable_proc_time()); 111 const auto st = ScopedTimer(mutable_proc_time());
84 RTC_CHECK_EQ(AudioProcessing::kNoError, 112 RTC_CHECK_EQ(AudioProcessing::kNoError,
85 ap_->ProcessStream(in_buf_->channels(), in_config_, 113 ap_->ProcessStream(in_buf_->channels(), in_config_,
86 out_config_, out_buf_->channels())); 114 out_config_, out_buf_->channels()));
87 } 115 }
88 116
89 if (buffer_writer_) { 117 if (buffer_writer_) {
90 buffer_writer_->Write(*out_buf_); 118 buffer_writer_->Write(*out_buf_);
91 } 119 }
92 120
121 if (residual_echo_likelihood_graph_writer_.is_open()) {
122 auto stats = ap_->GetStatistics();
123 residual_echo_likelihood_graph_writer_ << stats.residual_echo_likelihood
124 << ", ";
125 }
126
93 ++num_process_stream_calls_; 127 ++num_process_stream_calls_;
94 } 128 }
95 129
96 void AudioProcessingSimulator::ProcessReverseStream(bool fixed_interface) { 130 void AudioProcessingSimulator::ProcessReverseStream(bool fixed_interface) {
97 if (fixed_interface) { 131 if (fixed_interface) {
98 const auto st = ScopedTimer(mutable_proc_time()); 132 const auto st = ScopedTimer(mutable_proc_time());
99 RTC_CHECK_EQ(AudioProcessing::kNoError, 133 RTC_CHECK_EQ(AudioProcessing::kNoError,
100 ap_->ProcessReverseStream(&rev_frame_)); 134 ap_->ProcessReverseStream(&rev_frame_));
101 CopyFromAudioFrame(rev_frame_, reverse_out_buf_.get()); 135 CopyFromAudioFrame(rev_frame_, reverse_out_buf_.get());
102 136
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 apm_config.level_controller.enabled = *settings_.use_lc; 272 apm_config.level_controller.enabled = *settings_.use_lc;
239 } 273 }
240 if (settings_.use_refined_adaptive_filter) { 274 if (settings_.use_refined_adaptive_filter) {
241 config.Set<RefinedAdaptiveFilter>( 275 config.Set<RefinedAdaptiveFilter>(
242 new RefinedAdaptiveFilter(*settings_.use_refined_adaptive_filter)); 276 new RefinedAdaptiveFilter(*settings_.use_refined_adaptive_filter));
243 } 277 }
244 config.Set<ExtendedFilter>(new ExtendedFilter( 278 config.Set<ExtendedFilter>(new ExtendedFilter(
245 !settings_.use_extended_filter || *settings_.use_extended_filter)); 279 !settings_.use_extended_filter || *settings_.use_extended_filter));
246 config.Set<DelayAgnostic>(new DelayAgnostic(!settings_.use_delay_agnostic || 280 config.Set<DelayAgnostic>(new DelayAgnostic(!settings_.use_delay_agnostic ||
247 *settings_.use_delay_agnostic)); 281 *settings_.use_delay_agnostic));
282 if (settings_.use_red) {
283 apm_config.residual_echo_detector.enabled = *settings_.use_red;
284 }
248 285
249 ap_.reset(AudioProcessing::Create(config)); 286 ap_.reset(AudioProcessing::Create(config));
250 RTC_CHECK(ap_); 287 RTC_CHECK(ap_);
251 288
252 ap_->ApplyConfig(apm_config); 289 ap_->ApplyConfig(apm_config);
253 290
254 if (settings_.use_aec) { 291 if (settings_.use_aec) {
255 RTC_CHECK_EQ(AudioProcessing::kNoError, 292 RTC_CHECK_EQ(AudioProcessing::kNoError,
256 ap_->echo_cancellation()->Enable(*settings_.use_aec)); 293 ap_->echo_cancellation()->Enable(*settings_.use_aec));
257 } 294 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize; 380 size_t kMaxFilenameSize = AudioProcessing::kMaxFilenameSize;
344 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize); 381 RTC_CHECK_LE(settings_.aec_dump_output_filename->size(), kMaxFilenameSize);
345 RTC_CHECK_EQ(AudioProcessing::kNoError, 382 RTC_CHECK_EQ(AudioProcessing::kNoError,
346 ap_->StartDebugRecording( 383 ap_->StartDebugRecording(
347 settings_.aec_dump_output_filename->c_str(), -1)); 384 settings_.aec_dump_output_filename->c_str(), -1));
348 } 385 }
349 } 386 }
350 387
351 } // namespace test 388 } // namespace test
352 } // namespace webrtc 389 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698