echo_cancellation.h 8.8 KB

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