luat_audio.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef __LUAT_AUDIO_H__
  22. #define __LUAT_AUDIO_H__
  23. #include "luat_base.h"
  24. #ifndef __BSP_COMMON_H__
  25. #include "c_common.h"
  26. #endif
  27. /**
  28. * @brief 播放指定数量的文件或者ROM数组(文件数据直接写成数组形式)
  29. *
  30. * @param multimedia_id 多媒体通道,目前只有0
  31. * @param info 文件信息,文件路径信息
  32. * @param files_num 文件数量
  33. * @return int =0成功,其他失败
  34. */
  35. int luat_audio_play_multi_files(uint8_t multimedia_id, uData_t *info, uint32_t files_num, uint8_t error_stop);
  36. /**
  37. * @brief 播放指定的文件或
  38. *
  39. * @param multimedia_id 多媒体通道,目前只有0
  40. * @param path 文件路径
  41. * @return int =0成功,其他失败
  42. */
  43. int luat_audio_play_file(uint8_t multimedia_id, const char *path);
  44. /**
  45. * @brief 是否播放完全部数据
  46. *
  47. * @param multimedia_id multimedia_id 多媒体通道,目前只有0
  48. * @return uint8_t =1是,=0没有
  49. */
  50. uint8_t luat_audio_is_finish(uint8_t multimedia_id);
  51. /**
  52. * @brief 强制停止播放文件,但是不会停止已经输出到底层驱动的数据播放
  53. *
  54. * @param multimedia_id multimedia_id 多媒体通道,目前只有0
  55. * @return int =0成功,其他失败
  56. */
  57. int luat_audio_play_stop(uint8_t multimedia_id);
  58. /**
  59. * @brief 获取上一次播放结果,在MULTIMEDIA_CB_AUDIO_DONE回调时调用最佳
  60. *
  61. * @param multimedia_id multimedia_id 多媒体通道,目前只有0
  62. * @return int =0完整的播放完成,<0被用户停止了,>0 TTS失败,或者第几个音频文件解码失败(用户在play_info未设置了解码失败后继续,文件位置+1)
  63. */
  64. int luat_audio_play_get_last_error(uint8_t multimedia_id);
  65. /**
  66. * @brief 立刻初始化播放未编码的原始音频数据流
  67. *
  68. * @param multimedia_id multimedia_id 多媒体通道,目前只有0
  69. * @param audio_format 音频数据格式,目前只支持PCM,即需要手动解码
  70. * @param num_channels 声道数,目前只能1或2
  71. * @param sample_rate 采样率,注意只有8K,16K,32K,48K,96K,22.05K,44.1K这些能被支持
  72. * @param bits_per_sample 量化bit,只能是16
  73. * @param is_signed 量化数据是否带符号,只能是1
  74. * @return int =0成功,其他失败
  75. */
  76. int luat_audio_start_raw(uint8_t multimedia_id, uint8_t audio_format, uint8_t num_channels, uint32_t sample_rate, uint8_t bits_per_sample, uint8_t is_signed);
  77. /**
  78. * @brief 向底层驱动传入一段原始音频数据
  79. *
  80. * @param multimedia_id multimedia_id 多媒体通道,目前只有0
  81. * @param data 原始音频数据
  82. * @param len 原始音频数据长度
  83. * @return int =0成功,其他失败
  84. */
  85. int luat_audio_write_raw(uint8_t multimedia_id, uint8_t *data, uint32_t len);
  86. /**
  87. * @brief 强制停止所有播放,同时底层驱动也会停止输出,不要用于播放文件的结束
  88. *
  89. * @param multimedia_id multimedia_id 多媒体通道,目前只有0
  90. * @return int =0成功,其他失败
  91. */
  92. int luat_audio_stop_raw(uint8_t multimedia_id);
  93. /**
  94. * @brief 暂停/恢复播放
  95. *
  96. * @param multimedia_id multimedia_id 多媒体通道,目前只有0
  97. * @param is_pause 0恢复,其他暂停
  98. * @return int =0成功,其他失败
  99. */
  100. int luat_audio_pause_raw(uint8_t multimedia_id, uint8_t is_pause);
  101. /**
  102. * @brief 编码并播放一段文字
  103. *
  104. * @param multimedia_id multimedia_id 多媒体通道,目前只有0
  105. * @param text 文字数据
  106. * @param text_bytes 文字数据长度
  107. * @return int =0成功,其他失败
  108. */
  109. int luat_audio_play_tts_text(uint32_t multimedia_id, void *text, uint32_t text_bytes);
  110. /**
  111. * @brief 在收到MULTIMEDIA_CB_TTS_INIT回调时,可以设置TTS参数,等同于ivTTS_SetParam
  112. *
  113. * @param multimedia_id multimedia_id 多媒体通道,目前只有0
  114. * @param param_id 见ivTTS_PARAM_XXX
  115. * @param param_value param_id对应的value
  116. * @return int =0成功,其他失败
  117. */
  118. int luat_audio_play_tts_set_param(uint32_t multimedia_id, uint32_t param_id, uint32_t param_value);
  119. void luat_audio_config_pa(uint8_t multimedia_id, uint32_t pin, int level, uint32_t dummy_time_len, uint32_t pa_delay_time);
  120. void luat_audio_config_dac(uint8_t multimedia_id, int pin, int level, uint32_t dac_off_delay_time);
  121. uint16_t luat_audio_vol(uint8_t multimedia_id, uint16_t vol);
  122. /**
  123. * @brief 设置音频硬件输出类型
  124. *
  125. * @param bus_type 见MULTIMEDIA_AUDIO_BUS,目前只有0=DAC 1=I2S 2=SOFT_DAC
  126. */
  127. void luat_audio_set_bus_type(uint8_t bus_type);
  128. #endif