niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 15 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | #include <list> |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 17 | #include <string> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 19 | #include "webrtc/base/thread_annotations.h" |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 20 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 23 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 24 | class AgcManagerDirect; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | class AudioBuffer; |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 26 | class Beamformer; |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 27 | class CriticalSectionWrapper; |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 28 | class EchoCancellationImpl; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | class EchoControlMobileImpl; |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 30 | class FileWrapper; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | class GainControlImpl; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 32 | class GainControlForNewAgc; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | class HighPassFilterImpl; |
| 34 | class LevelEstimatorImpl; |
| 35 | class NoiseSuppressionImpl; |
| 36 | class ProcessingComponent; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 37 | class TransientSuppressor; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | class VoiceDetectionImpl; |
| 39 | |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 40 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 41 | namespace audioproc { |
| 42 | |
| 43 | class Event; |
| 44 | |
| 45 | } // namespace audioproc |
| 46 | #endif |
| 47 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 48 | class AudioRate { |
| 49 | public: |
| 50 | explicit AudioRate(int sample_rate_hz) |
| 51 | : rate_(sample_rate_hz), |
| 52 | samples_per_channel_(AudioProcessing::kChunkSizeMs * rate_ / 1000) {} |
| 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 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | class AudioProcessingImpl : public AudioProcessing { |
| 87 | public: |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 88 | explicit AudioProcessingImpl(const Config& config); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | virtual ~AudioProcessingImpl(); |
| 90 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | // AudioProcessing methods. |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 92 | virtual int Initialize() OVERRIDE; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 93 | virtual int Initialize(int input_sample_rate_hz, |
| 94 | int output_sample_rate_hz, |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 95 | int reverse_sample_rate_hz, |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 96 | ChannelLayout input_layout, |
| 97 | ChannelLayout output_layout, |
| 98 | ChannelLayout reverse_layout) OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 99 | virtual void SetExtraOptions(const Config& config) OVERRIDE; |
| 100 | virtual int set_sample_rate_hz(int rate) OVERRIDE; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 101 | virtual int input_sample_rate_hz() const OVERRIDE; |
andrew@webrtc.org | 46b31b1 | 2014-04-23 03:33:54 +0000 | [diff] [blame] | 102 | virtual int sample_rate_hz() const OVERRIDE; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 103 | virtual int proc_sample_rate_hz() const OVERRIDE; |
| 104 | virtual int proc_split_sample_rate_hz() const OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 105 | virtual int num_input_channels() const OVERRIDE; |
| 106 | virtual int num_output_channels() const OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 107 | virtual int num_reverse_channels() const OVERRIDE; |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 108 | virtual void set_output_will_be_muted(bool muted) OVERRIDE; |
| 109 | virtual bool output_will_be_muted() const OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 110 | virtual int ProcessStream(AudioFrame* frame) OVERRIDE; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 111 | virtual int ProcessStream(const float* const* src, |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 112 | int samples_per_channel, |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 113 | int input_sample_rate_hz, |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 114 | ChannelLayout input_layout, |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 115 | int output_sample_rate_hz, |
| 116 | ChannelLayout output_layout, |
| 117 | float* const* dest) OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 118 | virtual int AnalyzeReverseStream(AudioFrame* frame) OVERRIDE; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 119 | virtual int AnalyzeReverseStream(const float* const* data, |
| 120 | int samples_per_channel, |
| 121 | int sample_rate_hz, |
| 122 | ChannelLayout layout) OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 123 | virtual int set_stream_delay_ms(int delay) OVERRIDE; |
| 124 | virtual int stream_delay_ms() const OVERRIDE; |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 125 | virtual bool was_stream_delay_set() const OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 126 | virtual void set_delay_offset_ms(int offset) OVERRIDE; |
| 127 | virtual int delay_offset_ms() const OVERRIDE; |
andrew@webrtc.org | 75dd288 | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 128 | virtual void set_stream_key_pressed(bool key_pressed) OVERRIDE; |
| 129 | virtual bool stream_key_pressed() const OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 130 | virtual int StartDebugRecording( |
| 131 | const char filename[kMaxFilenameSize]) OVERRIDE; |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 132 | virtual int StartDebugRecording(FILE* handle) OVERRIDE; |
xians@webrtc.org | e46bc77 | 2014-10-10 08:36:56 +0000 | [diff] [blame] | 133 | virtual int StartDebugRecordingForPlatformFile( |
| 134 | rtc::PlatformFile handle) OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 135 | virtual int StopDebugRecording() OVERRIDE; |
| 136 | virtual EchoCancellation* echo_cancellation() const OVERRIDE; |
| 137 | virtual EchoControlMobile* echo_control_mobile() const OVERRIDE; |
| 138 | virtual GainControl* gain_control() const OVERRIDE; |
| 139 | virtual HighPassFilter* high_pass_filter() const OVERRIDE; |
| 140 | virtual LevelEstimator* level_estimator() const OVERRIDE; |
| 141 | virtual NoiseSuppression* noise_suppression() const OVERRIDE; |
| 142 | virtual VoiceDetection* voice_detection() const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 143 | |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 144 | protected: |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 145 | // Overridden in a mock. |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 146 | virtual int InitializeLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 147 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | private: |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 149 | int InitializeLocked(int input_sample_rate_hz, |
| 150 | int output_sample_rate_hz, |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 151 | int reverse_sample_rate_hz, |
| 152 | int num_input_channels, |
| 153 | int num_output_channels, |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 154 | int num_reverse_channels) |
| 155 | EXCLUSIVE_LOCKS_REQUIRED(crit_); |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 156 | int MaybeInitializeLocked(int input_sample_rate_hz, |
| 157 | int output_sample_rate_hz, |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 158 | int reverse_sample_rate_hz, |
| 159 | int num_input_channels, |
| 160 | int num_output_channels, |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 161 | int num_reverse_channels) |
| 162 | EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 163 | int ProcessStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 164 | int AnalyzeReverseStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 165 | |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 166 | bool is_data_processed() const; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 167 | bool output_copy_needed(bool is_data_processed) const; |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 168 | bool synthesis_needed(bool is_data_processed) const; |
| 169 | bool analysis_needed(bool is_data_processed) const; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 170 | int InitializeExperimentalAgc() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 171 | int InitializeTransient() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 172 | void InitializeBeamformer() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 173 | |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 174 | EchoCancellationImpl* echo_cancellation_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 175 | EchoControlMobileImpl* echo_control_mobile_; |
| 176 | GainControlImpl* gain_control_; |
| 177 | HighPassFilterImpl* high_pass_filter_; |
| 178 | LevelEstimatorImpl* level_estimator_; |
| 179 | NoiseSuppressionImpl* noise_suppression_; |
| 180 | VoiceDetectionImpl* voice_detection_; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 181 | scoped_ptr<GainControlForNewAgc> gain_control_for_new_agc_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | |
| 183 | std::list<ProcessingComponent*> component_list_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | CriticalSectionWrapper* crit_; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 185 | scoped_ptr<AudioBuffer> render_audio_; |
| 186 | scoped_ptr<AudioBuffer> capture_audio_; |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 187 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 188 | // TODO(andrew): make this more graceful. Ideally we would split this stuff |
| 189 | // out into a separate class with an "enabled" and "disabled" implementation. |
| 190 | int WriteMessageToDebugFile(); |
| 191 | int WriteInitMessage(); |
| 192 | scoped_ptr<FileWrapper> debug_file_; |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 193 | scoped_ptr<audioproc::Event> event_msg_; // Protobuf message. |
| 194 | std::string event_str_; // Memory for protobuf serialization. |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 195 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 196 | |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 197 | AudioFormat fwd_in_format_; |
aluebs@webrtc.org | 27d106b | 2014-12-11 17:09:21 +0000 | [diff] [blame] | 198 | // This one is an AudioRate, because the forward processing number of channels |
| 199 | // is mutable and is tracked by the capture_audio_. |
| 200 | AudioRate fwd_proc_format_; |
| 201 | AudioFormat fwd_out_format_; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 202 | AudioFormat rev_in_format_; |
| 203 | AudioFormat rev_proc_format_; |
| 204 | int split_rate_; |
| 205 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 206 | int stream_delay_ms_; |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 207 | int delay_offset_ms_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 208 | bool was_stream_delay_set_; |
| 209 | |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 210 | bool output_will_be_muted_; |
andrew@webrtc.org | 75dd288 | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 211 | |
| 212 | bool key_pressed_; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 213 | |
| 214 | // Only set through the constructor's Config parameter. |
| 215 | const bool use_new_agc_; |
| 216 | scoped_ptr<AgcManagerDirect> agc_manager_ GUARDED_BY(crit_); |
| 217 | |
| 218 | bool transient_suppressor_enabled_; |
| 219 | scoped_ptr<TransientSuppressor> transient_suppressor_; |
aluebs@webrtc.org | ae643ce | 2014-12-19 19:57:34 +0000 | [diff] [blame] | 220 | const bool beamformer_enabled_; |
| 221 | scoped_ptr<Beamformer> beamformer_; |
aluebs@webrtc.org | fb7a039 | 2015-01-05 21:58:58 +0000 | [diff] [blame] | 222 | const std::vector<Point> array_geometry_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 223 | }; |
andrew@webrtc.org | ddbb8a2 | 2014-04-22 21:00:04 +0000 | [diff] [blame] | 224 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 225 | } // namespace webrtc |
| 226 | |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 227 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AUDIO_PROCESSING_IMPL_H_ |