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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_ |
| 12 | #define MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Niels Möller | a12c42a | 2018-07-25 16:05:48 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
Per Åhgren | be36db1 | 2020-03-20 16:45:09 +0100 | [diff] [blame] | 17 | namespace webrtc { |
| 18 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 19 | enum { AecmFalse = 0, AecmTrue }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | // Errors |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 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 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
| 28 | // Warnings |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 29 | #define AECM_BAD_PARAMETER_WARNING 12100 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | |
| 31 | typedef struct { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 32 | int16_t cngMode; // AECM_FALSE, AECM_TRUE (default) |
| 33 | int16_t echoMode; // 0, 1, 2, 3 (default), 4 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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. |
Bjorn Volcker | a743794 | 2015-05-28 15:58:42 +0200 | [diff] [blame] | 43 | * Returns a pointer to the instance and a nullptr at failure. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | */ |
Bjorn Volcker | a743794 | 2015-05-28 15:58:42 +0200 | [diff] [blame] | 45 | void* WebRtcAecm_Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * This function releases the memory allocated by WebRtcAecm_Create() |
| 49 | * |
| 50 | * Inputs Description |
| 51 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 52 | * void* aecmInst Pointer to the AECM instance |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | */ |
Bjorn Volcker | f6a99e6 | 2015-04-10 07:56:57 +0200 | [diff] [blame] | 54 | void WebRtcAecm_Free(void* aecmInst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * Initializes an AECM instance. |
| 58 | * |
| 59 | * Inputs Description |
| 60 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 61 | * void* aecmInst Pointer to the AECM instance |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 62 | * int32_t sampFreq Sampling frequency of data |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | * |
| 64 | * Outputs Description |
| 65 | * ------------------------------------------------------------------- |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 66 | * int32_t return 0: OK |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 67 | * 1200-12004,12100: error/warning |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | */ |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 69 | int32_t WebRtcAecm_Init(void* aecmInst, int32_t sampFreq); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * Inserts an 80 or 160 sample block of data into the farend buffer. |
| 73 | * |
| 74 | * Inputs Description |
| 75 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 76 | * void* aecmInst Pointer to the AECM instance |
| 77 | * int16_t* farend In buffer containing one frame of |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | * farend signal |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 79 | * int16_t nrOfSamples Number of samples in farend buffer |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | * |
| 81 | * Outputs Description |
| 82 | * ------------------------------------------------------------------- |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 83 | * int32_t return 0: OK |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 84 | * 1200-12004,12100: error/warning |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | */ |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 86 | int32_t WebRtcAecm_BufferFarend(void* aecmInst, |
| 87 | const int16_t* farend, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 88 | size_t nrOfSamples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
| 90 | /* |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 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 | /* |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | * Runs the AECM on an 80 or 160 sample blocks of data. |
| 111 | * |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 112 | * Inputs Description |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 114 | * void* aecmInst Pointer to the AECM instance |
| 115 | * int16_t* nearendNoisy In buffer containing one frame of |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | * reference nearend+echo signal. If |
| 117 | * noise reduction is active, provide |
| 118 | * the noisy signal here. |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 119 | * int16_t* nearendClean In buffer containing one frame of |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | * nearend+echo signal. If noise |
| 121 | * reduction is active, provide the |
| 122 | * clean signal here. Otherwise pass a |
| 123 | * NULL pointer. |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 124 | * int16_t nrOfSamples Number of samples in nearend buffer |
| 125 | * int16_t msInSndCardBuf Delay estimate for sound card and |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | * system buffers |
| 127 | * |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 128 | * Outputs Description |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 130 | * int16_t* out Out buffer, one frame of processed nearend |
| 131 | * int32_t return 0: OK |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 132 | * 1200-12004,12100: error/warning |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 133 | */ |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 134 | int32_t WebRtcAecm_Process(void* aecmInst, |
| 135 | const int16_t* nearendNoisy, |
| 136 | const int16_t* nearendClean, |
| 137 | int16_t* out, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 138 | size_t nrOfSamples, |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 139 | int16_t msInSndCardBuf); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * This function enables the user to set certain parameters on-the-fly |
| 143 | * |
| 144 | * Inputs Description |
| 145 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 146 | * void* aecmInst Pointer to the AECM instance |
| 147 | * AecmConfig config Config instance that contains all |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | * properties to be set |
| 149 | * |
| 150 | * Outputs Description |
| 151 | * ------------------------------------------------------------------- |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 152 | * int32_t return 0: OK |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 153 | * 1200-12004,12100: error/warning |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 154 | */ |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 155 | int32_t WebRtcAecm_set_config(void* aecmInst, AecmConfig config); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 156 | |
| 157 | /* |
bjornv@google.com | c4b939c | 2011-07-13 08:09:56 +0000 | [diff] [blame] | 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 |
ajm@google.com | 22e6515 | 2011-07-18 18:03:01 +0000 | [diff] [blame] | 164 | * size_t size_bytes Size in bytes of the echo path |
bjornv@google.com | c4b939c | 2011-07-13 08:09:56 +0000 | [diff] [blame] | 165 | * |
| 166 | * Outputs Description |
| 167 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 168 | * int32_t return 0: OK |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 169 | * 1200-12004,12100: error/warning |
bjornv@google.com | c4b939c | 2011-07-13 08:09:56 +0000 | [diff] [blame] | 170 | */ |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 171 | int32_t WebRtcAecm_InitEchoPath(void* aecmInst, |
| 172 | const void* echo_path, |
| 173 | size_t size_bytes); |
bjornv@google.com | c4b939c | 2011-07-13 08:09:56 +0000 | [diff] [blame] | 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 |
ajm@google.com | 22e6515 | 2011-07-18 18:03:01 +0000 | [diff] [blame] | 183 | * size_t size_bytes Size in bytes of the echo path |
bjornv@google.com | c4b939c | 2011-07-13 08:09:56 +0000 | [diff] [blame] | 184 | * |
| 185 | * Outputs Description |
| 186 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 187 | * int32_t return 0: OK |
peah | c12be39 | 2015-11-09 23:53:50 -0800 | [diff] [blame] | 188 | * 1200-12004,12100: error/warning |
bjornv@google.com | c4b939c | 2011-07-13 08:09:56 +0000 | [diff] [blame] | 189 | */ |
pbos@webrtc.org | b7192b8 | 2013-04-10 07:50:54 +0000 | [diff] [blame] | 190 | int32_t WebRtcAecm_GetEchoPath(void* aecmInst, |
| 191 | void* echo_path, |
| 192 | size_t size_bytes); |
bjornv@google.com | c4b939c | 2011-07-13 08:09:56 +0000 | [diff] [blame] | 193 | |
| 194 | /* |
| 195 | * This function enables the user to get the echo path size in bytes |
| 196 | * |
| 197 | * Outputs Description |
| 198 | * ------------------------------------------------------------------- |
kwiberg@webrtc.org | 924e81f | 2014-05-12 09:55:19 +0000 | [diff] [blame] | 199 | * size_t return Size in bytes |
bjornv@google.com | c4b939c | 2011-07-13 08:09:56 +0000 | [diff] [blame] | 200 | */ |
ajm@google.com | 22e6515 | 2011-07-18 18:03:01 +0000 | [diff] [blame] | 201 | size_t WebRtcAecm_echo_path_size_bytes(); |
bjornv@google.com | c4b939c | 2011-07-13 08:09:56 +0000 | [diff] [blame] | 202 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | #ifdef __cplusplus |
| 204 | } |
| 205 | #endif |
Per Åhgren | be36db1 | 2020-03-20 16:45:09 +0100 | [diff] [blame] | 206 | |
| 207 | } // namespace webrtc |
| 208 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 209 | #endif // MODULES_AUDIO_PROCESSING_AECM_ECHO_CONTROL_MOBILE_H_ |