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

Side by Side Diff: webrtc/modules/audio_processing/audio_processing_impl.h

Issue 1226093007: Allow more than 2 input channels in AudioProcessing. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix comments and rearrange code Created 5 years, 5 months 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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_AUDIO_PROCESSING_IMPL_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
13 13
14 #include <list> 14 #include <list>
15 #include <string> 15 #include <string>
16 #include <vector>
16 17
17 #include "webrtc/base/scoped_ptr.h" 18 #include "webrtc/base/scoped_ptr.h"
18 #include "webrtc/base/thread_annotations.h" 19 #include "webrtc/base/thread_annotations.h"
19 #include "webrtc/modules/audio_processing/include/audio_processing.h" 20 #include "webrtc/modules/audio_processing/include/audio_processing.h"
20 21
21 namespace webrtc { 22 namespace webrtc {
22 23
23 class AgcManagerDirect; 24 class AgcManagerDirect;
24 class AudioBuffer; 25 class AudioBuffer;
25 26
(...skipping 14 matching lines...) Expand all
40 class VoiceDetectionImpl; 41 class VoiceDetectionImpl;
41 42
42 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 43 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
43 namespace audioproc { 44 namespace audioproc {
44 45
45 class Event; 46 class Event;
46 47
47 } // namespace audioproc 48 } // namespace audioproc
48 #endif 49 #endif
49 50
50 class AudioRate {
mgraczyk 2015/07/10 00:33:36 I replaced AudioRate and AudioFormat with the exte
51 public:
52 explicit AudioRate(int sample_rate_hz) { set(sample_rate_hz); }
53 virtual ~AudioRate() {}
54
55 void set(int rate) {
56 rate_ = rate;
57 samples_per_channel_ = AudioProcessing::kChunkSizeMs * rate_ / 1000;
58 }
59
60 int rate() const { return rate_; }
61 int samples_per_channel() const { return samples_per_channel_; }
62
63 private:
64 int rate_;
65 int samples_per_channel_;
66 };
67
68 class AudioFormat : public AudioRate {
69 public:
70 AudioFormat(int sample_rate_hz, int num_channels)
71 : AudioRate(sample_rate_hz),
72 num_channels_(num_channels) {}
73 virtual ~AudioFormat() {}
74
75 void set(int rate, int num_channels) {
76 AudioRate::set(rate);
77 num_channels_ = num_channels;
78 }
79
80 int num_channels() const { return num_channels_; }
81
82 private:
83 int num_channels_;
84 };
85
86 class AudioProcessingImpl : public AudioProcessing { 51 class AudioProcessingImpl : public AudioProcessing {
87 public: 52 public:
88 explicit AudioProcessingImpl(const Config& config); 53 explicit AudioProcessingImpl(const Config& config);
89 54
90 // AudioProcessingImpl takes ownership of beamformer. 55 // AudioProcessingImpl takes ownership of beamformer.
91 AudioProcessingImpl(const Config& config, Beamformer<float>* beamformer); 56 AudioProcessingImpl(const Config& config, Beamformer<float>* beamformer);
92 virtual ~AudioProcessingImpl(); 57 virtual ~AudioProcessingImpl();
93 58
94 // AudioProcessing methods. 59 // AudioProcessing methods.
95 int Initialize() override; 60 int Initialize() override;
96 int Initialize(int input_sample_rate_hz, 61 int Initialize(int input_sample_rate_hz,
97 int output_sample_rate_hz, 62 int output_sample_rate_hz,
98 int reverse_sample_rate_hz, 63 int reverse_sample_rate_hz,
99 ChannelLayout input_layout, 64 ChannelLayout input_layout,
100 ChannelLayout output_layout, 65 ChannelLayout output_layout,
101 ChannelLayout reverse_layout) override; 66 ChannelLayout reverse_layout) override;
67 int Initialize(const ProcessingConfig& processing_config) override;
102 void SetExtraOptions(const Config& config) override; 68 void SetExtraOptions(const Config& config) override;
103 int set_sample_rate_hz(int rate) override; 69 int set_sample_rate_hz(int rate) override;
104 int input_sample_rate_hz() const override; 70 int input_sample_rate_hz() const override;
105 int sample_rate_hz() const override; 71 int sample_rate_hz() const override;
106 int proc_sample_rate_hz() const override; 72 int proc_sample_rate_hz() const override;
107 int proc_split_sample_rate_hz() const override; 73 int proc_split_sample_rate_hz() const override;
108 int num_input_channels() const override; 74 int num_input_channels() const override;
109 int num_output_channels() const override; 75 int num_output_channels() const override;
110 int num_reverse_channels() const override; 76 int num_reverse_channels() const override;
111 void set_output_will_be_muted(bool muted) override; 77 void set_output_will_be_muted(bool muted) override;
112 bool output_will_be_muted() const override; 78 bool output_will_be_muted() const override;
113 int ProcessStream(AudioFrame* frame) override; 79 int ProcessStream(AudioFrame* frame) override;
114 int ProcessStream(const float* const* src, 80 int ProcessStream(const float* const* src,
115 int samples_per_channel, 81 int samples_per_channel,
116 int input_sample_rate_hz, 82 int input_sample_rate_hz,
117 ChannelLayout input_layout, 83 ChannelLayout input_layout,
118 int output_sample_rate_hz, 84 int output_sample_rate_hz,
119 ChannelLayout output_layout, 85 ChannelLayout output_layout,
120 float* const* dest) override; 86 float* const* dest) override;
87 int ProcessStream(const float* const* src,
88 const ProcessingConfig& processing_config,
89 float* const* dest) override;
121 int AnalyzeReverseStream(AudioFrame* frame) override; 90 int AnalyzeReverseStream(AudioFrame* frame) override;
122 int AnalyzeReverseStream(const float* const* data, 91 int AnalyzeReverseStream(const float* const* data,
123 int samples_per_channel, 92 int samples_per_channel,
124 int sample_rate_hz, 93 int sample_rate_hz,
125 ChannelLayout layout) override; 94 ChannelLayout layout) override;
95 int AnalyzeReverseStream(const float* const* data,
96 const StreamConfig& reverse_config) override;
126 int set_stream_delay_ms(int delay) override; 97 int set_stream_delay_ms(int delay) override;
127 int stream_delay_ms() const override; 98 int stream_delay_ms() const override;
128 bool was_stream_delay_set() const override; 99 bool was_stream_delay_set() const override;
129 void set_delay_offset_ms(int offset) override; 100 void set_delay_offset_ms(int offset) override;
130 int delay_offset_ms() const override; 101 int delay_offset_ms() const override;
131 void set_stream_key_pressed(bool key_pressed) override; 102 void set_stream_key_pressed(bool key_pressed) override;
132 bool stream_key_pressed() const override; 103 bool stream_key_pressed() const override;
133 int StartDebugRecording(const char filename[kMaxFilenameSize]) override; 104 int StartDebugRecording(const char filename[kMaxFilenameSize]) override;
134 int StartDebugRecording(FILE* handle) override; 105 int StartDebugRecording(FILE* handle) override;
135 int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override; 106 int StartDebugRecordingForPlatformFile(rtc::PlatformFile handle) override;
136 int StopDebugRecording() override; 107 int StopDebugRecording() override;
137 void UpdateHistogramsOnCallEnd() override; 108 void UpdateHistogramsOnCallEnd() override;
138 EchoCancellation* echo_cancellation() const override; 109 EchoCancellation* echo_cancellation() const override;
139 EchoControlMobile* echo_control_mobile() const override; 110 EchoControlMobile* echo_control_mobile() const override;
140 GainControl* gain_control() const override; 111 GainControl* gain_control() const override;
141 HighPassFilter* high_pass_filter() const override; 112 HighPassFilter* high_pass_filter() const override;
142 LevelEstimator* level_estimator() const override; 113 LevelEstimator* level_estimator() const override;
143 NoiseSuppression* noise_suppression() const override; 114 NoiseSuppression* noise_suppression() const override;
144 VoiceDetection* voice_detection() const override; 115 VoiceDetection* voice_detection() const override;
145 116
146 protected: 117 protected:
147 // Overridden in a mock. 118 // Overridden in a mock.
148 virtual int InitializeLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); 119 virtual int InitializeLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
149 120
150 private: 121 private:
151 int InitializeLocked(int input_sample_rate_hz, 122 int InitializeLocked(const ProcessingConfig& config)
152 int output_sample_rate_hz,
153 int reverse_sample_rate_hz,
154 int num_input_channels,
155 int num_output_channels,
156 int num_reverse_channels)
157 EXCLUSIVE_LOCKS_REQUIRED(crit_); 123 EXCLUSIVE_LOCKS_REQUIRED(crit_);
158 int MaybeInitializeLocked(int input_sample_rate_hz, 124 int MaybeInitializeLocked(const ProcessingConfig& config)
159 int output_sample_rate_hz,
160 int reverse_sample_rate_hz,
161 int num_input_channels,
162 int num_output_channels,
163 int num_reverse_channels)
164 EXCLUSIVE_LOCKS_REQUIRED(crit_); 125 EXCLUSIVE_LOCKS_REQUIRED(crit_);
165 int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); 126 int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
166 int AnalyzeReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); 127 int AnalyzeReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
167 128
168 bool is_data_processed() const; 129 bool is_data_processed() const;
169 bool output_copy_needed(bool is_data_processed) const; 130 bool output_copy_needed(bool is_data_processed) const;
170 bool synthesis_needed(bool is_data_processed) const; 131 bool synthesis_needed(bool is_data_processed) const;
171 bool analysis_needed(bool is_data_processed) const; 132 bool analysis_needed(bool is_data_processed) const;
172 void InitializeExperimentalAgc() EXCLUSIVE_LOCKS_REQUIRED(crit_); 133 void InitializeExperimentalAgc() EXCLUSIVE_LOCKS_REQUIRED(crit_);
173 void InitializeTransient() EXCLUSIVE_LOCKS_REQUIRED(crit_); 134 void InitializeTransient() EXCLUSIVE_LOCKS_REQUIRED(crit_);
(...skipping 16 matching lines...) Expand all
190 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 151 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
191 // TODO(andrew): make this more graceful. Ideally we would split this stuff 152 // TODO(andrew): make this more graceful. Ideally we would split this stuff
192 // out into a separate class with an "enabled" and "disabled" implementation. 153 // out into a separate class with an "enabled" and "disabled" implementation.
193 int WriteMessageToDebugFile(); 154 int WriteMessageToDebugFile();
194 int WriteInitMessage(); 155 int WriteInitMessage();
195 rtc::scoped_ptr<FileWrapper> debug_file_; 156 rtc::scoped_ptr<FileWrapper> debug_file_;
196 rtc::scoped_ptr<audioproc::Event> event_msg_; // Protobuf message. 157 rtc::scoped_ptr<audioproc::Event> event_msg_; // Protobuf message.
197 std::string event_str_; // Memory for protobuf serialization. 158 std::string event_str_; // Memory for protobuf serialization.
198 #endif 159 #endif
199 160
200 AudioFormat fwd_in_format_; 161 // Format of processing streams at input/output call sites.
201 // This one is an AudioRate, because the forward processing number of channels 162 ProcessingConfig api_format_;
202 // is mutable and is tracked by the capture_audio_. 163
203 AudioRate fwd_proc_format_; 164 // Only the rate and samples fields of fwd_proc_format_ are used because the
204 AudioFormat fwd_out_format_; 165 // forward processing number of channels is mutable and is tracked by the
205 AudioFormat rev_in_format_; 166 // capture_audio_.
206 AudioFormat rev_proc_format_; 167 StreamConfig fwd_proc_format_;
168 StreamConfig rev_proc_format_;
207 int split_rate_; 169 int split_rate_;
208 170
209 int stream_delay_ms_; 171 int stream_delay_ms_;
210 int delay_offset_ms_; 172 int delay_offset_ms_;
211 bool was_stream_delay_set_; 173 bool was_stream_delay_set_;
212 int last_stream_delay_ms_; 174 int last_stream_delay_ms_;
213 int last_aec_system_delay_ms_; 175 int last_aec_system_delay_ms_;
214 int stream_delay_jumps_; 176 int stream_delay_jumps_;
215 int aec_system_delay_jumps_; 177 int aec_system_delay_jumps_;
216 178
(...skipping 11 matching lines...) Expand all
228 const bool beamformer_enabled_; 190 const bool beamformer_enabled_;
229 rtc::scoped_ptr<Beamformer<float>> beamformer_; 191 rtc::scoped_ptr<Beamformer<float>> beamformer_;
230 const std::vector<Point> array_geometry_; 192 const std::vector<Point> array_geometry_;
231 193
232 const bool supports_48kHz_; 194 const bool supports_48kHz_;
233 }; 195 };
234 196
235 } // namespace webrtc 197 } // namespace webrtc
236 198
237 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ 199 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698