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

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

Issue 2562593003: Add an optional artificial nearend signal for aecdump call recreation (Closed)
Patch Set: Created 4 years 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 return false; 55 return false;
56 } 56 }
57 } 57 }
58 } 58 }
59 } 59 }
60 return true; 60 return true;
61 } 61 }
62 62
63 } // namespace 63 } // namespace
64 64
65 AecDumpBasedSimulator::AecDumpBasedSimulator(const SimulationSettings& settings)
66 : AudioProcessingSimulator(settings) {}
67
68 AecDumpBasedSimulator::~AecDumpBasedSimulator() = default;
69
65 void AecDumpBasedSimulator::PrepareProcessStreamCall( 70 void AecDumpBasedSimulator::PrepareProcessStreamCall(
66 const webrtc::audioproc::Stream& msg, 71 const webrtc::audioproc::Stream& msg,
67 bool* set_stream_analog_level_called) { 72 bool* set_stream_analog_level_called) {
68 if (msg.has_input_data()) { 73 if (msg.has_input_data()) {
69 // Fixed interface processing. 74 // Fixed interface processing.
70 // Verify interface invariance. 75 // Verify interface invariance.
71 RTC_CHECK(interface_used_ == InterfaceType::kFixedInterface || 76 RTC_CHECK(interface_used_ == InterfaceType::kFixedInterface ||
72 interface_used_ == InterfaceType::kNotSpecified); 77 interface_used_ == InterfaceType::kNotSpecified);
73 interface_used_ = InterfaceType::kFixedInterface; 78 interface_used_ = InterfaceType::kFixedInterface;
74 79
(...skipping 14 matching lines...) Expand all
89 94
90 // Populate input buffer. 95 // Populate input buffer.
91 for (int i = 0; i < msg.input_channel_size(); ++i) { 96 for (int i = 0; i < msg.input_channel_size(); ++i) {
92 RTC_CHECK_EQ(in_buf_->num_frames() * sizeof(*in_buf_->channels()[i]), 97 RTC_CHECK_EQ(in_buf_->num_frames() * sizeof(*in_buf_->channels()[i]),
93 msg.input_channel(i).size()); 98 msg.input_channel(i).size());
94 std::memcpy(in_buf_->channels()[i], msg.input_channel(i).data(), 99 std::memcpy(in_buf_->channels()[i], msg.input_channel(i).data(),
95 msg.input_channel(i).size()); 100 msg.input_channel(i).size());
96 } 101 }
97 } 102 }
98 103
104 if (artificial_nearend_buffer_reader_) {
105 bool samples_left_to_process =
106 artificial_nearend_buffer_reader_->Read(artificial_nearend_buf_.get());
107 if (samples_left_to_process) {
108 if (msg.has_input_data()) {
109 for (size_t k = 0; k < in_buf_->num_frames(); ++k) {
110 fwd_frame_.data_[0] += static_cast<int16_t>(
111 32767 * artificial_nearend_buf_->channels()[0][k]);
ivoc 2016/12/08 10:55:19 Shouldn't this be fwd_frame_.data[k]? Also, why is
peah-webrtc 2016/12/08 12:02:26 Great find (I probably have not used this yet with
ivoc 2016/12/08 12:13:24 I see, that makes sense. I think this code can cau
peah-webrtc 2016/12/09 07:19:25 You are fully correct! I added explicit controlled
112 }
113 } else {
114 for (int i = 0; i < msg.input_channel_size(); ++i) {
115 for (size_t k = 0; k < in_buf_->num_frames(); ++k) {
116 in_buf_->channels()[i][k] +=
117 artificial_nearend_buf_->channels()[0][k];
118 }
119 }
120 }
121 }
122 }
123
99 if (!settings_.stream_delay) { 124 if (!settings_.stream_delay) {
100 if (msg.has_delay()) { 125 if (msg.has_delay()) {
101 RTC_CHECK_EQ(AudioProcessing::kNoError, 126 RTC_CHECK_EQ(AudioProcessing::kNoError,
102 ap_->set_stream_delay_ms(msg.delay())); 127 ap_->set_stream_delay_ms(msg.delay()));
103 } 128 }
104 } else { 129 } else {
105 RTC_CHECK_EQ(AudioProcessing::kNoError, 130 RTC_CHECK_EQ(AudioProcessing::kNoError,
106 ap_->set_stream_delay_ms(*settings_.stream_delay)); 131 ap_->set_stream_delay_ms(*settings_.stream_delay));
107 } 132 }
108 133
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 207
183 void AecDumpBasedSimulator::Process() { 208 void AecDumpBasedSimulator::Process() {
184 std::unique_ptr<test::TraceToStderr> trace_to_stderr; 209 std::unique_ptr<test::TraceToStderr> trace_to_stderr;
185 if (settings_.use_verbose_logging) { 210 if (settings_.use_verbose_logging) {
186 trace_to_stderr.reset(new test::TraceToStderr(true)); 211 trace_to_stderr.reset(new test::TraceToStderr(true));
187 } 212 }
188 213
189 CreateAudioProcessor(); 214 CreateAudioProcessor();
190 dump_input_file_ = OpenFile(settings_.aec_dump_input_filename->c_str(), "rb"); 215 dump_input_file_ = OpenFile(settings_.aec_dump_input_filename->c_str(), "rb");
191 216
217 if (settings_.artificial_nearend_filename) {
218 std::unique_ptr<WavReader> artificial_nearend_file(
219 new WavReader(settings_.artificial_nearend_filename->c_str()));
220
221 if (artificial_nearend_file->num_channels() != 1) {
222 std::cout << "Only mono files for the artificial nearend are supported, "
223 "reverted to not using the artificial nearend file";
224 } else {
225 artificial_nearend_buffer_reader_.reset(
226 new ChannelBufferWavReader(std::move(artificial_nearend_file)));
227 }
228 }
229
192 webrtc::audioproc::Event event_msg; 230 webrtc::audioproc::Event event_msg;
193 int num_forward_chunks_processed = 0; 231 int num_forward_chunks_processed = 0;
194 const float kOneBykChunksPerSecond = 232 const float kOneBykChunksPerSecond =
195 1.f / AudioProcessingSimulator::kChunksPerSecond; 233 1.f / AudioProcessingSimulator::kChunksPerSecond;
196 while (ReadMessageFromFile(dump_input_file_, &event_msg)) { 234 while (ReadMessageFromFile(dump_input_file_, &event_msg)) {
197 switch (event_msg.type()) { 235 switch (event_msg.type()) {
198 case webrtc::audioproc::Event::INIT: 236 case webrtc::audioproc::Event::INIT:
199 RTC_CHECK(event_msg.has_init()); 237 RTC_CHECK(event_msg.has_init());
200 HandleMessage(event_msg.init()); 238 HandleMessage(event_msg.init());
201 break; 239 break;
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 564 }
527 565
528 void AecDumpBasedSimulator::HandleMessage( 566 void AecDumpBasedSimulator::HandleMessage(
529 const webrtc::audioproc::ReverseStream& msg) { 567 const webrtc::audioproc::ReverseStream& msg) {
530 PrepareReverseProcessStreamCall(msg); 568 PrepareReverseProcessStreamCall(msg);
531 ProcessReverseStream(interface_used_ == InterfaceType::kFixedInterface); 569 ProcessReverseStream(interface_used_ == InterfaceType::kFixedInterface);
532 } 570 }
533 571
534 } // namespace test 572 } // namespace test
535 } // namespace webrtc 573 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698