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