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

Side by Side Diff: webrtc/modules/audio_processing/aec3/echo_canceller3.h

Issue 2584493002: Added first layer of the echo canceller 3 functionality (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
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_ECHO_CANCELLER3_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_ECHO_CANCELLER3_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_ECHO_CANCELLER3_H_ 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_ECHO_CANCELLER3_H_
13 13
14 #include <string>
15
16 #include "webrtc/base/constructormagic.h" 14 #include "webrtc/base/constructormagic.h"
15 #include "webrtc/base/swap_queue.h"
16 #include "webrtc/modules/audio_processing/aec3/block_framer.h"
17 #include "webrtc/modules/audio_processing/aec3/block_processor.h"
18 #include "webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.h"
19 #include "webrtc/modules/audio_processing/aec3/frame_blocker.h"
17 #include "webrtc/modules/audio_processing/audio_buffer.h" 20 #include "webrtc/modules/audio_processing/audio_buffer.h"
21 #include "webrtc/modules/audio_processing/include/audio_processing.h"
22 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
18 23
19 namespace webrtc { 24 namespace webrtc {
20 25
26 // Functor for verifying the invariance of the frames being put into the render
27 // queue.
28 class Aec3RenderQueueItemVerifier {
29 public:
30 explicit Aec3RenderQueueItemVerifier(size_t num_bands, size_t frame_length)
31 : num_bands_(num_bands), frame_length_(frame_length) {}
32
33 bool operator()(const std::vector<std::vector<float>>& v) const {
34 bool result = true;
35 result &= v.size() == num_bands_;
ivoc 2016/12/21 13:04:05 This is the bitwise-AND operator (like a = a & b),
peah-webrtc 2016/12/21 23:13:51 Good one! Done.
36 for (auto v_k : v) {
aleloi 2016/12/20 15:55:35 const auto &.
peah-webrtc 2016/12/21 23:13:51 Good find!!! Thanks! Done.
37 result &= v_k.size() == frame_length_;
ivoc 2016/12/21 13:04:05 I suggest using an early return here: if (v_k.size
peah-webrtc 2016/12/21 23:13:51 Done.
38 }
39 return result;
40 }
41
42 private:
43 const size_t num_bands_;
44 const size_t frame_length_;
45 };
46
47 // Main class for the echo canceller3. It does 4 things:
48 // -Receives 10 ms frames of band-split audio.
49 // -Optionally applies an anti-hum (high-pass) filter on the
50 // received signals.
51 // -Provides the lower level echo canceller functionality with
52 // blocks of 64 samples of audio data.
53 // -Partially handles the jitter in the render and capture API
54 // call sequence.
55 // The class is supposed to be used in a non-concurrent manner apart from the
56 // AnalyzeRender call which can be called concurrently with the other methods.
21 class EchoCanceller3 { 57 class EchoCanceller3 {
22 public: 58 public:
23 EchoCanceller3(int sample_rate_hz, bool use_anti_hum_filter); 59 // Normal c-tor to use.
60 EchoCanceller3(int sample_rate_hz, bool use_highpass_filter);
61 // Testing c-tor that is used only for testing purposes.
62 EchoCanceller3(int sample_rate_hz,
63 bool use_highpass_filter,
64 BlockProcessor* block_processor);
hlundin-webrtc 2016/12/20 15:10:35 It is not obvious to the caller that the ownership
aleloi 2016/12/20 15:55:35 I think block_processor should be a unique_ptr<Blo
peah-webrtc 2016/12/21 23:13:51 Done.
peah-webrtc 2016/12/21 23:13:51 Done.
24 ~EchoCanceller3(); 65 ~EchoCanceller3();
25 // Analyzes and stores an internal copy of the split-band domain render 66 // Analyzes and stores an internal copy of the split-band domain render
26 // signal. 67 // signal.
27 bool AnalyzeRender(AudioBuffer* farend); 68 bool AnalyzeRender(AudioBuffer* farend);
28 // Analyzes the full-band domain capture signal to detect signal saturation. 69 // Analyzes the full-band domain capture signal to detect signal saturation.
29 void AnalyzeCapture(AudioBuffer* capture); 70 void AnalyzeCapture(AudioBuffer* capture);
30 // Processes the split-band domain capture signal in order to remove any echo 71 // Processes the split-band domain capture signal in order to remove any echo
31 // present in the signal. 72 // present in the signal.
32 void ProcessCapture(AudioBuffer* capture, bool known_echo_path_change); 73 void ProcessCapture(AudioBuffer* capture, bool known_echo_path_change);
33 74
75 // Signals whether an external detector has detected echo leakage from the
76 // echo canceller.
77 // Note that in the case echo leakage has been flagged, it should be unflagged
78 // once it is no longer occurring.
79 void ReportEchoLeakage(bool leakage_detected) {
80 block_processor_->ReportEchoLeakage(leakage_detected);
81 }
82
34 // Validates a config. 83 // Validates a config.
35 static bool Validate(const AudioProcessing::Config::EchoCanceller3& config); 84 static bool Validate(const AudioProcessing::Config::EchoCanceller3& config);
36 // Dumps a config to a string. 85 // Dumps a config to a string.
37 static std::string ToString( 86 static std::string ToString(
38 const AudioProcessing::Config::EchoCanceller3& config); 87 const AudioProcessing::Config::EchoCanceller3& config);
39 88
40 private: 89 private:
90 class RenderWriter;
91
92 bool EmptyRenderQueue();
93
94 // State that is accessed by the AnalyzeRender call.
95 std::unique_ptr<RenderWriter> render_writer_;
96
97 // State that may be accessed by the capture thread.
41 static int instance_count_; 98 static int instance_count_;
42 size_t frame_length_; 99 std::unique_ptr<ApmDataDumper> data_dumper_;
100 const int sample_rate_hz_;
101 const int num_bands_;
102 const size_t frame_length_;
103 BlockFramer output_framer_;
104 FrameBlocker capture_blocker_;
105 FrameBlocker render_blocker_;
106 SwapQueue<std::vector<std::vector<float>>, Aec3RenderQueueItemVerifier>
107 render_transfer_queue_;
108 std::unique_ptr<BlockProcessor> block_processor_;
109 std::vector<std::vector<float>> render_queue_output_frame_;
110 std::unique_ptr<CascadedBiQuadFilter> capture_highpass_filter_;
111 bool saturated_microphone_signal_ = false;
112 std::vector<std::vector<float>> block_;
43 113
44 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoCanceller3); 114 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoCanceller3);
45 }; 115 };
46 } // namespace webrtc 116 } // namespace webrtc
47 117
48 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_ECHO_CANCELLER3_H_ 118 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC3_ECHO_CANCELLER3_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698