blob: 6c228781d1ea3a7db77e79db0760e8dd8b28a678 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org7fad4b82013-05-28 08:11:59 +000014#include "webrtc/modules/audio_processing/include/audio_processing.h"
andrew@webrtc.org7bf26462011-12-03 00:03:31 +000015
niklase@google.com470e71d2011-07-07 08:21:25 +000016#include <list>
ajm@google.com808e0e02011-08-03 21:08:51 +000017#include <string>
niklase@google.com470e71d2011-07-07 08:21:25 +000018
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000019#include "webrtc/system_wrappers/interface/scoped_ptr.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022class AudioBuffer;
ajm@google.com808e0e02011-08-03 21:08:51 +000023class CriticalSectionWrapper;
andrew@webrtc.org61e596f2013-07-25 18:28:29 +000024class EchoCancellationImplWrapper;
niklase@google.com470e71d2011-07-07 08:21:25 +000025class EchoControlMobileImpl;
ajm@google.com808e0e02011-08-03 21:08:51 +000026class FileWrapper;
niklase@google.com470e71d2011-07-07 08:21:25 +000027class GainControlImpl;
28class HighPassFilterImpl;
29class LevelEstimatorImpl;
30class NoiseSuppressionImpl;
31class ProcessingComponent;
32class VoiceDetectionImpl;
33
andrew@webrtc.org7bf26462011-12-03 00:03:31 +000034#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
35namespace audioproc {
36
37class Event;
38
39} // namespace audioproc
40#endif
41
niklase@google.com470e71d2011-07-07 08:21:25 +000042class 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.org91620802013-08-02 11:44:11 +000059 virtual int Initialize() OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000060 virtual int InitializeLocked();
pbos@webrtc.org91620802013-08-02 11:44:11 +000061 virtual void SetExtraOptions(const Config& config) OVERRIDE;
aluebs@webrtc.org0b72f582013-11-19 15:17:51 +000062 virtual int EnableExperimentalNs(bool enable) OVERRIDE;
63 virtual bool experimental_ns_enabled() const OVERRIDE {
64 return false;
65 }
pbos@webrtc.org91620802013-08-02 11:44:11 +000066 virtual int set_sample_rate_hz(int rate) OVERRIDE;
67 virtual int sample_rate_hz() const OVERRIDE;
68 virtual int set_num_channels(int input_channels,
69 int output_channels) OVERRIDE;
70 virtual int num_input_channels() const OVERRIDE;
71 virtual int num_output_channels() const OVERRIDE;
72 virtual int set_num_reverse_channels(int channels) OVERRIDE;
73 virtual int num_reverse_channels() const OVERRIDE;
74 virtual int ProcessStream(AudioFrame* frame) OVERRIDE;
75 virtual int AnalyzeReverseStream(AudioFrame* frame) OVERRIDE;
76 virtual int set_stream_delay_ms(int delay) OVERRIDE;
77 virtual int stream_delay_ms() const OVERRIDE;
78 virtual void set_delay_offset_ms(int offset) OVERRIDE;
79 virtual int delay_offset_ms() const OVERRIDE;
80 virtual int StartDebugRecording(
81 const char filename[kMaxFilenameSize]) OVERRIDE;
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;
niklase@google.com470e71d2011-07-07 08:21:25 +000090
91 // Module methods.
pbos@webrtc.org91620802013-08-02 11:44:11 +000092 virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000093
94 private:
andrew@webrtc.org369166a2012-04-24 18:38:03 +000095 bool is_data_processed() const;
96 bool interleave_needed(bool is_data_processed) const;
97 bool synthesis_needed(bool is_data_processed) const;
98 bool analysis_needed(bool is_data_processed) const;
ajm@google.com808e0e02011-08-03 21:08:51 +000099
niklase@google.com470e71d2011-07-07 08:21:25 +0000100 int id_;
101
andrew@webrtc.org61e596f2013-07-25 18:28:29 +0000102 EchoCancellationImplWrapper* echo_cancellation_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103 EchoControlMobileImpl* echo_control_mobile_;
104 GainControlImpl* gain_control_;
105 HighPassFilterImpl* high_pass_filter_;
106 LevelEstimatorImpl* level_estimator_;
107 NoiseSuppressionImpl* noise_suppression_;
108 VoiceDetectionImpl* voice_detection_;
109
110 std::list<ProcessingComponent*> component_list_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000111 CriticalSectionWrapper* crit_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112 AudioBuffer* render_audio_;
113 AudioBuffer* capture_audio_;
andrew@webrtc.org7bf26462011-12-03 00:03:31 +0000114#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
115 // TODO(andrew): make this more graceful. Ideally we would split this stuff
116 // out into a separate class with an "enabled" and "disabled" implementation.
117 int WriteMessageToDebugFile();
118 int WriteInitMessage();
119 scoped_ptr<FileWrapper> debug_file_;
120 scoped_ptr<audioproc::Event> event_msg_; // Protobuf message.
121 std::string event_str_; // Memory for protobuf serialization.
122#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000123
124 int sample_rate_hz_;
125 int split_sample_rate_hz_;
126 int samples_per_channel_;
127 int stream_delay_ms_;
andrew@webrtc.org6f9f8172012-03-06 19:03:39 +0000128 int delay_offset_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129 bool was_stream_delay_set_;
130
ajm@google.com808e0e02011-08-03 21:08:51 +0000131 int num_reverse_channels_;
132 int num_input_channels_;
133 int num_output_channels_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000134};
135} // namespace webrtc
136
137#endif // WEBRTC_MODULES_AUDIO_PROCESSING_MAIN_SOURCE_AUDIO_PROCESSING_IMPL_H_