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