audio_processor.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*
  2. * Copyright (c) 2020, Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file Audio processor interface
  8. */
  9. #ifndef __AUDIO_PROCESSOR_H__
  10. #define __AUDIO_PROCESSOR_H__
  11. #include <zephyr.h>
  12. #include <acts_ringbuf.h>
  13. /**
  14. * @brief Audio processor APIs
  15. * @defgroup audio_processor_apis Audio Processor APIs
  16. * @ingroup media_system_apis
  17. * @{
  18. */
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define MAKE_AUDIO_PROCESSOR_MODULE_ID(A, B, C, D) \
  23. (((uint32_t)(A) << 24) | ((uint32_t)(B) << 16) | ((uint32_t)(C) << 8) | (D))
  24. #define MAKE_AUDIO_PROCESSOR_VERSION(major, minor, patchlevel) \
  25. (((uint32_t)((major) && 0xFF) << 24) | ((uint32_t)((minor) && 0xFF) << 16) | ((uint32_t)((patchlevel) && 0xFF) << 8))
  26. #define AUDIO_PROCESSOR_VER_MAJOR(ver) ((ver >> 24) & 0xFF)
  27. #define AUDIO_PROCESSOR_VER_MINOR(ver) ((ver >> 16) & 0xFF)
  28. #define AUDIO_PROCESSOR_VER_PATCHLEVEL(ver) ((ver >> 8) & 0xFF)
  29. #define MAX_AUDIO_CHANNELS (2)
  30. typedef enum {
  31. BTCALL_PREPROCESSOR_MODULE_ID = MAKE_AUDIO_PROCESSOR_MODULE_ID('B', 'T', 'C', 'R'),
  32. BTCALL_POSTPROCESSOR_MODULE_ID = MAKE_AUDIO_PROCESSOR_MODULE_ID('B', 'T', 'C', 'O'),
  33. MUSIC_POSTPROCESSOR_MODULE_ID = MAKE_AUDIO_PROCESSOR_MODULE_ID('M', 'U', 'S', 'O'),
  34. } audio_processor_module_id_e;
  35. /** audio preprocessor init param */
  36. typedef struct audio_preprocessor_init_param {
  37. /* audio_stream_type_e, see audio_system.h */
  38. uint8_t stream_type; /* stream type of the media */
  39. uint8_t stream_effect; /* stream type of the effect applied on the media */
  40. uint8_t sample_rate; /* kHz */
  41. uint8_t sample_bits; /* bits per sample, 16/24/32 */
  42. uint8_t frac_bits; /* fractional bits, 0 for integral samples */
  43. uint8_t channels; /* channels of in/output pcms */
  44. uint8_t format; /* media_type_e */
  45. /* input pcm, separated channels */
  46. struct acts_ringbuf *inbufs[MAX_AUDIO_CHANNELS];
  47. /* input ref pcm as required, single channel in most cases */
  48. struct acts_ringbuf *refbuf;
  49. /* output pcm, separated channels */
  50. struct acts_ringbuf *outbufs[MAX_AUDIO_CHANNELS];
  51. /* processor specific params */
  52. void *ext_param;
  53. } audio_preprocessor_init_param_t;
  54. /** audio postprocessor init param */
  55. typedef struct audio_postprocessor_init_param {
  56. /* audio_stream_type_e, see audio_system.h */
  57. uint8_t stream_type; /* stream type of the media */
  58. uint8_t stream_effect; /* stream type of the effect applied on the media */
  59. uint8_t sample_rate; /* kHz */
  60. uint8_t sample_bits; /* bits per sample, 16/24/32 */
  61. uint8_t frac_bits; /* fractional bits, 0 for integral samples */
  62. uint8_t channels; /* channels of in/output pcm */
  63. uint8_t format; /* media_type_e */
  64. /* input pcm, separated channels */
  65. struct acts_ringbuf *inbufs[MAX_AUDIO_CHANNELS];
  66. /* output ref pcm as required, single channel in most cases */
  67. struct acts_ringbuf *refbuf;
  68. /* output pcm, interweaved channels */
  69. struct acts_ringbuf *outbuf;
  70. /* processor specific params */
  71. void *ext_param;
  72. } audio_postprocessor_init_param_t;
  73. struct audio_processor_module;
  74. typedef struct audio_processor {
  75. const struct audio_processor_module *module;
  76. void *priv; /* private data */
  77. } audio_processor_t;
  78. /** audio pre/postprocessor module */
  79. typedef struct audio_processor_module {
  80. /** Identifier of module */
  81. uint32_t id;
  82. /** Version of the implemented module */
  83. uint32_t version;
  84. /** Name of this module */
  85. const char *name;
  86. /** Module ops: initialize a processor, return 0 if succeed */
  87. int (*initialize)(audio_processor_t *handle, void *init_param);
  88. /** Module ops: destroy a processor, return 0 if succeed */
  89. int (*destroy)(audio_processor_t *handle);
  90. /** Module ops: run a processor, return number of sample (pair) successfully processed */
  91. int (*process)(audio_processor_t *handle);
  92. /** Module ops: flush a processor, return number of sample (pair) successfully flushed */
  93. int (*flush)(audio_processor_t *handle);
  94. /** Module ops: get parameters of a processor, return 0 if succeed */
  95. int (*get_parameter)(audio_processor_t *handle, int pname, void *param, unsigned int psize);
  96. /** Module ops: set parameters of a processor, return 0 if succeed */
  97. int (*set_parameter)(audio_processor_t *handle, int pname, void *param, unsigned int psize);
  98. /** Module ops: debug a processor, return 0 if succeed */
  99. int (*dump)(audio_processor_t *handle, int data_tag, struct acts_ringbuf *data_buf);
  100. /** The following ops are mostly used to send control commands in dsp implemented processors */
  101. #ifdef CONFIG_DSP
  102. /** Module ops: enable a processor (may cause re-initialization), return 0 if succeed */
  103. int (*enable)(audio_processor_t *handle);
  104. /** Module ops: disable a processor, return 0 if succeed */
  105. int (*disable)(audio_processor_t *handle);
  106. /** Module ops: pause a processor, return 0 if succeed */
  107. int (*pause)(audio_processor_t *handle);
  108. /** Module ops: resum a processor, return 0 if succeed */
  109. int (*resume)(audio_processor_t *handle);
  110. #endif /* CONFIG_DSP */
  111. } audio_processor_module_t;
  112. /**
  113. * @brief Open a audio preprocessor.
  114. *
  115. * This routine open a audio preprocessor.
  116. *
  117. * @param init_param Address of preprocessor init param
  118. *
  119. * @return handle of preprocessor
  120. */
  121. void *audio_preprocessor_open(audio_preprocessor_init_param_t *init_param);
  122. /**
  123. * @brief Open a audio postprocessor.
  124. *
  125. * This routine open a audio postprocessor.
  126. *
  127. * @param init_param Address of postprocessor init param
  128. *
  129. * @return handle of postprocessor
  130. */
  131. void *audio_postprocessor_open(audio_postprocessor_init_param_t *init_param);
  132. /**
  133. * @brief Close a audio pre/postprocessor.
  134. *
  135. * This routine close a audio pre/postprocessor.
  136. *
  137. * @param handle Handle of pre/postprocessor.
  138. *
  139. * @return 0 if succeed; non-zero if fail.
  140. */
  141. int audio_processor_close(void *handle);
  142. /**
  143. * @brief Enable a audio pre/postprocessor.
  144. *
  145. * This routine enable a audio pre/postprocessor.
  146. *
  147. * @param handle Handle of pre/postprocessor.
  148. *
  149. * @return 0 if succeed; non-zero if fail.
  150. */
  151. int audio_processor_enable(void *handle);
  152. /**
  153. * @brief Disable a audio pre/postprocessor.
  154. *
  155. * This routine disable a audio pre/postprocessor.
  156. *
  157. * @param handle Handle of pre/postprocessor.
  158. *
  159. * @return 0 if succeed; non-zero if fail.
  160. */
  161. int audio_processor_disable(void *handle);
  162. /**
  163. * @brief Pause a audio pre/postprocessor.
  164. *
  165. * This routine pause a audio pre/postprocessor.
  166. *
  167. * @param handle Handle of pre/postprocessor.
  168. *
  169. * @return 0 if succeed; non-zero if fail.
  170. */
  171. int audio_processor_pause(void *handle);
  172. /**
  173. * @brief Resume a audio pre/postprocessor.
  174. *
  175. * This routine resume a audio pre/postprocessor.
  176. *
  177. * @param handle Handle of pre/postprocessor.
  178. *
  179. * @return 0 if succeed; non-zero if fail.
  180. */
  181. int audio_processor_resume(void *handle);
  182. /**
  183. * @brief Run a audio pre/postprocessor to process data.
  184. *
  185. * This routine run a audio pre/postprocessor to process data.
  186. *
  187. * @param handle Handle of pre/postprocessor.
  188. *
  189. * @return number of samples processed.
  190. */
  191. int audio_processor_process(void *handle);
  192. /**
  193. * @brief Flush the remain data of a audio pre/postprocessor.
  194. *
  195. * This routine flush the remain data of a audio pre/postprocessor.
  196. *
  197. * @param handle Handle of pre/postprocessor.
  198. *
  199. * @return number of samples processed.
  200. */
  201. int audio_processor_flush(void *handle);
  202. /**
  203. * @brief Get parameter of a audio pre/postprocessor.
  204. *
  205. * This routine get parameter of a audio pre/postprocessor.
  206. *
  207. * @param handle Handle of pre/postprocessor.
  208. * @param pname Parameter name.
  209. * @param param Address of parameter.
  210. * @param psize Size of parameter.
  211. *
  212. * @return 0 if succeed; non-zero if fail.
  213. */
  214. int audio_processor_get_parameter(void *handle, int pname, void *param, unsigned int psize);
  215. /**
  216. * @brief Set parameter of a audio pre/postprocessor.
  217. *
  218. * This routine set parameter of a audio pre/postprocessor.
  219. *
  220. * @param handle Handle of pre/postprocessor.
  221. * @param pname Parameter name.
  222. * @param param Address of parameter.
  223. * @param psize Size of parameter.
  224. *
  225. * @return 0 if succeed; non-zero if fail.
  226. */
  227. int audio_processor_set_parameter(void *handle, int pname, void *param, unsigned int psize);
  228. /**
  229. * @brief Dump a audio pre/postprocessor
  230. *
  231. * This routine debug a audio pre/postprocessor.
  232. *
  233. * @param handle Handle of pre/postprocessor.
  234. * @param data_tag tag of dumpable data, see enum media_dump_data_tag_e in media_service.h
  235. * @param data_buf buffer to store dumpable data
  236. *
  237. * @return 0 if succeed; non-zero if fail.
  238. */
  239. int audio_processor_dump(void *handle, int data_tag, struct acts_ringbuf *data_buf);
  240. /**
  241. * @brief Register a audio preprocessor.
  242. *
  243. * This routine register a audio preprocessor to process data of specific stream_type.
  244. *
  245. * @param module Address of preprocessor module
  246. * @param stream_type type of audio stream, see audio_stream_type_e.
  247. *
  248. * @return 0 if succeed; non-zero if fail.
  249. */
  250. int audio_preprocessor_register(audio_processor_module_t *module, uint8_t stream_type);
  251. /**
  252. * @brief Unregister a audio preprocessor.
  253. *
  254. * This routine unregister a audio preprocessor which process data of specific stream_type.
  255. *
  256. * @param module Address of preprocessor module
  257. * @param stream_type type of audio stream, see audio_stream_type_e.
  258. *
  259. * @return 0 if succeed; non-zero if fail.
  260. */
  261. int audio_preprocessor_unregister(audio_processor_module_t *module, uint8_t stream_type);
  262. /**
  263. * @brief Register a audio postprocessor.
  264. *
  265. * This routine register a audio postprocessor to process data of specific stream_type.
  266. *
  267. * @param module Address of postprocessor module
  268. * @param stream_type type of audio stream, see audio_stream_type_e.
  269. *
  270. * @return 0 if succeed; non-zero if fail.
  271. */
  272. int audio_postprocessor_register(audio_processor_module_t *module, uint8_t stream_type);
  273. /**
  274. * @brief Unregister a audio postprocessor.
  275. *
  276. * This routine unregister a audio postprocessor which process data of specific stream_type.
  277. *
  278. * @param module Address of postprocessor module
  279. * @param stream_type type of audio stream, see audio_stream_type_e.
  280. *
  281. * @return 0 if succeed; non-zero if fail.
  282. */
  283. int audio_postprocessor_unregister(audio_processor_module_t *module, uint8_t stream_type);
  284. #ifdef __cplusplus
  285. }
  286. #endif
  287. /**
  288. * @}
  289. */
  290. #endif /* __AUDIO_PROCESSOR_H__ */