• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2011 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_AEC_MAIN_INTERFACE_ECHO_CANCELLATION_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_MAIN_INTERFACE_ECHO_CANCELLATION_H_
13 
14 #include "typedefs.h"
15 
16 // Errors
17 #define AEC_UNSPECIFIED_ERROR           12000
18 #define AEC_UNSUPPORTED_FUNCTION_ERROR  12001
19 #define AEC_UNINITIALIZED_ERROR         12002
20 #define AEC_NULL_POINTER_ERROR          12003
21 #define AEC_BAD_PARAMETER_ERROR         12004
22 
23 // Warnings
24 #define AEC_BAD_PARAMETER_WARNING       12050
25 
26 enum {
27     kAecNlpConservative = 0,
28     kAecNlpModerate,
29     kAecNlpAggressive
30 };
31 
32 enum {
33     kAecFalse = 0,
34     kAecTrue
35 };
36 
37 typedef struct {
38     WebRtc_Word16 nlpMode;        // default kAecNlpModerate
39     WebRtc_Word16 skewMode;       // default kAecFalse
40     WebRtc_Word16 metricsMode;    // default kAecFalse
41     //float realSkew;
42 } AecConfig;
43 
44 typedef struct {
45     WebRtc_Word16 instant;
46     WebRtc_Word16 average;
47     WebRtc_Word16 max;
48     WebRtc_Word16 min;
49 } AecLevel;
50 
51 typedef struct {
52     AecLevel rerl;
53     AecLevel erl;
54     AecLevel erle;
55     AecLevel aNlp;
56 } AecMetrics;
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 /*
63  * Allocates the memory needed by the AEC. The memory needs to be initialized
64  * separately using the WebRtcAec_Init() function.
65  *
66  * Inputs                       Description
67  * -------------------------------------------------------------------
68  * void **aecInst               Pointer to the AEC instance to be created
69  *                              and initilized
70  *
71  * Outputs                      Description
72  * -------------------------------------------------------------------
73  * WebRtc_Word32 return          0: OK
74  *                              -1: error
75  */
76 WebRtc_Word32 WebRtcAec_Create(void **aecInst);
77 
78 /*
79  * This function releases the memory allocated by WebRtcAec_Create().
80  *
81  * Inputs                       Description
82  * -------------------------------------------------------------------
83  * void         *aecInst        Pointer to the AEC instance
84  *
85  * Outputs                      Description
86  * -------------------------------------------------------------------
87  * WebRtc_Word32  return         0: OK
88  *                              -1: error
89  */
90 WebRtc_Word32 WebRtcAec_Free(void *aecInst);
91 
92 /*
93  * Initializes an AEC instance.
94  *
95  * Inputs                       Description
96  * -------------------------------------------------------------------
97  * void           *aecInst      Pointer to the AEC instance
98  * WebRtc_Word32  sampFreq      Sampling frequency of data
99  * WebRtc_Word32  scSampFreq    Soundcard sampling frequency
100  *
101  * Outputs                      Description
102  * -------------------------------------------------------------------
103  * WebRtc_Word32 return          0: OK
104  *                              -1: error
105  */
106 WebRtc_Word32 WebRtcAec_Init(void *aecInst,
107                              WebRtc_Word32 sampFreq,
108                              WebRtc_Word32 scSampFreq);
109 
110 /*
111  * Inserts an 80 or 160 sample block of data into the farend buffer.
112  *
113  * Inputs                       Description
114  * -------------------------------------------------------------------
115  * void           *aecInst      Pointer to the AEC instance
116  * WebRtc_Word16  *farend       In buffer containing one frame of
117  *                              farend signal for L band
118  * WebRtc_Word16  nrOfSamples   Number of samples in farend buffer
119  *
120  * Outputs                      Description
121  * -------------------------------------------------------------------
122  * WebRtc_Word32  return         0: OK
123  *                              -1: error
124  */
125 WebRtc_Word32 WebRtcAec_BufferFarend(void *aecInst,
126                                      const WebRtc_Word16 *farend,
127                                      WebRtc_Word16 nrOfSamples);
128 
129 /*
130  * Runs the echo canceller on an 80 or 160 sample blocks of data.
131  *
132  * Inputs                       Description
133  * -------------------------------------------------------------------
134  * void          *aecInst       Pointer to the AEC instance
135  * WebRtc_Word16 *nearend       In buffer containing one frame of
136  *                              nearend+echo signal for L band
137  * WebRtc_Word16 *nearendH      In buffer containing one frame of
138  *                              nearend+echo signal for H band
139  * WebRtc_Word16 nrOfSamples    Number of samples in nearend buffer
140  * WebRtc_Word16 msInSndCardBuf Delay estimate for sound card and
141  *                              system buffers
142  * WebRtc_Word16 skew           Difference between number of samples played
143  *                              and recorded at the soundcard (for clock skew
144  *                              compensation)
145  *
146  * Outputs                      Description
147  * -------------------------------------------------------------------
148  * WebRtc_Word16  *out          Out buffer, one frame of processed nearend
149  *                              for L band
150  * WebRtc_Word16  *outH         Out buffer, one frame of processed nearend
151  *                              for H band
152  * WebRtc_Word32  return         0: OK
153  *                              -1: error
154  */
155 WebRtc_Word32 WebRtcAec_Process(void *aecInst,
156                                 const WebRtc_Word16 *nearend,
157                                 const WebRtc_Word16 *nearendH,
158                                 WebRtc_Word16 *out,
159                                 WebRtc_Word16 *outH,
160                                 WebRtc_Word16 nrOfSamples,
161                                 WebRtc_Word16 msInSndCardBuf,
162                                 WebRtc_Word32 skew);
163 
164 /*
165  * This function enables the user to set certain parameters on-the-fly.
166  *
167  * Inputs                       Description
168  * -------------------------------------------------------------------
169  * void           *aecInst      Pointer to the AEC instance
170  * AecConfig      config        Config instance that contains all
171  *                              properties to be set
172  *
173  * Outputs                      Description
174  * -------------------------------------------------------------------
175  * WebRtc_Word32  return         0: OK
176  *                              -1: error
177  */
178 WebRtc_Word32 WebRtcAec_set_config(void *aecInst, AecConfig config);
179 
180 /*
181  * Gets the on-the-fly paramters.
182  *
183  * Inputs                       Description
184  * -------------------------------------------------------------------
185  * void           *aecInst      Pointer to the AEC instance
186  *
187  * Outputs                      Description
188  * -------------------------------------------------------------------
189  * AecConfig      *config       Pointer to the config instance that
190  *                              all properties will be written to
191  * WebRtc_Word32  return         0: OK
192  *                              -1: error
193  */
194 WebRtc_Word32 WebRtcAec_get_config(void *aecInst, AecConfig *config);
195 
196 /*
197  * Gets the current echo status of the nearend signal.
198  *
199  * Inputs                       Description
200  * -------------------------------------------------------------------
201  * void           *aecInst      Pointer to the AEC instance
202  *
203  * Outputs                      Description
204  * -------------------------------------------------------------------
205  * WebRtc_Word16  *status       0: Almost certainly nearend single-talk
206  *                              1: Might not be neared single-talk
207  * WebRtc_Word32  return         0: OK
208  *                              -1: error
209  */
210 WebRtc_Word32 WebRtcAec_get_echo_status(void *aecInst, WebRtc_Word16 *status);
211 
212 /*
213  * Gets the current echo metrics for the session.
214  *
215  * Inputs                       Description
216  * -------------------------------------------------------------------
217  * void           *aecInst      Pointer to the AEC instance
218  *
219  * Outputs                      Description
220  * -------------------------------------------------------------------
221  * AecMetrics     *metrics      Struct which will be filled out with the
222  *                              current echo metrics.
223  * WebRtc_Word32  return         0: OK
224  *                              -1: error
225  */
226 WebRtc_Word32 WebRtcAec_GetMetrics(void *aecInst, AecMetrics *metrics);
227 
228 /*
229  * Gets the last error code.
230  *
231  * Inputs                       Description
232  * -------------------------------------------------------------------
233  * void           *aecInst      Pointer to the AEC instance
234  *
235  * Outputs                      Description
236  * -------------------------------------------------------------------
237  * WebRtc_Word32  return        11000-11100: error code
238  */
239 WebRtc_Word32 WebRtcAec_get_error_code(void *aecInst);
240 
241 /*
242  * Gets a version string.
243  *
244  * Inputs                       Description
245  * -------------------------------------------------------------------
246  * char           *versionStr   Pointer to a string array
247  * WebRtc_Word16  len           The maximum length of the string
248  *
249  * Outputs                      Description
250  * -------------------------------------------------------------------
251  * WebRtc_Word8   *versionStr   Pointer to a string array
252  * WebRtc_Word32  return         0: OK
253  *                              -1: error
254  */
255 WebRtc_Word32 WebRtcAec_get_version(WebRtc_Word8 *versionStr, WebRtc_Word16 len);
256 
257 #ifdef __cplusplus
258 }
259 #endif
260 #endif  /* WEBRTC_MODULES_AUDIO_PROCESSING_AEC_MAIN_INTERFACE_ECHO_CANCELLATION_H_ */
261