niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | b9d7d93 | 2012-01-25 19:21:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Henrik Kjellander | 9b72af9 | 2015-11-11 20:16:11 +0100 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 16 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
peah | 50e21bd | 2016-03-05 08:39:21 -0800 | [diff] [blame^] | 18 | namespace webrtc { |
| 19 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | // Errors |
andrew@webrtc.org | 13b2d46 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 21 | #define AEC_UNSPECIFIED_ERROR 12000 |
| 22 | #define AEC_UNSUPPORTED_FUNCTION_ERROR 12001 |
| 23 | #define AEC_UNINITIALIZED_ERROR 12002 |
| 24 | #define AEC_NULL_POINTER_ERROR 12003 |
| 25 | #define AEC_BAD_PARAMETER_ERROR 12004 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
| 27 | // Warnings |
andrew@webrtc.org | 13b2d46 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 28 | #define AEC_BAD_PARAMETER_WARNING 12050 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | |
peah | ff63ed2 | 2016-01-29 07:46:13 -0800 | [diff] [blame] | 30 | enum { kAecNlpConservative = 0, kAecNlpModerate, kAecNlpAggressive }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | |
peah | ff63ed2 | 2016-01-29 07:46:13 -0800 | [diff] [blame] | 32 | enum { kAecFalse = 0, kAecTrue }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
| 34 | typedef struct { |
andrew@webrtc.org | 13b2d46 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 35 | int16_t nlpMode; // default kAecNlpModerate |
| 36 | int16_t skewMode; // default kAecFalse |
| 37 | int16_t metricsMode; // default kAecFalse |
| 38 | int delay_logging; // default kAecFalse |
| 39 | // float realSkew; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | } AecConfig; |
| 41 | |
| 42 | typedef struct { |
bjornv@webrtc.org | b4cd342 | 2013-02-15 18:40:34 +0000 | [diff] [blame] | 43 | int instant; |
| 44 | int average; |
| 45 | int max; |
| 46 | int min; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | } AecLevel; |
| 48 | |
| 49 | typedef struct { |
andrew@webrtc.org | 13b2d46 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 50 | AecLevel rerl; |
| 51 | AecLevel erl; |
| 52 | AecLevel erle; |
| 53 | AecLevel aNlp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | } AecMetrics; |
| 55 | |
bjornv@webrtc.org | 132c15d | 2013-02-27 21:03:41 +0000 | [diff] [blame] | 56 | struct AecCore; |
| 57 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | /* |
| 59 | * Allocates the memory needed by the AEC. The memory needs to be initialized |
Bjorn Volcker | 9345e86 | 2015-06-10 21:43:36 +0200 | [diff] [blame] | 60 | * separately using the WebRtcAec_Init() function. Returns a pointer to the |
| 61 | * object or NULL on error. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | */ |
Bjorn Volcker | 9345e86 | 2015-06-10 21:43:36 +0200 | [diff] [blame] | 63 | void* WebRtcAec_Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * This function releases the memory allocated by WebRtcAec_Create(). |
| 67 | * |
| 68 | * Inputs Description |
| 69 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 70 | * void* aecInst Pointer to the AEC instance |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | */ |
Bjorn Volcker | f6a99e6 | 2015-04-10 07:56:57 +0200 | [diff] [blame] | 72 | void WebRtcAec_Free(void* aecInst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * Initializes an AEC instance. |
| 76 | * |
| 77 | * Inputs Description |
| 78 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 79 | * void* aecInst Pointer to the AEC instance |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 80 | * int32_t sampFreq Sampling frequency of data |
| 81 | * int32_t scSampFreq Soundcard sampling frequency |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | * |
| 83 | * Outputs Description |
| 84 | * ------------------------------------------------------------------- |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 85 | * int32_t return 0: OK |
| 86 | * -1: error |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | */ |
andrew@webrtc.org | 13b2d46 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 88 | int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Inserts an 80 or 160 sample block of data into the farend buffer. |
| 92 | * |
| 93 | * Inputs Description |
| 94 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 95 | * void* aecInst Pointer to the AEC instance |
kwiberg@webrtc.org | 38214d5 | 2014-07-03 09:47:33 +0000 | [diff] [blame] | 96 | * const float* farend In buffer containing one frame of |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | * farend signal for L band |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 98 | * int16_t nrOfSamples Number of samples in farend buffer |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | * |
| 100 | * Outputs Description |
| 101 | * ------------------------------------------------------------------- |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 102 | * int32_t return 0: OK |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 103 | * 12000-12050: error code |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | */ |
andrew@webrtc.org | 13b2d46 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 105 | int32_t WebRtcAec_BufferFarend(void* aecInst, |
kwiberg@webrtc.org | 38214d5 | 2014-07-03 09:47:33 +0000 | [diff] [blame] | 106 | const float* farend, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 107 | size_t nrOfSamples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
| 109 | /* |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 110 | * Reports any errors that would arise if buffering a farend buffer |
| 111 | * |
| 112 | * Inputs Description |
| 113 | * ------------------------------------------------------------------- |
| 114 | * void* aecInst Pointer to the AEC instance |
| 115 | * const float* farend In buffer containing one frame of |
| 116 | * farend signal for L band |
| 117 | * int16_t nrOfSamples Number of samples in farend buffer |
| 118 | * |
| 119 | * Outputs Description |
| 120 | * ------------------------------------------------------------------- |
| 121 | * int32_t return 0: OK |
| 122 | * 12000-12050: error code |
| 123 | */ |
| 124 | int32_t WebRtcAec_GetBufferFarendError(void* aecInst, |
| 125 | const float* farend, |
| 126 | size_t nrOfSamples); |
| 127 | |
| 128 | /* |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | * Runs the echo canceller on an 80 or 160 sample blocks of data. |
| 130 | * |
| 131 | * Inputs Description |
| 132 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 133 | * void* aecInst Pointer to the AEC instance |
aluebs@webrtc.org | c78d81a | 2015-01-21 19:10:55 +0000 | [diff] [blame] | 134 | * float* const* nearend In buffer containing one frame of |
| 135 | * nearend+echo signal for each band |
| 136 | * int num_bands Number of bands in nearend buffer |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 137 | * int16_t nrOfSamples Number of samples in nearend buffer |
| 138 | * int16_t msInSndCardBuf Delay estimate for sound card and |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 139 | * system buffers |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 140 | * int16_t skew Difference between number of samples played |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | * and recorded at the soundcard (for clock skew |
| 142 | * compensation) |
| 143 | * |
| 144 | * Outputs Description |
| 145 | * ------------------------------------------------------------------- |
aluebs@webrtc.org | c78d81a | 2015-01-21 19:10:55 +0000 | [diff] [blame] | 146 | * float* const* out Out buffer, one frame of processed nearend |
| 147 | * for each band |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 148 | * int32_t return 0: OK |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 149 | * 12000-12050: error code |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 150 | */ |
andrew@webrtc.org | 13b2d46 | 2013-10-08 23:41:42 +0000 | [diff] [blame] | 151 | int32_t WebRtcAec_Process(void* aecInst, |
aluebs@webrtc.org | c78d81a | 2015-01-21 19:10:55 +0000 | [diff] [blame] | 152 | const float* const* nearend, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 153 | size_t num_bands, |
aluebs@webrtc.org | c78d81a | 2015-01-21 19:10:55 +0000 | [diff] [blame] | 154 | float* const* out, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 155 | size_t nrOfSamples, |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 156 | int16_t msInSndCardBuf, |
| 157 | int32_t skew); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * This function enables the user to set certain parameters on-the-fly. |
| 161 | * |
| 162 | * Inputs Description |
| 163 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 164 | * void* handle Pointer to the AEC instance |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 165 | * AecConfig config Config instance that contains all |
| 166 | * properties to be set |
| 167 | * |
| 168 | * Outputs Description |
| 169 | * ------------------------------------------------------------------- |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 170 | * int return 0: OK |
| 171 | * 12000-12050: error code |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | */ |
bjornv@webrtc.org | 47b274d | 2013-02-20 17:09:47 +0000 | [diff] [blame] | 173 | int WebRtcAec_set_config(void* handle, AecConfig config); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 174 | |
| 175 | /* |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 176 | * Gets the current echo status of the nearend signal. |
| 177 | * |
| 178 | * Inputs Description |
| 179 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 180 | * void* handle Pointer to the AEC instance |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 181 | * |
| 182 | * Outputs Description |
| 183 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 184 | * int* status 0: Almost certainly nearend single-talk |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 185 | * 1: Might not be neared single-talk |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 186 | * int return 0: OK |
| 187 | * 12000-12050: error code |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | */ |
bjornv@webrtc.org | 21a2fc9 | 2013-02-15 17:01:03 +0000 | [diff] [blame] | 189 | int WebRtcAec_get_echo_status(void* handle, int* status); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * Gets the current echo metrics for the session. |
| 193 | * |
| 194 | * Inputs Description |
| 195 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 196 | * void* handle Pointer to the AEC instance |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 197 | * |
| 198 | * Outputs Description |
| 199 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 200 | * AecMetrics* metrics Struct which will be filled out with the |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 201 | * current echo metrics. |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 202 | * int return 0: OK |
| 203 | * 12000-12050: error code |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 204 | */ |
bjornv@webrtc.org | b4cd342 | 2013-02-15 18:40:34 +0000 | [diff] [blame] | 205 | int WebRtcAec_GetMetrics(void* handle, AecMetrics* metrics); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 206 | |
| 207 | /* |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 208 | * Gets the current delay metrics for the session. |
| 209 | * |
| 210 | * Inputs Description |
| 211 | * ------------------------------------------------------------------- |
bjornv@webrtc.org | b1786db | 2015-02-03 06:06:26 +0000 | [diff] [blame] | 212 | * void* handle Pointer to the AEC instance |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 213 | * |
| 214 | * Outputs Description |
| 215 | * ------------------------------------------------------------------- |
bjornv@webrtc.org | b1786db | 2015-02-03 06:06:26 +0000 | [diff] [blame] | 216 | * int* median Delay median value. |
| 217 | * int* std Delay standard deviation. |
| 218 | * float* fraction_poor_delays Fraction of the delay estimates that may |
| 219 | * cause the AEC to perform poorly. |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 220 | * |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 221 | * int return 0: OK |
| 222 | * 12000-12050: error code |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 223 | */ |
bjornv@webrtc.org | b1786db | 2015-02-03 06:06:26 +0000 | [diff] [blame] | 224 | int WebRtcAec_GetDelayMetrics(void* handle, |
| 225 | int* median, |
| 226 | int* std, |
| 227 | float* fraction_poor_delays); |
bjornv@google.com | 1ba3dbe | 2011-10-03 08:18:10 +0000 | [diff] [blame] | 228 | |
bjornv@webrtc.org | 132c15d | 2013-02-27 21:03:41 +0000 | [diff] [blame] | 229 | // Returns a pointer to the low level AEC handle. |
| 230 | // |
| 231 | // Input: |
| 232 | // - handle : Pointer to the AEC instance. |
| 233 | // |
| 234 | // Return value: |
| 235 | // - AecCore pointer : NULL for error. |
| 236 | // |
| 237 | struct AecCore* WebRtcAec_aec_core(void* handle); |
| 238 | |
peah | 50e21bd | 2016-03-05 08:39:21 -0800 | [diff] [blame^] | 239 | } // namespace webrtc |
| 240 | |
Henrik Kjellander | 9b72af9 | 2015-11-11 20:16:11 +0100 | [diff] [blame] | 241 | #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_ECHO_CANCELLATION_H_ |