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

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(
106 artificial_nearend_buf_.get())) {
107 if (msg.has_input_data()) {
108 for (size_t k = 0; k < in_buf_->num_frames(); ++k) {
109 fwd_frame_.data_[k] = rtc::saturated_cast<int16_t>(
110 fwd_frame_.data_[k] +
111 static_cast<int16_t>(32767 *
112 artificial_nearend_buf_->channels()[0][k]));
113 }
114 } else {
115 for (int i = 0; i < msg.input_channel_size(); ++i) {
116 for (size_t k = 0; k < in_buf_->num_frames(); ++k) {
117 in_buf_->channels()[i][k] +=
118 artificial_nearend_buf_->channels()[0][k];
119 in_buf_->channels()[i][k] = std::min(
120 32767.f, std::max(-32768.f, in_buf_->channels()[i][k]));
121 }
122 }
123 }
124 } else {
125 if (!artificial_nearend_eof_reported_) {
126 std::cout << "The artificial nearend file ended before the recording.";
127 artificial_nearend_eof_reported_ = true;
128 }
129 }
130 }
131
99 if (!settings_.stream_delay) { 132 if (!settings_.stream_delay) {
100 if (msg.has_delay()) { 133 if (msg.has_delay()) {
101 RTC_CHECK_EQ(AudioProcessing::kNoError, 134 RTC_CHECK_EQ(AudioProcessing::kNoError,
102 ap_->set_stream_delay_ms(msg.delay())); 135 ap_->set_stream_delay_ms(msg.delay()));
103 } 136 }
104 } else { 137 } else {
105 RTC_CHECK_EQ(AudioProcessing::kNoError, 138 RTC_CHECK_EQ(AudioProcessing::kNoError,
106 ap_->set_stream_delay_ms(*settings_.stream_delay)); 139 ap_->set_stream_delay_ms(*settings_.stream_delay));
107 } 140 }
108 141
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 215
183 void AecDumpBasedSimulator::Process() { 216 void AecDumpBasedSimulator::Process() {
184 std::unique_ptr<test::TraceToStderr> trace_to_stderr; 217 std::unique_ptr<test::TraceToStderr> trace_to_stderr;
185 if (settings_.use_verbose_logging) { 218 if (settings_.use_verbose_logging) {
186 trace_to_stderr.reset(new test::TraceToStderr(true)); 219 trace_to_stderr.reset(new test::TraceToStderr(true));
187 } 220 }
188 221
189 CreateAudioProcessor(); 222 CreateAudioProcessor();
190 dump_input_file_ = OpenFile(settings_.aec_dump_input_filename->c_str(), "rb"); 223 dump_input_file_ = OpenFile(settings_.aec_dump_input_filename->c_str(), "rb");
191 224
225 if (settings_.artificial_nearend_filename) {
226 std::unique_ptr<WavReader> artificial_nearend_file(
227 new WavReader(settings_.artificial_nearend_filename->c_str()));
228
229 if (artificial_nearend_file->num_channels() != 1) {
230 std::cout << "Only mono files for the artificial nearend are supported, "
231 "reverted to not using the artificial nearend file";
232 RTC_DCHECK_EQ(1, artificial_nearend_file->num_channels());
hlundin-webrtc 2016/12/09 09:24:26 Sorry, I mean to write CHECK, not DCHECK. I think
peah-webrtc 2016/12/09 10:14:10 Done.
233 } else {
234 artificial_nearend_buffer_reader_.reset(
235 new ChannelBufferWavReader(std::move(artificial_nearend_file)));
236
237 artificial_nearend_buf_.reset(new ChannelBuffer<float>(
238 rtc::CheckedDivExact(artificial_nearend_file->sample_rate(),
239 kChunksPerSecond),
240 1));
241 }
242 }
243
192 webrtc::audioproc::Event event_msg; 244 webrtc::audioproc::Event event_msg;
193 int num_forward_chunks_processed = 0; 245 int num_forward_chunks_processed = 0;
194 const float kOneBykChunksPerSecond = 246 const float kOneBykChunksPerSecond =
195 1.f / AudioProcessingSimulator::kChunksPerSecond; 247 1.f / AudioProcessingSimulator::kChunksPerSecond;
196 while (ReadMessageFromFile(dump_input_file_, &event_msg)) { 248 while (ReadMessageFromFile(dump_input_file_, &event_msg)) {
197 switch (event_msg.type()) { 249 switch (event_msg.type()) {
198 case webrtc::audioproc::Event::INIT: 250 case webrtc::audioproc::Event::INIT:
199 RTC_CHECK(event_msg.has_init()); 251 RTC_CHECK(event_msg.has_init());
200 HandleMessage(event_msg.init()); 252 HandleMessage(event_msg.init());
201 break; 253 break;
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 578 }
527 579
528 void AecDumpBasedSimulator::HandleMessage( 580 void AecDumpBasedSimulator::HandleMessage(
529 const webrtc::audioproc::ReverseStream& msg) { 581 const webrtc::audioproc::ReverseStream& msg) {
530 PrepareReverseProcessStreamCall(msg); 582 PrepareReverseProcessStreamCall(msg);
531 ProcessReverseStream(interface_used_ == InterfaceType::kFixedInterface); 583 ProcessReverseStream(interface_used_ == InterfaceType::kFixedInterface);
532 } 584 }
533 585
534 } // namespace test 586 } // namespace test
535 } // namespace webrtc 587 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698