OLD | NEW |
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 #include "webrtc/modules/audio_processing/aec3/echo_canceller3.h" | 10 #include "webrtc/modules/audio_processing/aec3/echo_canceller3.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 RTC_DCHECK_GE(1, sub_frame_index); | 46 RTC_DCHECK_GE(1, sub_frame_index); |
47 RTC_DCHECK_EQ(frame->size(), sub_frame_view->size()); | 47 RTC_DCHECK_EQ(frame->size(), sub_frame_view->size()); |
48 for (size_t k = 0; k < frame->size(); ++k) { | 48 for (size_t k = 0; k < frame->size(); ++k) { |
49 (*sub_frame_view)[k] = rtc::ArrayView<float>( | 49 (*sub_frame_view)[k] = rtc::ArrayView<float>( |
50 &(*frame)[k][sub_frame_index * kSubFrameLength], kSubFrameLength); | 50 &(*frame)[k][sub_frame_index * kSubFrameLength], kSubFrameLength); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 void ProcessCaptureFrameContent( | 54 void ProcessCaptureFrameContent( |
55 AudioBuffer* capture, | 55 AudioBuffer* capture, |
56 bool known_echo_path_change, | 56 bool level_change, |
57 bool saturated_microphone_signal, | 57 bool saturated_microphone_signal, |
58 size_t sub_frame_index, | 58 size_t sub_frame_index, |
59 FrameBlocker* capture_blocker, | 59 FrameBlocker* capture_blocker, |
60 BlockFramer* output_framer, | 60 BlockFramer* output_framer, |
61 BlockProcessor* block_processor, | 61 BlockProcessor* block_processor, |
62 std::vector<std::vector<float>>* block, | 62 std::vector<std::vector<float>>* block, |
63 std::vector<rtc::ArrayView<float>>* sub_frame_view) { | 63 std::vector<rtc::ArrayView<float>>* sub_frame_view) { |
64 FillSubFrameView(capture, sub_frame_index, sub_frame_view); | 64 FillSubFrameView(capture, sub_frame_index, sub_frame_view); |
65 capture_blocker->InsertSubFrameAndExtractBlock(*sub_frame_view, block); | 65 capture_blocker->InsertSubFrameAndExtractBlock(*sub_frame_view, block); |
66 block_processor->ProcessCapture(known_echo_path_change, | 66 block_processor->ProcessCapture(level_change, saturated_microphone_signal, |
67 saturated_microphone_signal, block); | 67 block); |
68 output_framer->InsertBlockAndExtractSubFrame(*block, sub_frame_view); | 68 output_framer->InsertBlockAndExtractSubFrame(*block, sub_frame_view); |
69 } | 69 } |
70 | 70 |
71 void ProcessRemainingCaptureFrameContent( | 71 void ProcessRemainingCaptureFrameContent( |
72 bool known_echo_path_change, | 72 bool level_change, |
73 bool saturated_microphone_signal, | 73 bool saturated_microphone_signal, |
74 FrameBlocker* capture_blocker, | 74 FrameBlocker* capture_blocker, |
75 BlockFramer* output_framer, | 75 BlockFramer* output_framer, |
76 BlockProcessor* block_processor, | 76 BlockProcessor* block_processor, |
77 std::vector<std::vector<float>>* block) { | 77 std::vector<std::vector<float>>* block) { |
78 if (!capture_blocker->IsBlockAvailable()) { | 78 if (!capture_blocker->IsBlockAvailable()) { |
79 return; | 79 return; |
80 } | 80 } |
81 | 81 |
82 capture_blocker->ExtractBlock(block); | 82 capture_blocker->ExtractBlock(block); |
83 block_processor->ProcessCapture(known_echo_path_change, | 83 block_processor->ProcessCapture(level_change, saturated_microphone_signal, |
84 saturated_microphone_signal, block); | 84 block); |
85 output_framer->InsertBlock(*block); | 85 output_framer->InsertBlock(*block); |
86 } | 86 } |
87 | 87 |
88 bool BufferRenderFrameContent( | 88 bool BufferRenderFrameContent( |
89 std::vector<std::vector<float>>* render_frame, | 89 std::vector<std::vector<float>>* render_frame, |
90 size_t sub_frame_index, | 90 size_t sub_frame_index, |
91 FrameBlocker* render_blocker, | 91 FrameBlocker* render_blocker, |
92 BlockProcessor* block_processor, | 92 BlockProcessor* block_processor, |
93 std::vector<std::vector<float>>* block, | 93 std::vector<std::vector<float>>* block, |
94 std::vector<rtc::ArrayView<float>>* sub_frame_view) { | 94 std::vector<rtc::ArrayView<float>>* sub_frame_view) { |
95 FillSubFrameView(render_frame, sub_frame_index, sub_frame_view); | 95 FillSubFrameView(render_frame, sub_frame_index, sub_frame_view); |
96 render_blocker->InsertSubFrameAndExtractBlock(*sub_frame_view, block); | 96 render_blocker->InsertSubFrameAndExtractBlock(*sub_frame_view, block); |
97 return block_processor->BufferRender(block); | 97 return block_processor->BufferRender(block); |
98 } | 98 } |
99 | 99 |
100 bool BufferRemainingRenderFrameContent(FrameBlocker* render_blocker, | 100 bool BufferRemainingRenderFrameContent(FrameBlocker* render_blocker, |
101 BlockProcessor* block_processor, | 101 BlockProcessor* block_processor, |
102 std::vector<std::vector<float>>* block) { | 102 std::vector<std::vector<float>>* block) { |
103 if (!render_blocker->IsBlockAvailable()) { | 103 if (!render_blocker->IsBlockAvailable()) { |
104 return false; | 104 return true; |
105 } | 105 } |
106 render_blocker->ExtractBlock(block); | 106 render_blocker->ExtractBlock(block); |
107 return block_processor->BufferRender(block); | 107 return block_processor->BufferRender(block); |
108 } | 108 } |
109 | 109 |
110 void CopyAudioBufferIntoFrame(AudioBuffer* buffer, | 110 void CopyAudioBufferIntoFrame(AudioBuffer* buffer, |
111 size_t num_bands, | 111 size_t num_bands, |
112 size_t frame_length, | 112 size_t frame_length, |
113 std::vector<std::vector<float>>* frame) { | 113 std::vector<std::vector<float>>* frame) { |
114 RTC_DCHECK_EQ(num_bands, frame->size()); | 114 RTC_DCHECK_EQ(num_bands, frame->size()); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 for (size_t k = 0; k < capture->num_channels(); ++k) { | 268 for (size_t k = 0; k < capture->num_channels(); ++k) { |
269 saturated_microphone_signal_ |= | 269 saturated_microphone_signal_ |= |
270 DetectSaturation(rtc::ArrayView<const float>(capture->channels_f()[k], | 270 DetectSaturation(rtc::ArrayView<const float>(capture->channels_f()[k], |
271 capture->num_frames())); | 271 capture->num_frames())); |
272 if (saturated_microphone_signal_) { | 272 if (saturated_microphone_signal_) { |
273 break; | 273 break; |
274 } | 274 } |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 void EchoCanceller3::ProcessCapture(AudioBuffer* capture, | 278 void EchoCanceller3::ProcessCapture(AudioBuffer* capture, bool level_change) { |
279 bool known_echo_path_change) { | |
280 RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); | 279 RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); |
281 RTC_DCHECK(capture); | 280 RTC_DCHECK(capture); |
282 RTC_DCHECK_EQ(1u, capture->num_channels()); | 281 RTC_DCHECK_EQ(1u, capture->num_channels()); |
283 RTC_DCHECK_EQ(num_bands_, capture->num_bands()); | 282 RTC_DCHECK_EQ(num_bands_, capture->num_bands()); |
284 RTC_DCHECK_EQ(frame_length_, capture->num_frames_per_band()); | 283 RTC_DCHECK_EQ(frame_length_, capture->num_frames_per_band()); |
285 | 284 |
286 rtc::ArrayView<float> capture_lower_band = | 285 rtc::ArrayView<float> capture_lower_band = |
287 rtc::ArrayView<float>(&capture->split_bands_f(0)[0][0], frame_length_); | 286 rtc::ArrayView<float>(&capture->split_bands_f(0)[0][0], frame_length_); |
288 | 287 |
289 data_dumper_->DumpWav("aec3_capture_input", capture_lower_band, | 288 data_dumper_->DumpWav("aec3_capture_input", capture_lower_band, |
290 LowestBandRate(sample_rate_hz_), 1); | 289 LowestBandRate(sample_rate_hz_), 1); |
291 | 290 |
292 const bool render_buffer_overrun = EmptyRenderQueue(); | 291 const bool successful_buffering = EmptyRenderQueue(); |
293 RTC_DCHECK(!render_buffer_overrun); | 292 RTC_DCHECK(successful_buffering); |
294 | 293 |
295 if (capture_highpass_filter_) { | 294 if (capture_highpass_filter_) { |
296 capture_highpass_filter_->Process(capture_lower_band); | 295 capture_highpass_filter_->Process(capture_lower_band); |
297 } | 296 } |
298 | 297 |
299 ProcessCaptureFrameContent(capture, known_echo_path_change, | 298 ProcessCaptureFrameContent( |
300 saturated_microphone_signal_, 0, &capture_blocker_, | 299 capture, level_change, saturated_microphone_signal_, 0, &capture_blocker_, |
301 &output_framer_, block_processor_.get(), &block_, | 300 &output_framer_, block_processor_.get(), &block_, &sub_frame_view_); |
302 &sub_frame_view_); | |
303 | 301 |
304 if (sample_rate_hz_ != 8000) { | 302 if (sample_rate_hz_ != 8000) { |
305 ProcessCaptureFrameContent( | 303 ProcessCaptureFrameContent( |
306 capture, known_echo_path_change, saturated_microphone_signal_, 1, | 304 capture, level_change, saturated_microphone_signal_, 1, |
307 &capture_blocker_, &output_framer_, block_processor_.get(), &block_, | 305 &capture_blocker_, &output_framer_, block_processor_.get(), &block_, |
308 &sub_frame_view_); | 306 &sub_frame_view_); |
309 } | 307 } |
310 | 308 |
311 ProcessRemainingCaptureFrameContent( | 309 ProcessRemainingCaptureFrameContent( |
312 known_echo_path_change, saturated_microphone_signal_, &capture_blocker_, | 310 level_change, saturated_microphone_signal_, &capture_blocker_, |
313 &output_framer_, block_processor_.get(), &block_); | 311 &output_framer_, block_processor_.get(), &block_); |
314 | 312 |
315 data_dumper_->DumpWav("aec3_capture_output", frame_length_, | 313 data_dumper_->DumpWav("aec3_capture_output", frame_length_, |
316 &capture->split_bands_f(0)[0][0], | 314 &capture->split_bands_f(0)[0][0], |
317 LowestBandRate(sample_rate_hz_), 1); | 315 LowestBandRate(sample_rate_hz_), 1); |
318 } | 316 } |
319 | 317 |
320 std::string EchoCanceller3::ToString( | 318 std::string EchoCanceller3::ToString( |
321 const AudioProcessing::Config::EchoCanceller3& config) { | 319 const AudioProcessing::Config::EchoCanceller3& config) { |
322 std::stringstream ss; | 320 std::stringstream ss; |
323 ss << "{" | 321 ss << "{" |
324 << "enabled: " << (config.enabled ? "true" : "false") << "}"; | 322 << "enabled: " << (config.enabled ? "true" : "false") << "}"; |
325 return ss.str(); | 323 return ss.str(); |
326 } | 324 } |
327 | 325 |
328 bool EchoCanceller3::Validate( | 326 bool EchoCanceller3::Validate( |
329 const AudioProcessing::Config::EchoCanceller3& config) { | 327 const AudioProcessing::Config::EchoCanceller3& config) { |
330 return true; | 328 return true; |
331 } | 329 } |
332 | 330 |
333 bool EchoCanceller3::EmptyRenderQueue() { | 331 bool EchoCanceller3::EmptyRenderQueue() { |
334 RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); | 332 RTC_DCHECK_RUNS_SERIALIZED(&capture_race_checker_); |
335 bool render_buffer_overrun = false; | 333 bool successful_buffering = true; |
336 bool frame_to_buffer = | 334 bool frame_to_buffer = |
337 render_transfer_queue_.Remove(&render_queue_output_frame_); | 335 render_transfer_queue_.Remove(&render_queue_output_frame_); |
338 while (frame_to_buffer) { | 336 while (frame_to_buffer) { |
339 render_buffer_overrun |= BufferRenderFrameContent( | 337 successful_buffering = |
340 &render_queue_output_frame_, 0, &render_blocker_, | 338 BufferRenderFrameContent(&render_queue_output_frame_, 0, |
341 block_processor_.get(), &block_, &sub_frame_view_); | 339 &render_blocker_, block_processor_.get(), |
| 340 &block_, &sub_frame_view_) && |
| 341 successful_buffering; |
342 | 342 |
343 if (sample_rate_hz_ != 8000) { | 343 if (sample_rate_hz_ != 8000) { |
344 render_buffer_overrun |= BufferRenderFrameContent( | 344 successful_buffering = |
345 &render_queue_output_frame_, 1, &render_blocker_, | 345 BufferRenderFrameContent(&render_queue_output_frame_, 1, |
346 block_processor_.get(), &block_, &sub_frame_view_); | 346 &render_blocker_, block_processor_.get(), |
| 347 &block_, &sub_frame_view_) && |
| 348 successful_buffering; |
347 } | 349 } |
348 | 350 |
349 render_buffer_overrun |= BufferRemainingRenderFrameContent( | 351 successful_buffering = |
350 &render_blocker_, block_processor_.get(), &block_); | 352 BufferRemainingRenderFrameContent(&render_blocker_, |
| 353 block_processor_.get(), &block_) && |
| 354 successful_buffering; |
351 | 355 |
352 frame_to_buffer = | 356 frame_to_buffer = |
353 render_transfer_queue_.Remove(&render_queue_output_frame_); | 357 render_transfer_queue_.Remove(&render_queue_output_frame_); |
354 } | 358 } |
355 return render_buffer_overrun; | 359 return successful_buffering; |
356 } | 360 } |
357 | 361 |
358 } // namespace webrtc | 362 } // namespace webrtc |
OLD | NEW |