1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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 
11 #ifndef MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_
12 #define MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include <memory>
18 #include <vector>
19 
20 #include "api/array_view.h"
21 
22 namespace webrtc {
23 
24 class AudioBuffer;
25 
26 // The acoustic echo control for mobile (AECM) component is a low complexity
27 // robust option intended for use on mobile devices.
28 class EchoControlMobileImpl {
29  public:
30   EchoControlMobileImpl();
31 
32   ~EchoControlMobileImpl();
33 
34   // 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 
55   void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio);
56   int ProcessCaptureAudio(AudioBuffer* audio, int stream_delay_ms);
57 
58   void Initialize(int sample_rate_hz,
59                   size_t num_reverse_channels,
60                   size_t num_output_channels);
61 
62   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);
69 
70  private:
71   class Canceller;
72   struct StreamProperties;
73 
74   int Configure();
75 
76   RoutingMode routing_mode_;
77   bool comfort_noise_enabled_;
78 
79   std::vector<std::unique_ptr<Canceller>> cancellers_;
80   std::unique_ptr<StreamProperties> stream_properties_;
81   std::vector<std::array<int16_t, 160>> low_pass_reference_;
82   bool reference_copied_ = false;
83 };
84 }  // namespace webrtc
85 
86 #endif  // MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_IMPL_H_
87