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

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

Powered by Google App Engine
This is Rietveld 408576698