echo_cancellation.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_INCLUDE_ECHO_CANCELLATION_H_
  11. #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_INCLUDE_ECHO_CANCELLATION_H_
  12. #include "typedefs.h"
  13. // Errors
  14. #define AEC_UNSPECIFIED_ERROR 12000
  15. #define AEC_UNSUPPORTED_FUNCTION_ERROR 12001
  16. #define AEC_UNINITIALIZED_ERROR 12002
  17. #define AEC_NULL_POINTER_ERROR 12003
  18. #define AEC_BAD_PARAMETER_ERROR 12004
  19. // Warnings
  20. #define AEC_BAD_PARAMETER_WARNING 12050
  21. enum {
  22. kAecNlpConservative = 0,
  23. kAecNlpModerate,
  24. kAecNlpAggressive
  25. };
  26. enum {
  27. kAecFalse = 0,
  28. kAecTrue
  29. };
  30. typedef struct {
  31. WebRtc_Word16 nlpMode; // default kAecNlpModerate
  32. WebRtc_Word16 skewMode; // default kAecFalse
  33. WebRtc_Word16 metricsMode; // default kAecFalse
  34. int delay_logging; // default kAecFalse
  35. //float realSkew;
  36. } AecConfig;
  37. typedef struct {
  38. WebRtc_Word16 instant;
  39. WebRtc_Word16 average;
  40. WebRtc_Word16 max;
  41. WebRtc_Word16 min;
  42. } AecLevel;
  43. typedef struct {
  44. AecLevel rerl;
  45. AecLevel erl;
  46. AecLevel erle;
  47. AecLevel aNlp;
  48. } AecMetrics;
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. /*
  53. * Allocates the memory needed by the AEC. The memory needs to be initialized
  54. * separately using the WebRtcAec_Init() function.
  55. *
  56. * Inputs Description
  57. * -------------------------------------------------------------------
  58. * void **aecInst Pointer to the AEC instance to be created
  59. * and initialized
  60. *
  61. * Outputs Description
  62. * -------------------------------------------------------------------
  63. * WebRtc_Word32 return 0: OK
  64. * -1: error
  65. */
  66. WebRtc_Word32 WebRtcAec_Create(void **aecInst);
  67. /*
  68. * This function releases the memory allocated by WebRtcAec_Create().
  69. *
  70. * Inputs Description
  71. * -------------------------------------------------------------------
  72. * void *aecInst Pointer to the AEC instance
  73. *
  74. * Outputs Description
  75. * -------------------------------------------------------------------
  76. * WebRtc_Word32 return 0: OK
  77. * -1: error
  78. */
  79. WebRtc_Word32 WebRtcAec_Free(void *aecInst);
  80. /*
  81. * Initializes an AEC instance.
  82. *
  83. * Inputs Description
  84. * -------------------------------------------------------------------
  85. * void *aecInst Pointer to the AEC instance
  86. * WebRtc_Word32 sampFreq Sampling frequency of data
  87. * WebRtc_Word32 scSampFreq Soundcard sampling frequency
  88. *
  89. * Outputs Description
  90. * -------------------------------------------------------------------
  91. * WebRtc_Word32 return 0: OK
  92. * -1: error
  93. */
  94. WebRtc_Word32 WebRtcAec_Init(void *aecInst,
  95. WebRtc_Word32 sampFreq,
  96. WebRtc_Word32 scSampFreq);
  97. /*
  98. * Inserts an 80 or 160 sample block of data into the farend buffer.
  99. *
  100. * Inputs Description
  101. * -------------------------------------------------------------------
  102. * void *aecInst Pointer to the AEC instance
  103. * WebRtc_Word16 *farend In buffer containing one frame of
  104. * farend signal for L band
  105. * WebRtc_Word16 nrOfSamples Number of samples in farend buffer
  106. *
  107. * Outputs Description
  108. * -------------------------------------------------------------------
  109. * WebRtc_Word32 return 0: OK
  110. * -1: error
  111. */
  112. WebRtc_Word32 WebRtcAec_BufferFarend(void *aecInst,
  113. const WebRtc_Word16 *farend,
  114. WebRtc_Word16 nrOfSamples);
  115. /*
  116. * Runs the echo canceller on an 80 or 160 sample blocks of data.
  117. *
  118. * Inputs Description
  119. * -------------------------------------------------------------------
  120. * void *aecInst Pointer to the AEC instance
  121. * WebRtc_Word16 *nearend In buffer containing one frame of
  122. * nearend+echo signal for L band
  123. * WebRtc_Word16 *nearendH In buffer containing one frame of
  124. * nearend+echo signal for H band
  125. * WebRtc_Word16 nrOfSamples Number of samples in nearend buffer
  126. * WebRtc_Word16 msInSndCardBuf Delay estimate for sound card and
  127. * system buffers
  128. * WebRtc_Word16 skew Difference between number of samples played
  129. * and recorded at the soundcard (for clock skew
  130. * compensation)
  131. *
  132. * Outputs Description
  133. * -------------------------------------------------------------------
  134. * WebRtc_Word16 *out Out buffer, one frame of processed nearend
  135. * for L band
  136. * WebRtc_Word16 *outH Out buffer, one frame of processed nearend
  137. * for H band
  138. * WebRtc_Word32 return 0: OK
  139. * -1: error
  140. */
  141. WebRtc_Word32 WebRtcAec_Process(void *aecInst,
  142. const WebRtc_Word16 *nearend,
  143. const WebRtc_Word16 *nearendH,
  144. WebRtc_Word16 *out,
  145. WebRtc_Word16 *outH,
  146. WebRtc_Word16 nrOfSamples,
  147. WebRtc_Word16 msInSndCardBuf,
  148. WebRtc_Word32 skew);
  149. /*
  150. * This function enables the user to set certain parameters on-the-fly.
  151. *
  152. * Inputs Description
  153. * -------------------------------------------------------------------
  154. * void *aecInst Pointer to the AEC instance
  155. * AecConfig config Config instance that contains all
  156. * properties to be set
  157. *
  158. * Outputs Description
  159. * -------------------------------------------------------------------
  160. * WebRtc_Word32 return 0: OK
  161. * -1: error
  162. */
  163. WebRtc_Word32 WebRtcAec_set_config(void *aecInst, AecConfig config);
  164. /*
  165. * Gets the on-the-fly paramters.
  166. *
  167. * Inputs Description
  168. * -------------------------------------------------------------------
  169. * void *aecInst Pointer to the AEC instance
  170. *
  171. * Outputs Description
  172. * -------------------------------------------------------------------
  173. * AecConfig *config Pointer to the config instance that
  174. * all properties will be written to
  175. * WebRtc_Word32 return 0: OK
  176. * -1: error
  177. */
  178. WebRtc_Word32 WebRtcAec_get_config(void *aecInst, AecConfig *config);
  179. /*
  180. * Gets the current echo status of the nearend signal.
  181. *
  182. * Inputs Description
  183. * -------------------------------------------------------------------
  184. * void *aecInst Pointer to the AEC instance
  185. *
  186. * Outputs Description
  187. * -------------------------------------------------------------------
  188. * WebRtc_Word16 *status 0: Almost certainly nearend single-talk
  189. * 1: Might not be neared single-talk
  190. * WebRtc_Word32 return 0: OK
  191. * -1: error
  192. */
  193. WebRtc_Word32 WebRtcAec_get_echo_status(void *aecInst, WebRtc_Word16 *status);
  194. /*
  195. * Gets the current echo metrics for the session.
  196. *
  197. * Inputs Description
  198. * -------------------------------------------------------------------
  199. * void *aecInst Pointer to the AEC instance
  200. *
  201. * Outputs Description
  202. * -------------------------------------------------------------------
  203. * AecMetrics *metrics Struct which will be filled out with the
  204. * current echo metrics.
  205. * WebRtc_Word32 return 0: OK
  206. * -1: error
  207. */
  208. WebRtc_Word32 WebRtcAec_GetMetrics(void *aecInst, AecMetrics *metrics);
  209. /*
  210. * Gets the current delay metrics for the session.
  211. *
  212. * Inputs Description
  213. * -------------------------------------------------------------------
  214. * void* handle Pointer to the AEC instance
  215. *
  216. * Outputs Description
  217. * -------------------------------------------------------------------
  218. * int* median Delay median value.
  219. * int* std Delay standard deviation.
  220. *
  221. * int return 0: OK
  222. * -1: error
  223. */
  224. int WebRtcAec_GetDelayMetrics(void* handle, int* median, int* std);
  225. /*
  226. * Gets the last error code.
  227. *
  228. * Inputs Description
  229. * -------------------------------------------------------------------
  230. * void *aecInst Pointer to the AEC instance
  231. *
  232. * Outputs Description
  233. * -------------------------------------------------------------------
  234. * WebRtc_Word32 return 11000-11100: error code
  235. */
  236. WebRtc_Word32 WebRtcAec_get_error_code(void *aecInst);
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240. #endif // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_INCLUDE_ECHO_CANCELLATION_H_