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 | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 24 | class EchoCancellationImplWrapper; |
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: |
| 44 | enum { |
| 45 | kSampleRate8kHz = 8000, |
| 46 | kSampleRate16kHz = 16000, |
| 47 | kSampleRate32kHz = 32000 |
| 48 | }; |
| 49 | |
| 50 | explicit AudioProcessingImpl(int id); |
| 51 | virtual ~AudioProcessingImpl(); |
| 52 | |
| 53 | CriticalSectionWrapper* crit() const; |
| 54 | |
| 55 | int split_sample_rate_hz() const; |
| 56 | bool was_stream_delay_set() const; |
| 57 | |
| 58 | // AudioProcessing methods. |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 59 | virtual int Initialize() OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | virtual int InitializeLocked(); |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 61 | virtual void SetExtraOptions(const Config& config) OVERRIDE; |
| 62 | virtual int set_sample_rate_hz(int rate) OVERRIDE; |
| 63 | virtual int sample_rate_hz() const OVERRIDE; |
| 64 | virtual int set_num_channels(int input_channels, |
| 65 | int output_channels) OVERRIDE; |
| 66 | virtual int num_input_channels() const OVERRIDE; |
| 67 | virtual int num_output_channels() const OVERRIDE; |
| 68 | virtual int set_num_reverse_channels(int channels) OVERRIDE; |
| 69 | virtual int num_reverse_channels() const OVERRIDE; |
| 70 | virtual int ProcessStream(AudioFrame* frame) OVERRIDE; |
| 71 | virtual int AnalyzeReverseStream(AudioFrame* frame) OVERRIDE; |
| 72 | virtual int set_stream_delay_ms(int delay) OVERRIDE; |
| 73 | virtual int stream_delay_ms() const OVERRIDE; |
| 74 | virtual void set_delay_offset_ms(int offset) OVERRIDE; |
| 75 | virtual int delay_offset_ms() const OVERRIDE; |
| 76 | virtual int StartDebugRecording( |
| 77 | const char filename[kMaxFilenameSize]) OVERRIDE; |
| 78 | virtual int StopDebugRecording() OVERRIDE; |
| 79 | virtual EchoCancellation* echo_cancellation() const OVERRIDE; |
| 80 | virtual EchoControlMobile* echo_control_mobile() const OVERRIDE; |
| 81 | virtual GainControl* gain_control() const OVERRIDE; |
| 82 | virtual HighPassFilter* high_pass_filter() const OVERRIDE; |
| 83 | virtual LevelEstimator* level_estimator() const OVERRIDE; |
| 84 | virtual NoiseSuppression* noise_suppression() const OVERRIDE; |
| 85 | virtual VoiceDetection* voice_detection() const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
| 87 | // Module methods. |
pbos@webrtc.org | 9162080 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 88 | virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
| 90 | private: |
andrew@webrtc.org | 369166a | 2012-04-24 18:38:03 +0000 | [diff] [blame] | 91 | bool is_data_processed() const; |
| 92 | bool interleave_needed(bool is_data_processed) const; |
| 93 | bool synthesis_needed(bool is_data_processed) const; |
| 94 | bool analysis_needed(bool is_data_processed) const; |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 95 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | int id_; |
| 97 | |
andrew@webrtc.org | 61e596f | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 98 | EchoCancellationImplWrapper* echo_cancellation_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | EchoControlMobileImpl* echo_control_mobile_; |
| 100 | GainControlImpl* gain_control_; |
| 101 | HighPassFilterImpl* high_pass_filter_; |
| 102 | LevelEstimatorImpl* level_estimator_; |
| 103 | NoiseSuppressionImpl* noise_suppression_; |
| 104 | VoiceDetectionImpl* voice_detection_; |
| 105 | |
| 106 | std::list<ProcessingComponent*> component_list_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | CriticalSectionWrapper* crit_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | AudioBuffer* render_audio_; |
| 109 | AudioBuffer* capture_audio_; |
andrew@webrtc.org | 7bf2646 | 2011-12-03 00:03:31 +0000 | [diff] [blame] | 110 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 111 | // TODO(andrew): make this more graceful. Ideally we would split this stuff |
| 112 | // out into a separate class with an "enabled" and "disabled" implementation. |
| 113 | int WriteMessageToDebugFile(); |
| 114 | int WriteInitMessage(); |
| 115 | scoped_ptr<FileWrapper> debug_file_; |
| 116 | scoped_ptr<audioproc::Event> event_msg_; // Protobuf message. |
| 117 | std::string event_str_; // Memory for protobuf serialization. |
| 118 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | |
| 120 | int sample_rate_hz_; |
| 121 | int split_sample_rate_hz_; |
| 122 | int samples_per_channel_; |
| 123 | int stream_delay_ms_; |
andrew@webrtc.org | 6f9f817 | 2012-03-06 19:03:39 +0000 | [diff] [blame] | 124 | int delay_offset_ms_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 125 | bool was_stream_delay_set_; |
| 126 | |
ajm@google.com | 808e0e0 | 2011-08-03 21:08:51 +0000 | [diff] [blame] | 127 | int num_reverse_channels_; |
| 128 | int num_input_channels_; |
| 129 | int num_output_channels_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | }; |
| 131 | } // namespace webrtc |
| 132 | |
| 133 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_ |