andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 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 | 9fb1613 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 15 | |
| 16 | #include <list> |
| 17 | #include <string> |
| 18 | |
pbos@webrtc.org | 9fb1613 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 19 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | class AudioBuffer; |
| 23 | class CriticalSectionWrapper; |
andrew@webrtc.org | 25613ea | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 24 | class EchoCancellationImplWrapper; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 25 | class EchoControlMobileImpl; |
| 26 | class FileWrapper; |
| 27 | class GainControlImpl; |
| 28 | class HighPassFilterImpl; |
| 29 | class LevelEstimatorImpl; |
| 30 | class NoiseSuppressionImpl; |
| 31 | class ProcessingComponent; |
| 32 | class VoiceDetectionImpl; |
| 33 | |
| 34 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 35 | namespace audioproc { |
| 36 | |
| 37 | class Event; |
| 38 | |
| 39 | } // namespace audioproc |
| 40 | #endif |
| 41 | |
| 42 | class AudioProcessingImpl : public AudioProcessing { |
| 43 | public: |
| 44 | enum { |
| 45 | kSampleRate8kHz = 8000, |
| 46 | kSampleRate16kHz = 16000, |
| 47 | kSampleRate32kHz = 32000 |
| 48 | }; |
| 49 | |
andrew@webrtc.org | 3fbe666 | 2014-01-25 02:09:06 +0000 | [diff] [blame] | 50 | explicit AudioProcessingImpl(const Config& config); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | 24add92 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 59 | virtual int Initialize() OVERRIDE; |
pbos@webrtc.org | 24add92 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 60 | virtual void SetExtraOptions(const Config& config) OVERRIDE; |
aluebs@webrtc.org | 09b40ec | 2013-11-19 15:17:51 +0000 | [diff] [blame] | 61 | virtual int EnableExperimentalNs(bool enable) OVERRIDE; |
| 62 | virtual bool experimental_ns_enabled() const OVERRIDE { |
| 63 | return false; |
| 64 | } |
pbos@webrtc.org | 24add92 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 65 | virtual int set_sample_rate_hz(int rate) OVERRIDE; |
| 66 | virtual int sample_rate_hz() const OVERRIDE; |
| 67 | virtual int set_num_channels(int input_channels, |
| 68 | int output_channels) OVERRIDE; |
| 69 | virtual int num_input_channels() const OVERRIDE; |
| 70 | virtual int num_output_channels() const OVERRIDE; |
| 71 | virtual int set_num_reverse_channels(int channels) OVERRIDE; |
| 72 | virtual int num_reverse_channels() const OVERRIDE; |
| 73 | virtual int ProcessStream(AudioFrame* frame) OVERRIDE; |
| 74 | virtual int AnalyzeReverseStream(AudioFrame* frame) OVERRIDE; |
| 75 | virtual int set_stream_delay_ms(int delay) OVERRIDE; |
| 76 | virtual int stream_delay_ms() const OVERRIDE; |
| 77 | virtual void set_delay_offset_ms(int offset) OVERRIDE; |
| 78 | virtual int delay_offset_ms() const OVERRIDE; |
| 79 | virtual int StartDebugRecording( |
| 80 | const char filename[kMaxFilenameSize]) OVERRIDE; |
henrikg@webrtc.org | 7b72264 | 2013-12-06 16:05:17 +0000 | [diff] [blame] | 81 | virtual int StartDebugRecording(FILE* handle) OVERRIDE; |
pbos@webrtc.org | 24add92 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 82 | virtual int StopDebugRecording() OVERRIDE; |
| 83 | virtual EchoCancellation* echo_cancellation() const OVERRIDE; |
| 84 | virtual EchoControlMobile* echo_control_mobile() const OVERRIDE; |
| 85 | virtual GainControl* gain_control() const OVERRIDE; |
| 86 | virtual HighPassFilter* high_pass_filter() const OVERRIDE; |
| 87 | virtual LevelEstimator* level_estimator() const OVERRIDE; |
| 88 | virtual NoiseSuppression* noise_suppression() const OVERRIDE; |
| 89 | virtual VoiceDetection* voice_detection() const OVERRIDE; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 90 | |
| 91 | // Module methods. |
pbos@webrtc.org | 24add92 | 2013-08-02 11:44:11 +0000 | [diff] [blame] | 92 | virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 93 | |
andrew@webrtc.org | e95dc25 | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 94 | protected: |
| 95 | virtual int InitializeLocked(); |
| 96 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 97 | private: |
andrew@webrtc.org | e95dc25 | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 98 | int MaybeInitializeLocked(int sample_rate_hz, int num_input_channels, |
| 99 | int num_output_channels, int num_reverse_channels); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 100 | bool is_data_processed() const; |
| 101 | bool interleave_needed(bool is_data_processed) const; |
| 102 | bool synthesis_needed(bool is_data_processed) const; |
| 103 | bool analysis_needed(bool is_data_processed) const; |
| 104 | |
andrew@webrtc.org | 25613ea | 2013-07-25 18:28:29 +0000 | [diff] [blame] | 105 | EchoCancellationImplWrapper* echo_cancellation_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 106 | EchoControlMobileImpl* echo_control_mobile_; |
| 107 | GainControlImpl* gain_control_; |
| 108 | HighPassFilterImpl* high_pass_filter_; |
| 109 | LevelEstimatorImpl* level_estimator_; |
| 110 | NoiseSuppressionImpl* noise_suppression_; |
| 111 | VoiceDetectionImpl* voice_detection_; |
| 112 | |
| 113 | std::list<ProcessingComponent*> component_list_; |
| 114 | CriticalSectionWrapper* crit_; |
| 115 | AudioBuffer* render_audio_; |
| 116 | AudioBuffer* capture_audio_; |
| 117 | #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 118 | // TODO(andrew): make this more graceful. Ideally we would split this stuff |
| 119 | // out into a separate class with an "enabled" and "disabled" implementation. |
| 120 | int WriteMessageToDebugFile(); |
| 121 | int WriteInitMessage(); |
| 122 | scoped_ptr<FileWrapper> debug_file_; |
andrew@webrtc.org | e95dc25 | 2014-01-07 17:45:09 +0000 | [diff] [blame] | 123 | scoped_ptr<audioproc::Event> event_msg_; // Protobuf message. |
| 124 | std::string event_str_; // Memory for protobuf serialization. |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 125 | #endif |
| 126 | |
| 127 | int sample_rate_hz_; |
| 128 | int split_sample_rate_hz_; |
| 129 | int samples_per_channel_; |
| 130 | int stream_delay_ms_; |
| 131 | int delay_offset_ms_; |
| 132 | bool was_stream_delay_set_; |
| 133 | |
| 134 | int num_reverse_channels_; |
| 135 | int num_input_channels_; |
| 136 | int num_output_channels_; |
| 137 | }; |
| 138 | } // namespace webrtc |
| 139 | |
| 140 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_ |