1 /* 2 * Copyright (c) 2012 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_AECM_INCLUDE_ECHO_CONTROL_MOBILE_H_ 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_AECM_INCLUDE_ECHO_CONTROL_MOBILE_H_ 13 14 #include <stdlib.h> 15 16 #include "webrtc/typedefs.h" 17 18 enum { 19 AecmFalse = 0, 20 AecmTrue 21 }; 22 23 // Errors 24 #define AECM_UNSPECIFIED_ERROR 12000 25 #define AECM_UNSUPPORTED_FUNCTION_ERROR 12001 26 #define AECM_UNINITIALIZED_ERROR 12002 27 #define AECM_NULL_POINTER_ERROR 12003 28 #define AECM_BAD_PARAMETER_ERROR 12004 29 30 // Warnings 31 #define AECM_BAD_PARAMETER_WARNING 12100 32 33 typedef struct { 34 int16_t cngMode; // AECM_FALSE, AECM_TRUE (default) 35 int16_t echoMode; // 0, 1, 2, 3 (default), 4 36 } AecmConfig; 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 /* 43 * Allocates the memory needed by the AECM. The memory needs to be 44 * initialized separately using the WebRtcAecm_Init() function. 45 * 46 * Inputs Description 47 * ------------------------------------------------------------------- 48 * void** aecmInst Pointer to the AECM instance to be 49 * created and initialized 50 * 51 * Outputs Description 52 * ------------------------------------------------------------------- 53 * int32_t return 0: OK 54 * -1: error 55 */ 56 int32_t WebRtcAecm_Create(void **aecmInst); 57 58 /* 59 * This function releases the memory allocated by WebRtcAecm_Create() 60 * 61 * Inputs Description 62 * ------------------------------------------------------------------- 63 * void* aecmInst Pointer to the AECM instance 64 * 65 * Outputs Description 66 * ------------------------------------------------------------------- 67 * int32_t return 0: OK 68 * -1: error 69 */ 70 int32_t WebRtcAecm_Free(void *aecmInst); 71 72 /* 73 * Initializes an AECM instance. 74 * 75 * Inputs Description 76 * ------------------------------------------------------------------- 77 * void* aecmInst Pointer to the AECM instance 78 * int32_t sampFreq Sampling frequency of data 79 * 80 * Outputs Description 81 * ------------------------------------------------------------------- 82 * int32_t return 0: OK 83 * -1: error 84 */ 85 int32_t WebRtcAecm_Init(void* aecmInst, int32_t sampFreq); 86 87 /* 88 * Inserts an 80 or 160 sample block of data into the farend buffer. 89 * 90 * Inputs Description 91 * ------------------------------------------------------------------- 92 * void* aecmInst Pointer to the AECM instance 93 * int16_t* farend In buffer containing one frame of 94 * farend signal 95 * int16_t nrOfSamples Number of samples in farend buffer 96 * 97 * Outputs Description 98 * ------------------------------------------------------------------- 99 * int32_t return 0: OK 100 * -1: error 101 */ 102 int32_t WebRtcAecm_BufferFarend(void* aecmInst, 103 const int16_t* farend, 104 int16_t nrOfSamples); 105 106 /* 107 * Runs the AECM on an 80 or 160 sample blocks of data. 108 * 109 * Inputs Description 110 * ------------------------------------------------------------------- 111 * void* aecmInst Pointer to the AECM instance 112 * int16_t* nearendNoisy In buffer containing one frame of 113 * reference nearend+echo signal. If 114 * noise reduction is active, provide 115 * the noisy signal here. 116 * int16_t* nearendClean In buffer containing one frame of 117 * nearend+echo signal. If noise 118 * reduction is active, provide the 119 * clean signal here. Otherwise pass a 120 * NULL pointer. 121 * int16_t nrOfSamples Number of samples in nearend buffer 122 * int16_t msInSndCardBuf Delay estimate for sound card and 123 * system buffers 124 * 125 * Outputs Description 126 * ------------------------------------------------------------------- 127 * int16_t* out Out buffer, one frame of processed nearend 128 * int32_t return 0: OK 129 * -1: error 130 */ 131 int32_t WebRtcAecm_Process(void* aecmInst, 132 const int16_t* nearendNoisy, 133 const int16_t* nearendClean, 134 int16_t* out, 135 int16_t nrOfSamples, 136 int16_t msInSndCardBuf); 137 138 /* 139 * This function enables the user to set certain parameters on-the-fly 140 * 141 * Inputs Description 142 * ------------------------------------------------------------------- 143 * void* aecmInst Pointer to the AECM instance 144 * AecmConfig config Config instance that contains all 145 * properties to be set 146 * 147 * Outputs Description 148 * ------------------------------------------------------------------- 149 * int32_t return 0: OK 150 * -1: error 151 */ 152 int32_t WebRtcAecm_set_config(void* aecmInst, AecmConfig config); 153 154 /* 155 * This function enables the user to set certain parameters on-the-fly 156 * 157 * Inputs Description 158 * ------------------------------------------------------------------- 159 * void* aecmInst Pointer to the AECM instance 160 * 161 * Outputs Description 162 * ------------------------------------------------------------------- 163 * AecmConfig* config Pointer to the config instance that 164 * all properties will be written to 165 * int32_t return 0: OK 166 * -1: error 167 */ 168 int32_t WebRtcAecm_get_config(void *aecmInst, AecmConfig *config); 169 170 /* 171 * This function enables the user to set the echo path on-the-fly. 172 * 173 * Inputs Description 174 * ------------------------------------------------------------------- 175 * void* aecmInst Pointer to the AECM instance 176 * void* echo_path Pointer to the echo path to be set 177 * size_t size_bytes Size in bytes of the echo path 178 * 179 * Outputs Description 180 * ------------------------------------------------------------------- 181 * int32_t return 0: OK 182 * -1: error 183 */ 184 int32_t WebRtcAecm_InitEchoPath(void* aecmInst, 185 const void* echo_path, 186 size_t size_bytes); 187 188 /* 189 * This function enables the user to get the currently used echo path 190 * on-the-fly 191 * 192 * Inputs Description 193 * ------------------------------------------------------------------- 194 * void* aecmInst Pointer to the AECM instance 195 * void* echo_path Pointer to echo path 196 * size_t size_bytes Size in bytes of the echo path 197 * 198 * Outputs Description 199 * ------------------------------------------------------------------- 200 * int32_t return 0: OK 201 * -1: error 202 */ 203 int32_t WebRtcAecm_GetEchoPath(void* aecmInst, 204 void* echo_path, 205 size_t size_bytes); 206 207 /* 208 * This function enables the user to get the echo path size in bytes 209 * 210 * Outputs Description 211 * ------------------------------------------------------------------- 212 * size_t return Size in bytes 213 */ 214 size_t WebRtcAecm_echo_path_size_bytes(); 215 216 /* 217 * Gets the last error code. 218 * 219 * Inputs Description 220 * ------------------------------------------------------------------- 221 * void* aecmInst Pointer to the AECM instance 222 * 223 * Outputs Description 224 * ------------------------------------------------------------------- 225 * int32_t return 11000-11100: error code 226 */ 227 int32_t WebRtcAecm_get_error_code(void *aecmInst); 228 229 #ifdef __cplusplus 230 } 231 #endif 232 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AECM_INCLUDE_ECHO_CONTROL_MOBILE_H_ 233