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

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: Changes in response to reviewer comments 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 if (artificial_nearend_buffer_reader_->Read(
hlundin-webrtc 2016/12/09 07:48:26 If the file ends before the rest of the simulation
peah-webrtc 2016/12/09 08:07:51 The intention was actually to do this silently but
hlundin-webrtc 2016/12/09 09:24:26 Good.
106 artificial_nearend_buf_.get())) {
107 if (msg.has_input_data()) {
108 for (size_t k = 0; k < in_buf_->num_frames(); ++k) {
109 int32_t tmp = fwd_frame_.data_[k] +
110 static_cast<int16_t>(
111 32767 * artificial_nearend_buf_->channels()[0][k]);
112 fwd_frame_.data_[k] =
113 static_cast<int16_t>(std::min(32767, std::max(-32768, tmp)));
hlundin-webrtc 2016/12/09 07:48:26 rtc::saturated_cast<int16_t>(tmp) will do the same
peah-webrtc 2016/12/09 08:07:51 Great! That I did not know. Changed the code to us
114 }
115 } else {
116 for (int i = 0; i < msg.input_channel_size(); ++i) {
117 for (size_t k = 0; k < in_buf_->num_frames(); ++k) {
118 in_buf_->channels()[i][k] +=
119 artificial_nearend_buf_->channels()[0][k];
120 in_buf_->channels()[i][k] = std::min(
121 32767.f, std::max(-32768.f, in_buf_->channels()[i][k]));
122 }
123 }
124 }
125 }
126 }
127
99 if (!settings_.stream_delay) { 128 if (!settings_.stream_delay) {
100 if (msg.has_delay()) { 129 if (msg.has_delay()) {
101 RTC_CHECK_EQ(AudioProcessing::kNoError, 130 RTC_CHECK_EQ(AudioProcessing::kNoError,
102 ap_->set_stream_delay_ms(msg.delay())); 131 ap_->set_stream_delay_ms(msg.delay()));
103 } 132 }
104 } else { 133 } else {
105 RTC_CHECK_EQ(AudioProcessing::kNoError, 134 RTC_CHECK_EQ(AudioProcessing::kNoError,
106 ap_->set_stream_delay_ms(*settings_.stream_delay)); 135 ap_->set_stream_delay_ms(*settings_.stream_delay));
107 } 136 }
108 137
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 211
183 void AecDumpBasedSimulator::Process() { 212 void AecDumpBasedSimulator::Process() {
184 std::unique_ptr<test::TraceToStderr> trace_to_stderr; 213 std::unique_ptr<test::TraceToStderr> trace_to_stderr;
185 if (settings_.use_verbose_logging) { 214 if (settings_.use_verbose_logging) {
186 trace_to_stderr.reset(new test::TraceToStderr(true)); 215 trace_to_stderr.reset(new test::TraceToStderr(true));
187 } 216 }
188 217
189 CreateAudioProcessor(); 218 CreateAudioProcessor();
190 dump_input_file_ = OpenFile(settings_.aec_dump_input_filename->c_str(), "rb"); 219 dump_input_file_ = OpenFile(settings_.aec_dump_input_filename->c_str(), "rb");
191 220
221 if (settings_.artificial_nearend_filename) {
222 std::unique_ptr<WavReader> artificial_nearend_file(
223 new WavReader(settings_.artificial_nearend_filename->c_str()));
224
225 if (artificial_nearend_file->num_channels() != 1) {
hlundin-webrtc 2016/12/09 07:48:26 Any point continuing here? Or simply RTC_DCHECK_EQ
peah-webrtc 2016/12/09 08:07:51 Good point! I added the DCHECK. Done.
226 std::cout << "Only mono files for the artificial nearend are supported, "
227 "reverted to not using the artificial nearend file";
228 } else {
229 artificial_nearend_buffer_reader_.reset(
230 new ChannelBufferWavReader(std::move(artificial_nearend_file)));
231
232 artificial_nearend_buf_.reset(new ChannelBuffer<float>(
233 rtc::CheckedDivExact(artificial_nearend_file->sample_rate(),
234 kChunksPerSecond),
235 1));
236 }
237 }
238
192 webrtc::audioproc::Event event_msg; 239 webrtc::audioproc::Event event_msg;
193 int num_forward_chunks_processed = 0; 240 int num_forward_chunks_processed = 0;
194 const float kOneBykChunksPerSecond = 241 const float kOneBykChunksPerSecond =
195 1.f / AudioProcessingSimulator::kChunksPerSecond; 242 1.f / AudioProcessingSimulator::kChunksPerSecond;
196 while (ReadMessageFromFile(dump_input_file_, &event_msg)) { 243 while (ReadMessageFromFile(dump_input_file_, &event_msg)) {
197 switch (event_msg.type()) { 244 switch (event_msg.type()) {
198 case webrtc::audioproc::Event::INIT: 245 case webrtc::audioproc::Event::INIT:
199 RTC_CHECK(event_msg.has_init()); 246 RTC_CHECK(event_msg.has_init());
200 HandleMessage(event_msg.init()); 247 HandleMessage(event_msg.init());
201 break; 248 break;
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 573 }
527 574
528 void AecDumpBasedSimulator::HandleMessage( 575 void AecDumpBasedSimulator::HandleMessage(
529 const webrtc::audioproc::ReverseStream& msg) { 576 const webrtc::audioproc::ReverseStream& msg) {
530 PrepareReverseProcessStreamCall(msg); 577 PrepareReverseProcessStreamCall(msg);
531 ProcessReverseStream(interface_used_ == InterfaceType::kFixedInterface); 578 ProcessReverseStream(interface_used_ == InterfaceType::kFixedInterface);
532 } 579 }
533 580
534 } // namespace test 581 } // namespace test
535 } // namespace webrtc 582 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698