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