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 | |
| 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_ |
| 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 | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 19 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | class AudioBuffer; |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 23 | class CriticalSectionWrapper; |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 24 | class EchoCancellationImpl; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | class EchoControlMobileImpl; |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 26 | class FileWrapper; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | class GainControlImpl; |
| 28 | class HighPassFilterImpl; |
| 29 | class LevelEstimatorImpl; |
| 30 | class NoiseSuppressionImpl; |
| 31 | class ProcessingComponent; |
| 32 | class VoiceDetectionImpl; |
| 33 | |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 34 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 35 | namespace audioproc { |
| 36 | |
| 37 | class Event; |
| 38 | |
| 39 | } // namespace audioproc |
| 40 | #endif |
| 41 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | class AudioProcessingImpl : public AudioProcessing { |
| 43 | public: |
andrew@webrtc.org | e84978f | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 44 | explicit AudioProcessingImpl(const Config& config); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | virtual ~AudioProcessingImpl(); |
| 46 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | // AudioProcessing methods. |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 48 | virtual int Initialize() OVERRIDE; |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 49 | virtual int Initialize(int sample_rate_hz, |
| 50 | int reverse_sample_rate_hz, |
| 51 | int num_input_channels, |
| 52 | int num_output_channels, |
| 53 | int num_reverse_channels) OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 54 | virtual void SetExtraOptions(const Config& config) OVERRIDE; |
aluebs@webrtc.org | 0b72f58 | 2013-11-19 15:17:51 +0000 | [diff] [blame] | 55 | virtual int EnableExperimentalNs(bool enable) OVERRIDE; |
| 56 | virtual bool experimental_ns_enabled() const OVERRIDE { |
| 57 | return false; |
| 58 | } |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 59 | virtual int set_sample_rate_hz(int rate) OVERRIDE; |
| 60 | virtual int sample_rate_hz() const OVERRIDE; |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 61 | virtual int split_sample_rate_hz() const OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 62 | virtual int set_num_channels(int input_channels, |
| 63 | int output_channels) OVERRIDE; |
| 64 | virtual int num_input_channels() const OVERRIDE; |
| 65 | virtual int num_output_channels() const OVERRIDE; |
| 66 | virtual int set_num_reverse_channels(int channels) OVERRIDE; |
| 67 | virtual int num_reverse_channels() const OVERRIDE; |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 68 | virtual void set_output_will_be_muted(bool muted) OVERRIDE; |
| 69 | virtual bool output_will_be_muted() const OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 70 | virtual int ProcessStream(AudioFrame* frame) OVERRIDE; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 71 | virtual int ProcessStream(float* const* data, |
| 72 | int samples_per_channel, |
| 73 | int sample_rate_hz, |
| 74 | ChannelLayout input_layout, |
| 75 | ChannelLayout output_layout) OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 76 | virtual int AnalyzeReverseStream(AudioFrame* frame) OVERRIDE; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 77 | virtual int AnalyzeReverseStream(const float* const* data, |
| 78 | int samples_per_channel, |
| 79 | int sample_rate_hz, |
| 80 | ChannelLayout layout) OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 81 | virtual int set_stream_delay_ms(int delay) OVERRIDE; |
| 82 | virtual int stream_delay_ms() const OVERRIDE; |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 83 | virtual bool was_stream_delay_set() const OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 84 | virtual void set_delay_offset_ms(int offset) OVERRIDE; |
| 85 | virtual int delay_offset_ms() const OVERRIDE; |
andrew@webrtc.org | 75dd288 | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 86 | virtual void set_stream_key_pressed(bool key_pressed) OVERRIDE; |
| 87 | virtual bool stream_key_pressed() const OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 88 | virtual int StartDebugRecording( |
| 89 | const char filename[kMaxFilenameSize]) OVERRIDE; |
henrikg@webrtc.org | 863b536 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 90 | virtual int StartDebugRecording(FILE* handle) OVERRIDE; |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 91 | virtual int StopDebugRecording() OVERRIDE; |
| 92 | virtual EchoCancellation* echo_cancellation() const OVERRIDE; |
| 93 | virtual EchoControlMobile* echo_control_mobile() const OVERRIDE; |
| 94 | virtual GainControl* gain_control() const OVERRIDE; |
| 95 | virtual HighPassFilter* high_pass_filter() const OVERRIDE; |
| 96 | virtual LevelEstimator* level_estimator() const OVERRIDE; |
| 97 | virtual NoiseSuppression* noise_suppression() const OVERRIDE; |
| 98 | virtual VoiceDetection* voice_detection() const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 100 | protected: |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 101 | // Overridden in a mock. |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 102 | virtual int InitializeLocked(); |
| 103 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | private: |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 105 | int InitializeLocked(int sample_rate_hz, |
| 106 | int reverse_sample_rate_hz, |
| 107 | int num_input_channels, |
| 108 | int num_output_channels, |
| 109 | int num_reverse_channels); |
| 110 | int MaybeInitializeLocked(int sample_rate_hz, |
| 111 | int reverse_sample_rate_hz, |
| 112 | int num_input_channels, |
| 113 | int num_output_channels, |
| 114 | int num_reverse_channels); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 115 | int ProcessStreamLocked(); |
| 116 | int AnalyzeReverseStreamLocked(); |
| 117 | |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 118 | bool is_data_processed() const; |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 119 | bool output_copy_needed(bool is_data_processed) const; |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 120 | bool synthesis_needed(bool is_data_processed) const; |
| 121 | bool analysis_needed(bool is_data_processed) const; |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 122 | |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 123 | EchoCancellationImpl* echo_cancellation_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 124 | EchoControlMobileImpl* echo_control_mobile_; |
| 125 | GainControlImpl* gain_control_; |
| 126 | HighPassFilterImpl* high_pass_filter_; |
| 127 | LevelEstimatorImpl* level_estimator_; |
| 128 | NoiseSuppressionImpl* noise_suppression_; |
| 129 | VoiceDetectionImpl* voice_detection_; |
| 130 | |
| 131 | std::list<ProcessingComponent*> component_list_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | CriticalSectionWrapper* crit_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 133 | AudioBuffer* render_audio_; |
| 134 | AudioBuffer* capture_audio_; |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 135 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 136 | // TODO(andrew): make this more graceful. Ideally we would split this stuff |
| 137 | // out into a separate class with an "enabled" and "disabled" implementation. |
| 138 | int WriteMessageToDebugFile(); |
| 139 | int WriteInitMessage(); |
| 140 | scoped_ptr<FileWrapper> debug_file_; |
andrew@webrtc.org | 60730cf | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 141 | scoped_ptr<audioproc::Event> event_msg_; // Protobuf message. |
| 142 | std::string event_str_; // Memory for protobuf serialization. |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 143 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | |
| 145 | int sample_rate_hz_; |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 146 | int reverse_sample_rate_hz_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 147 | int split_sample_rate_hz_; |
| 148 | int samples_per_channel_; |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 149 | int reverse_samples_per_channel_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 150 | int stream_delay_ms_; |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 151 | int delay_offset_ms_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | bool was_stream_delay_set_; |
| 153 | |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 154 | int num_reverse_channels_; |
| 155 | int num_input_channels_; |
| 156 | int num_output_channels_; |
andrew@webrtc.org | 17342e5 | 2014-02-12 22:28:31 +0000 | [diff] [blame] | 157 | bool output_will_be_muted_; |
andrew@webrtc.org | 75dd288 | 2014-02-11 20:52:30 +0000 | [diff] [blame] | 158 | |
| 159 | bool key_pressed_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 160 | }; |
| 161 | } // namespace webrtc |
| 162 | |
| 163 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_ |