• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_AECM_ECHO_CONTROL_MOBILE_H_
12 #define MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 namespace webrtc {
18 
19 enum { AecmFalse = 0, AecmTrue };
20 
21 // Errors
22 #define AECM_UNSPECIFIED_ERROR 12000
23 #define AECM_UNSUPPORTED_FUNCTION_ERROR 12001
24 #define AECM_UNINITIALIZED_ERROR 12002
25 #define AECM_NULL_POINTER_ERROR 12003
26 #define AECM_BAD_PARAMETER_ERROR 12004
27 
28 // Warnings
29 #define AECM_BAD_PARAMETER_WARNING 12100
30 
31 typedef struct {
32   int16_t cngMode;   // AECM_FALSE, AECM_TRUE (default)
33   int16_t echoMode;  // 0, 1, 2, 3 (default), 4
34 } AecmConfig;
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * Allocates the memory needed by the AECM. The memory needs to be
42  * initialized separately using the WebRtcAecm_Init() function.
43  * Returns a pointer to the instance and a nullptr at failure.
44  */
45 void* WebRtcAecm_Create();
46 
47 /*
48  * This function releases the memory allocated by WebRtcAecm_Create()
49  *
50  * Inputs                       Description
51  * -------------------------------------------------------------------
52  * void*    aecmInst            Pointer to the AECM instance
53  */
54 void WebRtcAecm_Free(void* aecmInst);
55 
56 /*
57  * Initializes an AECM instance.
58  *
59  * Inputs                       Description
60  * -------------------------------------------------------------------
61  * void*          aecmInst      Pointer to the AECM instance
62  * int32_t        sampFreq      Sampling frequency of data
63  *
64  * Outputs                      Description
65  * -------------------------------------------------------------------
66  * int32_t        return        0: OK
67  *                              1200-12004,12100: error/warning
68  */
69 int32_t WebRtcAecm_Init(void* aecmInst, int32_t sampFreq);
70 
71 /*
72  * Inserts an 80 or 160 sample block of data into the farend buffer.
73  *
74  * Inputs                       Description
75  * -------------------------------------------------------------------
76  * void*          aecmInst      Pointer to the AECM instance
77  * int16_t*       farend        In buffer containing one frame of
78  *                              farend signal
79  * int16_t        nrOfSamples   Number of samples in farend buffer
80  *
81  * Outputs                      Description
82  * -------------------------------------------------------------------
83  * int32_t        return        0: OK
84  *                              1200-12004,12100: error/warning
85  */
86 int32_t WebRtcAecm_BufferFarend(void* aecmInst,
87                                 const int16_t* farend,
88                                 size_t nrOfSamples);
89 
90 /*
91  * Reports any errors that would arise when buffering a farend buffer.
92  *
93  * Inputs                       Description
94  * -------------------------------------------------------------------
95  * void*          aecmInst      Pointer to the AECM instance
96  * int16_t*       farend        In buffer containing one frame of
97  *                              farend signal
98  * int16_t        nrOfSamples   Number of samples in farend buffer
99  *
100  * Outputs                      Description
101  * -------------------------------------------------------------------
102  * int32_t        return        0: OK
103  *                              1200-12004,12100: error/warning
104  */
105 int32_t WebRtcAecm_GetBufferFarendError(void* aecmInst,
106                                         const int16_t* farend,
107                                         size_t nrOfSamples);
108 
109 /*
110  * Runs the AECM on an 80 or 160 sample blocks of data.
111  *
112  * Inputs                        Description
113  * -------------------------------------------------------------------
114  * void*          aecmInst       Pointer to the AECM instance
115  * int16_t*       nearendNoisy   In buffer containing one frame of
116  *                               reference nearend+echo signal. If
117  *                               noise reduction is active, provide
118  *                               the noisy signal here.
119  * int16_t*       nearendClean   In buffer containing one frame of
120  *                               nearend+echo signal. If noise
121  *                               reduction is active, provide the
122  *                               clean signal here. Otherwise pass a
123  *                               NULL pointer.
124  * int16_t        nrOfSamples    Number of samples in nearend buffer
125  * int16_t        msInSndCardBuf Delay estimate for sound card and
126  *                               system buffers
127  *
128  * Outputs                       Description
129  * -------------------------------------------------------------------
130  * int16_t*       out            Out buffer, one frame of processed nearend
131  * int32_t        return         0: OK
132  *                               1200-12004,12100: error/warning
133  */
134 int32_t WebRtcAecm_Process(void* aecmInst,
135                            const int16_t* nearendNoisy,
136                            const int16_t* nearendClean,
137                            int16_t* out,
138                            size_t nrOfSamples,
139                            int16_t msInSndCardBuf);
140 
141 /*
142  * This function enables the user to set certain parameters on-the-fly
143  *
144  * Inputs                       Description
145  * -------------------------------------------------------------------
146  * void*          aecmInst      Pointer to the AECM instance
147  * AecmConfig     config        Config instance that contains all
148  *                              properties to be set
149  *
150  * Outputs                      Description
151  * -------------------------------------------------------------------
152  * int32_t        return        0: OK
153  *                              1200-12004,12100: error/warning
154  */
155 int32_t WebRtcAecm_set_config(void* aecmInst, AecmConfig config);
156 
157 /*
158  * This function enables the user to set the echo path on-the-fly.
159  *
160  * Inputs                       Description
161  * -------------------------------------------------------------------
162  * void*        aecmInst        Pointer to the AECM instance
163  * void*        echo_path       Pointer to the echo path to be set
164  * size_t       size_bytes      Size in bytes of the echo path
165  *
166  * Outputs                      Description
167  * -------------------------------------------------------------------
168  * int32_t      return          0: OK
169  *                              1200-12004,12100: error/warning
170  */
171 int32_t WebRtcAecm_InitEchoPath(void* aecmInst,
172                                 const void* echo_path,
173                                 size_t size_bytes);
174 
175 /*
176  * This function enables the user to get the currently used echo path
177  * on-the-fly
178  *
179  * Inputs                       Description
180  * -------------------------------------------------------------------
181  * void*        aecmInst        Pointer to the AECM instance
182  * void*        echo_path       Pointer to echo path
183  * size_t       size_bytes      Size in bytes of the echo path
184  *
185  * Outputs                      Description
186  * -------------------------------------------------------------------
187  * int32_t      return          0: OK
188  *                              1200-12004,12100: error/warning
189  */
190 int32_t WebRtcAecm_GetEchoPath(void* aecmInst,
191                                void* echo_path,
192                                size_t size_bytes);
193 
194 /*
195  * This function enables the user to get the echo path size in bytes
196  *
197  * Outputs                      Description
198  * -------------------------------------------------------------------
199  * size_t       return          Size in bytes
200  */
201 size_t WebRtcAecm_echo_path_size_bytes();
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 }  // namespace webrtc
208 
209 #endif  // MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_
210