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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 16 | #include <memory> |
terelius | 85fa7d5 | 2016-03-24 01:51:52 -0700 | [diff] [blame] | 17 | #include <vector> |
kwiberg | 88788ad | 2016-02-19 07:04:49 -0800 | [diff] [blame] | 18 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 19 | #include "api/array_view.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; |
| 24 | |
saza | be490b2 | 2018-10-03 17:03:13 +0200 | [diff] [blame] | 25 | // The acoustic echo control for mobile (AECM) component is a low complexity |
| 26 | // robust option intended for use on mobile devices. |
Sam Zackrisson | 8c147b6 | 2018-09-28 12:40:47 +0200 | [diff] [blame] | 27 | class EchoControlMobileImpl { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | public: |
Sam Zackrisson | c22f551 | 2018-11-05 16:10:00 +0100 | [diff] [blame] | 29 | EchoControlMobileImpl(); |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 30 | |
Sam Zackrisson | 8c147b6 | 2018-09-28 12:40:47 +0200 | [diff] [blame] | 31 | ~EchoControlMobileImpl(); |
| 32 | |
| 33 | int Enable(bool enable); |
| 34 | bool is_enabled() const; |
| 35 | |
| 36 | // Recommended settings for particular audio routes. In general, the louder |
| 37 | // the echo is expected to be, the higher this value should be set. The |
| 38 | // preferred setting may vary from device to device. |
| 39 | enum RoutingMode { |
| 40 | kQuietEarpieceOrHeadset, |
| 41 | kEarpiece, |
| 42 | kLoudEarpiece, |
| 43 | kSpeakerphone, |
| 44 | kLoudSpeakerphone |
| 45 | }; |
| 46 | |
| 47 | // Sets echo control appropriate for the audio routing |mode| on the device. |
| 48 | // It can and should be updated during a call if the audio routing changes. |
| 49 | int set_routing_mode(RoutingMode mode); |
| 50 | RoutingMode routing_mode() const; |
| 51 | |
| 52 | // Comfort noise replaces suppressed background noise to maintain a |
| 53 | // consistent signal level. |
| 54 | int enable_comfort_noise(bool enable); |
| 55 | bool is_comfort_noise_enabled() const; |
| 56 | |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 57 | void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio); |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 58 | int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 60 | void Initialize(int sample_rate_hz, |
| 61 | size_t num_reverse_channels, |
| 62 | size_t num_output_channels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
peah | a062460 | 2016-10-25 04:45:24 -0700 | [diff] [blame] | 64 | static void PackRenderAudioBuffer(const AudioBuffer* audio, |
| 65 | size_t num_output_channels, |
| 66 | size_t num_channels, |
| 67 | std::vector<int16_t>* packed_buffer); |
| 68 | |
| 69 | static size_t NumCancellersRequired(size_t num_output_channels, |
| 70 | size_t num_reverse_channels); |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 71 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | private: |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 73 | class Canceller; |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 74 | struct StreamProperties; |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 75 | |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 76 | int Configure(); |
peah | fa6228e | 2015-11-16 16:27:42 -0800 | [diff] [blame] | 77 | |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 78 | bool enabled_ = false; |
| 79 | |
Sam Zackrisson | c22f551 | 2018-11-05 16:10:00 +0100 | [diff] [blame] | 80 | RoutingMode routing_mode_; |
| 81 | bool comfort_noise_enabled_; |
peah | df3efa8 | 2015-11-28 12:35:15 -0800 | [diff] [blame] | 82 | |
peah | bb9edbd | 2016-03-10 12:54:25 -0800 | [diff] [blame] | 83 | std::vector<std::unique_ptr<Canceller>> cancellers_; |
peah | 253534d | 2016-03-15 04:32:28 -0700 | [diff] [blame] | 84 | std::unique_ptr<StreamProperties> stream_properties_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | }; |
| 86 | } // namespace webrtc |
| 87 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 88 | #endif // MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_ |