as_hfp_speech.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * Copyright (c) 2020, Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef __AL_HFP_SPEECH_LIB_DEV_H__
  7. #define __AL_HFP_SPEECH_LIB_DEV_H__
  8. /*******************************************************************************
  9. * PLC structures
  10. ******************************************************************************/
  11. #define PLC_GLOBAL_BUF_SIZE(samplerate_khz) \
  12. ((samplerate_khz == 16) ? (2030 * 2) : (1071 * 2))
  13. #define PLC_SHARE_BUF_SIZE(samplerate_khz) \
  14. ((samplerate_khz == 16) ? (1950 * 2) : (978 * 2))
  15. #define PLC_FRAME_SIZE(samplerate_khz) \
  16. ((samplerate_khz == 16) ? 120 : 60)
  17. typedef struct
  18. {
  19. int* global_buffer; // 8k:1071*2bytes 16k:2030*2bytes
  20. int* share_buffer; // 8k:978*2bytes 16k:1950*2bytes
  21. int num; // samples per frame, 8k:60, 16k:120
  22. } plc_prms_t;
  23. typedef struct
  24. {
  25. short* inoutput;
  26. int cnt; // number of samples
  27. } plc_inout_t;
  28. /*******************************************************************************
  29. * AEC structures
  30. ******************************************************************************/
  31. typedef struct
  32. {
  33. /*int aec_enable; extended param */
  34. char aec_enable; //aec module enable
  35. char aec_no_sat; //0: history mode; 1: convergence every frame
  36. short init_echo; // initial echo cancellation time. 0: default 40*16ms; otherwise init_echo*16ms
  37. int tail_length; // echo tail length in ms, mutiple of 16
  38. //int bulk_delay; //bulk delay
  39. /*int nlp_enable; extended param */
  40. short nlp_enable; //nonlinear processing submodule enable. 1: enable, make sure aec_enable is 1; 0: disable
  41. char nlp_echolevel; //default 0
  42. char nlp_speed; //default 0
  43. int nlp_aggressiveness; //nonlinear processing level, range 0~15, the greater, the more nonlinear.
  44. int dt_threshold; //speech retention level in dual speech near end, range 0~15, the greater, the more retention of near end in dual speech, while the less in single speech */
  45. int aes_enable; // residual echo suppression submodule enabe. 1: enable, make sure aec_enable is 1; 0: disable
  46. int echo_suppress; //single speech echo suppression ratio of echo suppression submodule, range 0~40 dB
  47. int echo_suppress_avtive; //dual speech echo suppression ratio of echo suppression submodule,range 0~40 dB
  48. } aec_prms_t;
  49. typedef struct
  50. {
  51. int ans_enable; //denoise enable
  52. int noise_suppress; //denoise suppression ratio, range 0~25 dB
  53. } ns_prms_t;
  54. typedef struct
  55. {
  56. int cng_enable; //comfort noise enable
  57. int noise_floor; //comfort noise level, in dB Fs, less than -45 dB generally
  58. } cng_prms_t;
  59. #define SV_GLOBAL_BUF1_SIZE(samplerate_khz) \
  60. ((samplerate_khz == 16) ? (10536 * 2) : (6184 * 2))
  61. #define SV_GLOBAL_BUF2_SIZE(samplerate_khz) \
  62. ((samplerate_khz == 16) ? (1280 * 2) : (0))
  63. #define SV_GLOBAL_BUF_SIZE(samplerate_khz) \
  64. (SV_GLOBAL_BUF1_SIZE(samplerate_khz) + SV_GLOBAL_BUF2_SIZE(samplerate_khz))
  65. #define SV_SHARE_BUF_SIZE(samplerate_khz) \
  66. ((samplerate_khz == 16) ? (3082 * 2) : (1546 * 2))
  67. #define SV_MDF_BUF_SIZE(samplerate_khz, tail_length) \
  68. ((samplerate_khz == 16) ? (tail_length * (32 * 6)) : (tail_length * (16 * 6)))
  69. #define SV_TAIL_LENGTH(samplerate_khz, mdf_bufsize) \
  70. ((samplerate_khz == 16) ? (mdf_bufsize / (32 * 6)) : (mdf_bufsize / (16 * 6)))
  71. #define SV_FRAME_SIZE(samplerate_khz) \
  72. ((samplerate_khz == 16) ? 256 : 128)
  73. typedef struct
  74. {
  75. int frame_size; //frame time in ms, only support 16ms
  76. int sampling_rate; //sample rate in Hz, only support 8000 and 16000
  77. // aec prms
  78. aec_prms_t aec_prms;
  79. //ns prms
  80. ns_prms_t ns_prms;
  81. //cng prms
  82. cng_prms_t cng_prms;
  83. int analysis_mode; //test mode, 0: simulation (offline) mode; 1: phonecall mode
  84. int half_mode; //half duplex mode, 0: full duplex, 1: half duplex
  85. int* global_buffer; //8k:6184*2 bytes 16k: 10536*2 bytes
  86. int* global_buffer2; //8k:null 16k:1280*2 bytes
  87. int* share_buffer; //8k:1546*2 bytes 16k: 3082*2 bytes
  88. int* mdf_buffer; //8k:tail_length(ms)*16*6bytes 16k:tail_length(ms)*32*6bytes
  89. } sv_prms_t;
  90. typedef struct
  91. {
  92. short* Txinbuf_mic;
  93. short* RxinBuf_spk;
  94. int cnt; //samples count, 16k:256, 8k:128
  95. } aec_inout_t;
  96. /*******************************************************************************
  97. * AGC structures
  98. ******************************************************************************/
  99. typedef struct
  100. {
  101. /*targe amplitude: 4000-24000, suggested 8000*/
  102. int agc_level;
  103. /*sample rate in Hz, onley support 8000 or 16000 */
  104. int sample_rate;
  105. /* number of channels, only suuport 1*/
  106. int channels;
  107. /*reserved for future*/
  108. int agc_mode;
  109. /* minimum gain. 0: no limit; others: lower limit of gain */
  110. int minimum_gain;
  111. /* maximum gain. 0: no limit; others: upper limit of gain */
  112. int maximum_gain;
  113. int zero_crose;
  114. /* hold time in ms */
  115. int hold_time;
  116. /* decay time in ms */
  117. int decay_time;
  118. /* attack time in ms */
  119. int attack_time;
  120. /* noise gate enable */
  121. int noise_gate_enable;
  122. /* noise gate threshold, range 200-1000, suggested 400 */
  123. int noise_gate_threshold;
  124. /* noise gate type. 0: fixed, 1: self adaption */
  125. int noise_gate_type;
  126. } AGCSetting_t;
  127. typedef struct
  128. {
  129. short* inoutput;
  130. int cnt; //samples count, 16k:256, 8k:128
  131. } agc_inout_t;
  132. /*******************************************************************************
  133. * BIN para structures
  134. ******************************************************************************/
  135. /* totally 60 bytes */
  136. typedef struct as_hfp_speech_para_bin {
  137. aec_prms_t aec_prms; /* 32 bytes */
  138. ns_prms_t ns_prms; /* 8 bytes */
  139. cng_prms_t cng_prms; /* 8 bytes */
  140. short analysis_mode; /* test mode, 0: simulating phonecall, 1: phonecall */
  141. short half_mode; /* 0: full-duplex, 1: half-duplex */
  142. short agc_pre_level; /* agc level, 0-15 (10000--25000) */
  143. short agc_post_level; /* agc level, 0-15 (10000--25000) */
  144. short agc_pre_en; /* 0: fixed gain, 1: enable agc */
  145. short agc_post_en; /* 0: fixed gain, 1: enable agc */
  146. } as_hfp_speech_para_bin_t;
  147. #define AS_HFP_SPEECH_PARA_BIN_SIZE (sizeof(as_hfp_speech_para_bin_t))
  148. /*******************************************************************************
  149. * library interface
  150. ******************************************************************************/
  151. /*!
  152. * \brief
  153. * ops error code
  154. */
  155. typedef enum
  156. {
  157. /*! unexpected error */
  158. HS_RET_UNEXPECTED = -3,
  159. /*! not enough memory */
  160. HS_RET_OUTOFMEMORY,
  161. /*! unsupported format */
  162. HS_RET_UNSUPPORTED,
  163. /*! no error */
  164. HS_RET_OK,
  165. /*! data underflow */
  166. HS_RET_DATAUNDERFLOW,
  167. } hs_ret_t;
  168. /*!
  169. * \brief
  170. * plc command
  171. */
  172. typedef enum
  173. {
  174. HS_CMD_PLC_OPEN = 0,
  175. HS_CMD_PLC_CLOSE,
  176. HS_CMD_PLC_PROCESS_NORMAL,
  177. HS_CMD_PLC_PROCESS_LOSS,
  178. } plc_ex_ops_cmd_t;
  179. /**
  180. * @brief hfp plc operation
  181. *
  182. * This routine provides hfp plc operation
  183. *
  184. * @param hnd handle hfp plc
  185. * @param cmd operation cmd, type of plc_ex_ops_cmd_t
  186. * @param args args of hfp plc parama addr
  187. *
  188. * @return type of hs_ret_t;
  189. */
  190. int hfp_plc_ops(void *handle, plc_ex_ops_cmd_t cmd, unsigned int args);
  191. /*!
  192. * \brief
  193. * speech command
  194. */
  195. typedef enum
  196. {
  197. HS_CMD_AGC_PRE_OPEN = 0,
  198. HS_CMD_AGC_POST_OPEN,
  199. HS_CMD_AEC_OPEN,
  200. HS_CMD_CLOSE,
  201. HS_CMD_AGC_PROCESS,
  202. HS_CMD_AEC_PROCESS,
  203. HS_CMD_AEC_GETSTASTUS,
  204. HS_CMD_CNG_PROCESS,
  205. HS_CMD_CONNECT,
  206. } hfp_ex_ops_cmd_t;
  207. /**
  208. * @brief hfp speech operation
  209. *
  210. * This routine provides hfp speech operation
  211. *
  212. * @param hnd handle of hfp speech
  213. * @param cmd operation cmd, type of hfp_ex_ops_cmd_t
  214. * @param args args of hfp speech parama addr
  215. *
  216. * @return type of hs_ret_t;
  217. */
  218. int hfp_speech_ops(void *handle, hfp_ex_ops_cmd_t cmd, unsigned int args);
  219. #endif /* __AL_HFP_SPEECH_LIB_DEV_H__ */