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