blob: d84a15ef05600623f7640480c3290db2627113ef [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
bjornv@webrtc.org0c6f9312012-01-30 09:39:08 +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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_
12#define MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
kwiberg88788ad2016-02-19 07:04:49 -080017#include <memory>
terelius85fa7d52016-03-24 01:51:52 -070018#include <vector>
kwiberg88788ad2016-02-19 07:04:49 -080019
Yves Gerey988cc082018-10-23 12:03:01 +020020#include "api/array_view.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
22namespace webrtc {
andrew@webrtc.org56e4a052014-02-27 22:23:17 +000023
niklase@google.com470e71d2011-07-07 08:21:25 +000024class AudioBuffer;
25
sazabe490b22018-10-03 17:03:13 +020026// The acoustic echo control for mobile (AECM) component is a low complexity
27// robust option intended for use on mobile devices.
Sam Zackrisson8c147b62018-09-28 12:40:47 +020028class EchoControlMobileImpl {
niklase@google.com470e71d2011-07-07 08:21:25 +000029 public:
Sam Zackrissonc22f5512018-11-05 16:10:00 +010030 EchoControlMobileImpl();
peahdf3efa82015-11-28 12:35:15 -080031
Sam Zackrisson8c147b62018-09-28 12:40:47 +020032 ~EchoControlMobileImpl();
33
Sam Zackrisson8c147b62018-09-28 12:40:47 +020034 // Recommended settings for particular audio routes. In general, the louder
35 // the echo is expected to be, the higher this value should be set. The
36 // preferred setting may vary from device to device.
37 enum RoutingMode {
38 kQuietEarpieceOrHeadset,
39 kEarpiece,
40 kLoudEarpiece,
41 kSpeakerphone,
42 kLoudSpeakerphone
43 };
44
45 // Sets echo control appropriate for the audio routing |mode| on the device.
46 // It can and should be updated during a call if the audio routing changes.
47 int set_routing_mode(RoutingMode mode);
48 RoutingMode routing_mode() const;
49
50 // Comfort noise replaces suppressed background noise to maintain a
51 // consistent signal level.
52 int enable_comfort_noise(bool enable);
53 bool is_comfort_noise_enabled() const;
54
peaha0624602016-10-25 04:45:24 -070055 void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio);
peah253534d2016-03-15 04:32:28 -070056 int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000057
peah253534d2016-03-15 04:32:28 -070058 void Initialize(int sample_rate_hz,
59 size_t num_reverse_channels,
60 size_t num_output_channels);
niklase@google.com470e71d2011-07-07 08:21:25 +000061
peaha0624602016-10-25 04:45:24 -070062 static void PackRenderAudioBuffer(const AudioBuffer* audio,
63 size_t num_output_channels,
64 size_t num_channels,
65 std::vector<int16_t>* packed_buffer);
66
67 static size_t NumCancellersRequired(size_t num_output_channels,
68 size_t num_reverse_channels);
peahfa6228e2015-11-16 16:27:42 -080069
niklase@google.com470e71d2011-07-07 08:21:25 +000070 private:
peahbb9edbd2016-03-10 12:54:25 -080071 class Canceller;
peah253534d2016-03-15 04:32:28 -070072 struct StreamProperties;
peahbb9edbd2016-03-10 12:54:25 -080073
peahbb9edbd2016-03-10 12:54:25 -080074 int Configure();
peahfa6228e2015-11-16 16:27:42 -080075
Sam Zackrissonc22f5512018-11-05 16:10:00 +010076 RoutingMode routing_mode_;
77 bool comfort_noise_enabled_;
peahdf3efa82015-11-28 12:35:15 -080078
peahbb9edbd2016-03-10 12:54:25 -080079 std::vector<std::unique_ptr<Canceller>> cancellers_;
peah253534d2016-03-15 04:32:28 -070080 std::unique_ptr<StreamProperties> stream_properties_;
niklase@google.com470e71d2011-07-07 08:21:25 +000081};
82} // namespace webrtc
83
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020084#endif // MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_