audio.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017-05-09 Urey first version
  9. */
  10. #ifndef __AUDIO_H__
  11. #define __AUDIO_H__
  12. /* AUDIO command */
  13. #define _AUDIO_CTL(a) (0x10 + a)
  14. #define AUDIO_CTL_GETCAPS _AUDIO_CTL(1)
  15. #define AUDIO_CTL_CONFIGURE _AUDIO_CTL(2)
  16. #define AUDIO_CTL_SHUTDOWN _AUDIO_CTL(3)
  17. #define AUDIO_CTL_START _AUDIO_CTL(4)
  18. #define AUDIO_CTL_STOP _AUDIO_CTL(5)
  19. #define AUDIO_CTL_PAUSE _AUDIO_CTL(6)
  20. #define AUDIO_CTL_RESUME _AUDIO_CTL(7)
  21. #define AUDIO_CTL_GETBUFFERINFO _AUDIO_CTL(8)
  22. #define AUDIO_CTL_ALLOCBUFFER _AUDIO_CTL(9)
  23. #define AUDIO_CTL_FREEBUFFER _AUDIO_CTL(10)
  24. #define AUDIO_CTL_HWRESET _AUDIO_CTL(11)
  25. /* Audio Device Types */
  26. #define AUDIO_TYPE_QUERY 0x00
  27. #define AUDIO_TYPE_INPUT 0x01
  28. #define AUDIO_TYPE_OUTPUT 0x02
  29. #define AUDIO_TYPE_MIXER 0x04
  30. #define AUDIO_TYPE_SELECTOR 0x08
  31. #define AUDIO_TYPE_EFFECT 0x10
  32. /* Audio Format Types */
  33. #define AUDIO_FMT_PCM_U8 0x0001
  34. #define AUDIO_FMT_PCM_S8 0x0002
  35. #define AUDIO_FMT_PCM_U16_LE 0x0010
  36. #define AUDIO_FMT_PCM_S16_BE 0x0020
  37. #define AUDIO_FMT_PCM_S16_LE 0x0040
  38. #define AUDIO_FMT_PCM_U16_BE 0x0080
  39. #define AUDIO_FMT_PCM_U24_LE 0x0100
  40. #define AUDIO_FMT_PCM_S24_BE 0x0200
  41. #define AUDIO_FMT_PCM_S24_LE 0x0400
  42. #define AUDIO_FMT_PCM_U24_BE 0x0800
  43. #define AUDIO_FMT_PCM_U32_LE 0x1000
  44. #define AUDIO_FMT_PCM_S32_BE 0x2000
  45. #define AUDIO_FMT_PCM_S32_LE 0x4000
  46. #define AUDIO_FMT_PCM_U32_BE 0x8000
  47. /* Supported Sampling Rates */
  48. #define AUDIO_SAMP_RATE_8K 0x0001
  49. #define AUDIO_SAMP_RATE_11K 0x0002
  50. #define AUDIO_SAMP_RATE_16K 0x0004
  51. #define AUDIO_SAMP_RATE_22K 0x0008
  52. #define AUDIO_SAMP_RATE_32K 0x0010
  53. #define AUDIO_SAMP_RATE_44K 0x0020
  54. #define AUDIO_SAMP_RATE_48K 0x0040
  55. #define AUDIO_SAMP_RATE_96K 0x0080
  56. #define AUDIO_SAMP_RATE_128K 0x0100
  57. #define AUDIO_SAMP_RATE_160K 0x0200
  58. #define AUDIO_SAMP_RATE_172K 0x0400
  59. #define AUDIO_SAMP_RATE_192K 0x0800
  60. /* Supported Bit Rates */
  61. #define AUDIO_BIT_RATE_22K 0x01
  62. #define AUDIO_BIT_RATE_44K 0x02
  63. #define AUDIO_BIT_RATE_48K 0x04
  64. #define AUDIO_BIT_RATE_96K 0x08
  65. #define AUDIO_BIT_RATE_128K 0x10
  66. #define AUDIO_BIT_RATE_160K 0x20
  67. #define AUDIO_BIT_RATE_172K 0x40
  68. #define AUDIO_BIT_RATE_192K 0x80
  69. /* Support Dsp(input/output) Units controls */
  70. #define AUDIO_DSP_PARAM 0 /* get/set all params */
  71. #define AUDIO_DSP_SAMPLERATE 1 /* 采样频率 */
  72. #define AUDIO_DSP_FMT 2
  73. #define AUDIO_DSP_CHANNELS 3
  74. /* Supported Mixer Units controls */
  75. #define AUDIO_MIXER_QUERY 0x0000
  76. #define AUDIO_MIXER_MUTE 0x0001
  77. #define AUDIO_MIXER_VOLUME 0x0002
  78. #define AUDIO_MIXER_BASS 0x0004
  79. #define AUDIO_MIXER_MID 0x0008
  80. #define AUDIO_MIXER_TREBLE 0x0010
  81. #define AUDIO_MIXER_EQUALIZER 0x0020
  82. #define AUDIO_MIXER_LINE 0x0040
  83. #define AUDIO_MIXER_DIGITAL 0x0080
  84. #define AUDIO_MIXER_MIC 0x0100
  85. #define AUDIO_MIXER_EXTEND 0x8000 //extend mixer command
  86. #define CFG_AUDIO_REPLAY_QUEUE_COUNT 4
  87. #define CFG_AUDIO_RECORD_PIPE_SIZE (8 * 1024)
  88. #define AUDIO_DEVICE_MP_CNT (4)
  89. #define AUDIO_DEVICE_DECODE_MP_BLOCK_SZ (4352 * 4)
  90. #define AUDIO_DEVICE_DECODE_MP_SZ ((AUDIO_DEVICE_DECODE_MP_BLOCK_SZ*2 + 4)*AUDIO_DEVICE_MP_CNT)
  91. enum
  92. {
  93. AUDIO_STREAM_REPLAY = 0,
  94. AUDIO_STREAM_RECORD,
  95. AUDIO_STREAM_LAST = AUDIO_STREAM_RECORD,
  96. };
  97. /* the preferred number and size of audio pipeline buffer for the audio device */
  98. struct rt_audio_buf_info
  99. {
  100. rt_uint32_t buffer_size; /* Preferred qty of buffers */
  101. rt_uint32_t buffer_count; /* Preferred size of the buffers */
  102. };
  103. struct rt_audio_buf_desc
  104. {
  105. rt_uint8_t *data_ptr;
  106. rt_size_t data_size;
  107. };
  108. struct rt_audio_frame
  109. {
  110. const void *data_ptr;
  111. rt_size_t data_size;
  112. };
  113. struct rt_audio_device;
  114. struct rt_audio_caps;
  115. struct rt_audio_configure;
  116. struct rt_audio_ops
  117. {
  118. rt_err_t (*getcaps) (struct rt_audio_device *audio,struct rt_audio_caps *caps);
  119. rt_err_t (*configure) (struct rt_audio_device *audio,struct rt_audio_caps *caps);
  120. rt_err_t (*init) (struct rt_audio_device *audio);
  121. rt_err_t (*shutdown) (struct rt_audio_device *audio);
  122. rt_err_t (*start) (struct rt_audio_device *audio,int stream);
  123. rt_err_t (*stop) (struct rt_audio_device *audio,int stream);
  124. rt_err_t (*suspend) (struct rt_audio_device *audio,int stream);
  125. rt_err_t (*resume) (struct rt_audio_device *audio,int stream);
  126. rt_err_t (*control) (struct rt_audio_device *audio, int cmd, void *arg);
  127. rt_size_t (*transmit) (struct rt_audio_device *audio, const void *writeBuf,void *readBuf, rt_size_t size);
  128. //get page size of codec or private buffer's info
  129. void (*buffer_info) (struct rt_audio_device *audio,struct rt_audio_buf_info *info );
  130. };
  131. struct rt_audio_configure
  132. {
  133. rt_uint32_t channels;
  134. rt_uint32_t samplefmt;
  135. rt_uint32_t samplerate;
  136. rt_uint32_t samplefmts;
  137. };
  138. struct rt_audio_caps
  139. {
  140. int main_type;
  141. int sub_type;
  142. union
  143. {
  144. rt_uint32_t mask;
  145. int value;
  146. struct rt_audio_configure config;
  147. }udata;
  148. };
  149. struct rt_audio_replay
  150. {
  151. rt_bool_t activated;
  152. struct rt_data_queue queue;
  153. };
  154. struct rt_audio_record
  155. {
  156. rt_bool_t activated;
  157. };
  158. struct rt_audio_device
  159. {
  160. struct rt_device parent;
  161. struct rt_audio_ops *ops;
  162. struct rt_mempool mp;
  163. struct rt_audio_replay *replay;
  164. struct rt_audio_record *record;
  165. };
  166. rt_err_t rt_audio_register (struct rt_audio_device *audio, const char *name, rt_uint32_t flag, void *data);
  167. void rt_audio_tx_complete (struct rt_audio_device *audio,rt_uint8_t *pbuf);
  168. void rt_audio_rx_done (struct rt_audio_device *audio,rt_uint8_t *pbuf,rt_size_t len);
  169. rt_uint32_t rt_audio_format_to_bits (rt_uint32_t format);
  170. /* Device Control Commands */
  171. #define CODEC_CMD_RESET 0
  172. #define CODEC_CMD_SET_VOLUME 1
  173. #define CODEC_CMD_GET_VOLUME 2
  174. #define CODEC_CMD_SAMPLERATE 3
  175. #define CODEC_CMD_EQ 4
  176. #define CODEC_CMD_3D 5
  177. #define CODEC_VOLUME_MAX (63)
  178. #endif /* __AUDIO_H__ */