dsp_hal_defs.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*
  2. * dsp_hal_defs.h
  3. *
  4. * Created on: 2019年5月23日
  5. * Author: wuyufan
  6. */
  7. #ifndef _DSP_HAL_DEFS_H_
  8. #define _DSP_HAL_DEFS_H_
  9. #include <stdint.h>
  10. #include <drivers/dsp.h>
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define RINGBUF_TYPE uint32_t
  15. /*****************************************************************
  16. * DSP compilation time options. You can change these here by *
  17. * uncommenting the lines, or on the compiler command line. *
  18. *****************************************************************/
  19. /* Enable DSP music effect*/
  20. //#define DSP_SUPPORT_MUSIC_EFFECT
  21. /* Enable DSP voice effect */
  22. #define DSP_SUPPORT_VOICE_EFFECT
  23. /* Enable DSP ASRC effect */
  24. //#define DSP_SUPPORT_ASR_EFFECT
  25. /* Enable DSP decoder support resample*/
  26. //#define DSP_SUPPORT_DECODER_RESAMPLE
  27. //Enable DSP print
  28. #define DSP_SUPPORT_DEBUG_PRINT
  29. /* config DSP mix multi buffer num */
  30. #define DSP_SUPPORT_MULTI_BUFFER_NUM (2)
  31. /* config DSP AEC refs buf num */
  32. #define DSP_SUPPORT_AEC_REFBUF_NUM (1)
  33. #define DSP_AEC_REF_DELAY (1)
  34. #ifdef DSP_SUPPORT_MUSIC_EFFECT
  35. /* Enable DSP support player */
  36. #define DSP_SUPPORT_PLAYER
  37. /* Enable DSP support decoder */
  38. #define DSP_SUPPORT_DECODER
  39. /* Enable DSP decoder support DAE effect */
  40. #define DSP_SUPPORT_DECODER_DAE
  41. /* Enable DSP support sbc decoder */
  42. //#define DSP_SUPPORT_SBC_DECODER
  43. /* Enable DSP support aac decoder */
  44. #define DSP_SUPPORT_AAC_DECODER
  45. /* Enable DSP support output subwoofer */
  46. #define DSP_SUPPORT_OUTPUT_SUBWOOFER
  47. #endif
  48. #ifdef DSP_SUPPORT_VOICE_EFFECT
  49. /* Enable DSP support player */
  50. #define DSP_SUPPORT_PLAYER
  51. /* Enable DSP support recorder */
  52. #define DSP_SUPPORT_RECODER
  53. /* Enable DSP support decoder*/
  54. #define DSP_SUPPORT_DECODER
  55. /* Enable DSP support encoder */
  56. #define DSP_SUPPORT_ENCODER
  57. /* Enable DSP support AGC*/
  58. #define DSP_SUPPORT_AGC
  59. /* Enable DSP support PEQ*/
  60. #define DSP_SUPPORT_PEQ
  61. /* Enable DSP support decoder AGC */
  62. #define DSP_SUPPORT_DECODER_AGC
  63. /* Enable DSP support decoder PEQ */
  64. #define DSP_SUPPORT_DECODER_PEQ
  65. /* Enable DSP support encoder AGC */
  66. #define DSP_SUPPORT_ENCODER_AGC
  67. /* Enable DSP support encoder PEQ */
  68. #define DSP_SUPPORT_ENCODER_PEQ
  69. /* Enable DSP support msbc decoder */
  70. #define DSP_SUPPORT_MSBC_DECODER
  71. /* Enable DSP support msbc encoder */
  72. #define DSP_SUPPORT_MSBC_ENCODER
  73. /* Enable DSP support cvsd decoder */
  74. //#define DSP_SUPPORT_CVSD_DECODER
  75. /* Enable DSP support cvsd encoder */
  76. //#define DSP_SUPPORT_CVSD_ENCODER
  77. /* Enable DSP encoder support AEC */
  78. #define DSP_SUPPORT_ENCODER_AEC
  79. /* Enable DSP AEC SYNC with encoder */
  80. //#define DSP_SUPPORT_PLAYER_AEC_SYNC
  81. /* Enable DSP hardware AEC SYNC */
  82. #define DSP_SUPPORT_HARDWARE_AEC_SYNC
  83. /* Enable DSP encoder support CNG */
  84. #define DSP_SUPPORT_ENCODER_CNG
  85. #endif
  86. #if !defined(DSP_SUPPORT_MUSIC_EFFECT) && !defined(DSP_SUPPORT_VOICE_EFFECT)
  87. /* Enable DSP support recorder */
  88. #define DSP_SUPPORT_RECODER
  89. /* Enable DSP support encoder */
  90. #define DSP_SUPPORT_ENCODER
  91. /* Enable DSP support aac decoder */
  92. #define DSP_SUPPORT_OPUS_ENCODER
  93. #endif
  94. #ifdef DSP_SUPPORT_DEBUG_PRINT
  95. #define DSP_PUTS(a) dsp_puts(a)
  96. #define DSP_PRINTHEX(a) dsp_printhex(a)
  97. #else
  98. #define DSP_PUTS(a)
  99. #define DSP_PRINTHEX(a)
  100. #endif
  101. /* session ids */
  102. enum {
  103. DSP_SESSION_DEFAULT = 0,
  104. DSP_SESSION_MEDIA,
  105. DSP_NUM_SESSIONS,
  106. };
  107. /* session function ids */
  108. enum {
  109. /* basic functions */
  110. DSP_FUNCTION_DECODER = 0,
  111. DSP_FUNCTION_ENCODER,
  112. /* complex functions */
  113. DSP_FUNCTION_PLAYER,
  114. DSP_FUNCTION_RECORDER,
  115. DSP_FUNCTION_PREPROCESS,
  116. DSP_FUNCTION_POSTPROCESS,
  117. DSP_NUM_FUNCTIONS,
  118. };
  119. #define DSP_FUNC_BIT(func) BIT(func)
  120. #define DSP_FUNC_ALL BIT_MASK(DSP_NUM_FUNCTIONS)
  121. #if defined(DSP_SUPPORT_CVSD_DECODER) || defined(DSP_SUPPORT_CVSD_ENCODER)
  122. #define PCM_FRAMESZ (128)
  123. #else
  124. #define PCM_FRAMESZ (256)
  125. #endif
  126. /* session command ids */
  127. enum {
  128. /* session global commands */
  129. DSP_CMD_USER_DEFINED = 32,
  130. DSP_MIN_SESSION_CMD = DSP_CMD_USER_DEFINED,
  131. /* initialize static params before first run */
  132. DSP_CMD_SESSION_INIT = DSP_MIN_SESSION_CMD,
  133. /* begin session running (with dynamic params) */
  134. DSP_CMD_SESSION_BEGIN,
  135. /* end session running */
  136. DSP_CMD_SESSION_END,
  137. /* user-defined session command started from */
  138. DSP_CMD_SESSION_USER_DEFINED,
  139. DSP_MAX_SESSION_CMD = DSP_MIN_SESSION_CMD + 0xFF,
  140. /* session function commands, function id is required */
  141. DSP_MIN_FUNCTION_CMD = DSP_MAX_SESSION_CMD + 0x1,
  142. /* configure function 288 */
  143. DSP_CMD_FUNCTION_CONFIG = DSP_MIN_FUNCTION_CMD,
  144. /* enable function */
  145. DSP_CMD_FUNCTION_ENABLE,
  146. /* disable function */
  147. DSP_CMD_FUNCTION_DISABLE,
  148. /* debug function */
  149. DSP_CMD_FUNCTION_DEBUG,
  150. /* pause function, like function_disable, but need not finalize function */
  151. DSP_CMD_FUNCTION_PAUSE,
  152. /* debug function, like function_enable, but need not initialize function */
  153. DSP_CMD_FUNCTION_RESUME,
  154. /* user-defined function command started from */
  155. DSP_CMD_FUNCTION_USER_DEFINED,
  156. DSP_MAX_FUNCTION_CMD = DSP_MIN_FUNCTION_CMD + 0xFF,
  157. };
  158. /* session function configuration ids for complex functions */
  159. enum {
  160. /* configure the default parameter set, for basic functions */
  161. DSP_CONFIG_DEFAULT = 0,
  162. /* configure the decoder parameter set, struct decoder_dspfunc_params */
  163. DSP_CONFIG_DECODER,
  164. /* configure the encoder parameter set, struct encoder_dspfunc_params */
  165. DSP_CONFIG_ENCODER,
  166. /* configure the encoder parameter set, struct dae_dspfunc_params */
  167. DSP_CONFIG_DAE,
  168. /* configure the aec reference parameter set, struct aec_dspfunc_ref_params */
  169. DSP_CONFIG_AEC_REF,
  170. /* configure the aec parameter set, struct aec_dspfunc_params */
  171. DSP_CONFIG_AEC,
  172. /* configure the playback mix parameter set, struct mix_dspfunc_params */
  173. DSP_CONFIG_MIX,
  174. /* configure the playback output parameter set, struct output_dspfunc_params */
  175. DSP_CONFIG_OUTPUT,
  176. /* configure the decoder extra parameter set, struct decoder_dspfunc_ext_params */
  177. DSP_CONFIG_DECODER_EXT,
  178. DSP_CONFIG_ENERGY,
  179. DSP_CONFIG_MSIC,
  180. DSP_CONFIG_DAE_DRM,
  181. };
  182. /* session error state */
  183. enum {
  184. /* 1 ~ 31 dev error state >32 session error*/
  185. DSP_BAD_STREAM = 32,
  186. };
  187. /* codec format definition */
  188. enum {
  189. DSP_CODEC_FORMAT_MP3 = 1, /* MP3_TYPE */
  190. DSP_CODEC_FORMAT_WMA = 2, /* WMA_TYPE */
  191. DSP_CODEC_FORMAT_WAV = 3, /* WAV_TYPE */
  192. DSP_CODEC_FORMAT_FLAC = 4, /* FLA_TYPE */
  193. DSP_CODEC_FORMAT_APE = 5, /* APE_TYPE */
  194. DSP_CODEC_FORMAT_AAC = 6, /* AAC_TYPE */
  195. DSP_CODEC_FORMAT_OGG = 7, /* OGGC_TYPE */
  196. DSP_CODEC_FORMAT_ACT = 8, /* ACT_TYPE */
  197. DSP_CODEC_FORMAT_AMR = 9, /* AMR_TYPE */
  198. DSP_CODEC_FORMAT_SBC = 10, /* SBC_TYPE */
  199. DSP_CODEC_FORMAT_MSBC = 11, /* MSBC_TYPE */
  200. DSP_CODEC_FORMAT_OPUS = 12, /* OPUS_TYPE */
  201. DSP_CODEC_FORMAT_CVSD = 15, /* CVSD_TYPE */
  202. DSP_CODEC_FORMAT_SPEECH = 16, /* CVSD_TYPE */
  203. DSP_CODEC_FORMAT_PCM = 17, /* LDAC_TYPE */
  204. DSP_CODEC_FORMAT_LDAC = 18, /* LDAC_TYPE */
  205. DSP_CODEC_FORMAT_NAV = 19, /* NAV_TYPE */
  206. DSP_CODEC_FORMAT_NAV_SEP = 20, /* NAV_SEP_TYPE */
  207. DSP_CODEC_FORMAT_AAC_M4A = 21, /* m4A_SEP_TYPE */
  208. };
  209. enum {
  210. RESAMPLE_SAMPLERATE_16 = 16000,
  211. RESAMPLE_SAMPLERATE_44_1 = 44100,
  212. RESAMPLE_SAMPLERATE_48 = 48000,
  213. };
  214. enum {
  215. RESAMPLE_FRAMESZ_44_1 = 441,
  216. RESAMPLE_FRAMESZ_48 = 480,
  217. RESAMPLE_FRAMESZ_16 = 160,
  218. };
  219. enum {
  220. REF_STREAM_NULL = 0,
  221. REF_STREAM_MONO,
  222. REF_STREAM_LEFT,
  223. REF_STREAM_RIGHT,
  224. };
  225. enum {
  226. MIX_MODE_NULL,
  227. MIX_MODE_LEFT_RIGHT, //左右输出
  228. MIX_MODE_LEFT, //左输出
  229. MIX_MODE_RIGHT, //右输出
  230. MIX_MODE_L_R_SWITCH, //左右交换
  231. MIX_MODE_L_R_MERGE, //左右混合
  232. };
  233. enum {
  234. AEC_NOT_INIT = 0,
  235. AEC_CONFIGED,
  236. AEC_START,
  237. };
  238. struct media_dspssn_params {
  239. int16_t aec_en;
  240. } __packed;
  241. struct media_dspssn_info {
  242. struct media_dspssn_params params;
  243. } __packed;
  244. /* test function parameters */
  245. struct test_dspfunc_params {
  246. RINGBUF_TYPE inbuf;
  247. RINGBUF_TYPE refbuf;
  248. RINGBUF_TYPE outbuf;
  249. } __packed;
  250. /* test function runtime */
  251. struct test_dspfunc_runtime {
  252. uint32_t sample_count;
  253. } __packed;
  254. /* test function runtime */
  255. struct test_dspfunc_debug {
  256. RINGBUF_TYPE inbuf;
  257. RINGBUF_TYPE refbuf;
  258. RINGBUF_TYPE outbuf;
  259. } __packed;
  260. /* test function information */
  261. struct test_dspfunc_info {
  262. struct test_dspfunc_params params;
  263. struct test_dspfunc_runtime runtime;
  264. } __packed;
  265. /* decoder resample function parameters */
  266. struct decoder_resample_params{
  267. uint32_t input_sr;
  268. uint32_t output_sr;
  269. uint32_t input_sample_pairs;
  270. uint32_t output_sample_pairs;
  271. } __packed;
  272. /* decoder function parameters */
  273. /* inbuf-->outbuf-->(resbuf)*/
  274. struct decoder_dspfunc_params {
  275. uint16_t slot; /* decoder slot */
  276. uint16_t format;
  277. uint16_t channels;
  278. uint16_t sample_bits;
  279. uint32_t sample_rate;
  280. RINGBUF_TYPE inbuf;
  281. RINGBUF_TYPE resbuf;
  282. RINGBUF_TYPE outbuf;
  283. struct decoder_resample_params resample_param;
  284. } __packed;
  285. /* decoder function extended parameters */
  286. struct decoder_dspfunc_ext_params {
  287. /* format specific parameter buffer */
  288. uint32_t format_pbuf;
  289. uint32_t format_pbufsz;
  290. /* store events passed by decoder */
  291. RINGBUF_TYPE evtbuf;
  292. } __packed;
  293. /* mix channel parameters */
  294. struct mix_channel_params{
  295. //uint16_t master_channel:1;
  296. uint16_t channels:2;
  297. uint16_t vol:6; // 0 ~ 31
  298. uint16_t is_mute:1;
  299. uint16_t mix_mode:3; //MIX_MODE_NULL ...
  300. uint16_t sample_bits:1; //0:16bit, 1:32bit
  301. uint16_t running:1;
  302. uint16_t master_channel:1;
  303. uint16_t reserved:1;
  304. uint16_t input_sr:8;
  305. uint16_t output_sr:8;
  306. RINGBUF_TYPE chan_buf;
  307. RINGBUF_TYPE res_buf;
  308. } __packed;
  309. /* mix function parameters */
  310. struct mix_dspfunc_params{
  311. uint32_t channel_num;
  312. struct mix_channel_params channel_params[DSP_SUPPORT_MULTI_BUFFER_NUM];
  313. } __packed;
  314. /* output function parameters */
  315. struct output_dspfunc_params{
  316. RINGBUF_TYPE outbuf;
  317. RINGBUF_TYPE outbuf_subwoofer;
  318. RINGBUF_TYPE hdrbuf;
  319. uint32_t sample_bits:1; //0:16bit, 1:32bit
  320. uint32_t reserved:31;
  321. } __packed;
  322. /* energy function parameters */
  323. struct energy_dspfunc_params{
  324. RINGBUF_TYPE energy_buf;
  325. } __packed;
  326. /* decoder function runtime */
  327. struct decoder_dspfunc_runtime {
  328. uint32_t frame_size;
  329. uint32_t channels;
  330. uint32_t sample_count;
  331. uint32_t datalost_count;
  332. uint32_t raw_count;
  333. } __packed;
  334. /* decoder function debug options */
  335. struct decoder_dspfunc_debug {
  336. RINGBUF_TYPE stream;
  337. RINGBUF_TYPE pcmbuf;
  338. RINGBUF_TYPE plcbuf;
  339. } __packed;
  340. /* decoder function information */
  341. struct decoder_dspfunc_info {
  342. struct decoder_dspfunc_params params;
  343. struct decoder_dspfunc_runtime runtime;
  344. struct decoder_dspfunc_debug debug;
  345. struct decoder_dspfunc_ext_params ext_params;
  346. } __packed;
  347. /* encoder function parameters */
  348. struct encoder_dspfunc_params {
  349. uint16_t slot; /* encoder slot */
  350. uint16_t format;
  351. uint16_t sub_format;
  352. uint16_t sample_bits;
  353. uint16_t sample_rate_orig;
  354. uint16_t sample_rate;
  355. uint32_t bit_rate; /* bps, bits per second */
  356. uint16_t complexity;
  357. uint16_t channels;
  358. uint32_t frame_size;
  359. RINGBUF_TYPE inbuf;
  360. RINGBUF_TYPE outbuf;
  361. } __packed;
  362. /* encoder function runtime */
  363. struct encoder_dspfunc_runtime {
  364. uint32_t frame_size;
  365. uint32_t channels;
  366. uint32_t compression_ratio;
  367. uint32_t sample_count;
  368. } __packed;
  369. /* encoder function debug options */
  370. struct encoder_dspfunc_debug {
  371. RINGBUF_TYPE pcmbuf;
  372. RINGBUF_TYPE stream;
  373. } __packed;
  374. /* encoder function information */
  375. struct encoder_dspfunc_info {
  376. struct encoder_dspfunc_params params;
  377. struct encoder_dspfunc_runtime runtime;
  378. struct encoder_dspfunc_debug debug;
  379. } __packed;
  380. /* preprocess function information */
  381. struct preprocess_dspfunc_info {
  382. struct encoder_dspfunc_params params;
  383. struct encoder_dspfunc_runtime runtime;
  384. struct encoder_dspfunc_debug debug;
  385. } __packed;
  386. /* dae function parameters */
  387. struct dae_dspfunc_params {
  388. uint32_t pbuf; /* parameter buffer address */
  389. uint32_t pbufsz; /* parameter buffer size */
  390. } __packed;
  391. struct aec_dspfunc_channel_params{
  392. /* aec reference stream type */
  393. int16_t stream_type;
  394. /* ref stream source buffers */
  395. RINGBUF_TYPE srcbuf;
  396. /* ref stream buffers */
  397. RINGBUF_TYPE refbuf;
  398. } __packed;
  399. /* aec refs channel parameters */
  400. struct aec_dspfunc_ref_params{
  401. /* delayed frames */
  402. int16_t delay;
  403. /* ref buffer num */
  404. int16_t channel_num;
  405. /* ref buffer num */
  406. struct aec_dspfunc_channel_params channel[DSP_SUPPORT_AEC_REFBUF_NUM];
  407. } __packed;
  408. /* aec function parameters */
  409. struct aec_dspfunc_params {
  410. /* aec enable or not and aec reterance type */
  411. int16_t enable; //0:disable 1:soft 2:hardware
  412. /* ref buffer num */
  413. int16_t channel_num;
  414. /* aec block size*/
  415. int16_t block_size;
  416. /* dropped count of mic samples to sync with aec reference */
  417. int16_t dropped_samples;
  418. /* mic data buffer */
  419. RINGBUF_TYPE inbuf;
  420. /* ref stream buffers */
  421. RINGBUF_TYPE refbuf[DSP_SUPPORT_AEC_REFBUF_NUM];
  422. /* aec out buffer */
  423. RINGBUF_TYPE outbuf;
  424. } __packed;
  425. /* misc function parameters */
  426. struct misc_dspfunc_parsms {
  427. int16_t auto_mute;
  428. int16_t auto_mute_threshold;
  429. int16_t reserved[2];
  430. }__packed;
  431. /* postprocessor function parameters */
  432. struct streamout_dspfunc_params {
  433. struct dae_dspfunc_params dae;
  434. struct aec_dspfunc_ref_params aec_ref;
  435. struct output_dspfunc_params output;
  436. struct mix_dspfunc_params mix;
  437. struct energy_dspfunc_params energy;
  438. struct misc_dspfunc_parsms misc;
  439. } __packed;
  440. /* postprocessor function runtime */
  441. struct streamout_dspfunc_runtime {
  442. } __packed;
  443. /* postprocessor function debug options */
  444. struct streamout_dspfunc_debug {
  445. } __packed;
  446. /* encoder function information */
  447. struct streamout_dspfunc_info {
  448. struct streamout_dspfunc_params params;
  449. struct streamout_dspfunc_runtime runtime;
  450. struct streamout_dspfunc_debug debug;
  451. } __packed;
  452. /* player function debug options */
  453. struct player_dspfunc_debug {
  454. RINGBUF_TYPE decode_stream;
  455. RINGBUF_TYPE decode_data;
  456. RINGBUF_TYPE plc_data;
  457. } __packed;
  458. /* player function information */
  459. struct player_dspfunc_info {
  460. struct dae_dspfunc_params dae;
  461. struct aec_dspfunc_ref_params aec_ref;
  462. struct output_dspfunc_params output;
  463. const struct decoder_dspfunc_info *decoder_info;
  464. struct mix_dspfunc_params mix;
  465. struct player_dspfunc_debug debug;
  466. struct energy_dspfunc_params energy;
  467. const struct streamout_dspfunc_info *streamout_info;
  468. } __packed;
  469. /* recorder function debug options */
  470. struct recorder_dspfunc_debug {
  471. RINGBUF_TYPE mic1_data;
  472. RINGBUF_TYPE mic2_data;
  473. RINGBUF_TYPE ref_data;
  474. RINGBUF_TYPE aec1_data;
  475. RINGBUF_TYPE aec2_data;
  476. RINGBUF_TYPE encode_data;
  477. RINGBUF_TYPE encode_stream;
  478. } __packed;
  479. /* recorder function information */
  480. struct recorder_dspfunc_info {
  481. struct dae_dspfunc_params dae;
  482. struct aec_dspfunc_params aec;
  483. const struct preprocess_dspfunc_info * preprocess_info;
  484. const struct encoder_dspfunc_info * encoder_info;
  485. struct recorder_dspfunc_debug debug;
  486. } __packed;
  487. #ifdef __cplusplus
  488. }
  489. #endif
  490. #endif /* _DSP_HAL_DEFS_H_ */