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