niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +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 | |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
| 14 | #include <vector> |
| 15 | |
peah | 4d291f7 | 2015-11-16 23:52:25 -0800 | [diff] [blame] | 16 | #include "webrtc/base/scoped_ptr.h" |
| 17 | #include "webrtc/common_audio/swap_queue.h" |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 19 | #include "webrtc/modules/audio_processing/processing_component.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 22 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | class AudioBuffer; |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 24 | class CriticalSectionWrapper; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
| 26 | class GainControlImpl : public GainControl, |
| 27 | public ProcessingComponent { |
| 28 | public: |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 29 | GainControlImpl(const AudioProcessing* apm, |
| 30 | CriticalSectionWrapper* crit); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | virtual ~GainControlImpl(); |
| 32 | |
| 33 | int ProcessRenderAudio(AudioBuffer* audio); |
| 34 | int AnalyzeCaptureAudio(AudioBuffer* audio); |
| 35 | int ProcessCaptureAudio(AudioBuffer* audio); |
| 36 | |
| 37 | // ProcessingComponent implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 38 | int Initialize() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
| 40 | // GainControl implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 41 | bool is_enabled() const override; |
| 42 | int stream_analog_level() override; |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 43 | bool is_limiter_enabled() const override; |
| 44 | Mode mode() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
peah | 4d291f7 | 2015-11-16 23:52:25 -0800 | [diff] [blame] | 46 | // Reads render side data that has been queued on the render call. |
| 47 | void ReadQueuedRenderData(); |
| 48 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | private: |
| 50 | // GainControl implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 51 | int Enable(bool enable) override; |
| 52 | int set_stream_analog_level(int level) override; |
| 53 | int set_mode(Mode mode) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 54 | int set_target_level_dbfs(int level) override; |
| 55 | int target_level_dbfs() const override; |
| 56 | int set_compression_gain_db(int gain) override; |
| 57 | int compression_gain_db() const override; |
| 58 | int enable_limiter(bool enable) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 59 | int set_analog_level_limits(int minimum, int maximum) override; |
| 60 | int analog_level_minimum() const override; |
| 61 | int analog_level_maximum() const override; |
| 62 | bool stream_is_saturated() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
| 64 | // ProcessingComponent implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 65 | void* CreateHandle() const override; |
| 66 | int InitializeHandle(void* handle) const override; |
| 67 | int ConfigureHandle(void* handle) const override; |
| 68 | void DestroyHandle(void* handle) const override; |
| 69 | int num_handles_required() const override; |
| 70 | int GetHandleError(void* handle) const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | |
peah | 4d291f7 | 2015-11-16 23:52:25 -0800 | [diff] [blame] | 72 | void AllocateRenderQueue(); |
| 73 | |
andrew@webrtc.org | 56e4a05 | 2014-02-27 22:23:17 +0000 | [diff] [blame] | 74 | const AudioProcessing* apm_; |
| 75 | CriticalSectionWrapper* crit_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | Mode mode_; |
| 77 | int minimum_capture_level_; |
| 78 | int maximum_capture_level_; |
| 79 | bool limiter_enabled_; |
| 80 | int target_level_dbfs_; |
| 81 | int compression_gain_db_; |
| 82 | std::vector<int> capture_levels_; |
| 83 | int analog_capture_level_; |
| 84 | bool was_analog_level_set_; |
| 85 | bool stream_is_saturated_; |
peah | 4d291f7 | 2015-11-16 23:52:25 -0800 | [diff] [blame] | 86 | |
| 87 | size_t render_queue_element_max_size_; |
| 88 | std::vector<int16_t> render_queue_buffer_; |
| 89 | std::vector<int16_t> capture_queue_buffer_; |
| 90 | rtc::scoped_ptr< |
| 91 | SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>> |
| 92 | render_signal_queue_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | }; |
| 94 | } // namespace webrtc |
| 95 | |
bjornv@webrtc.org | 0c6f931 | 2012-01-30 09:39:08 +0000 | [diff] [blame] | 96 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_ |