audio.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * File : audio.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2017-05-09 Urey first version
  23. */
  24. #ifndef __AUDIO_H__
  25. #define __AUDIO_H__
  26. /* AUDIO command */
  27. #define _AUDIO_CTL(a) (0x10 + a)
  28. #define AUDIO_CTL_GETCAPS _AUDIO_CTL(1)
  29. #define AUDIO_CTL_CONFIGURE _AUDIO_CTL(2)
  30. #define AUDIO_CTL_SHUTDOWN _AUDIO_CTL(3)
  31. #define AUDIO_CTL_START _AUDIO_CTL(4)
  32. #define AUDIO_CTL_STOP _AUDIO_CTL(5)
  33. #define AUDIO_CTL_PAUSE _AUDIO_CTL(6)
  34. #define AUDIO_CTL_RESUME _AUDIO_CTL(7)
  35. #define AUDIO_CTL_GETBUFFERINFO _AUDIO_CTL(8)
  36. #define AUDIO_CTL_ALLOCBUFFER _AUDIO_CTL(9)
  37. #define AUDIO_CTL_FREEBUFFER _AUDIO_CTL(10)
  38. #define AUDIO_CTL_HWRESET _AUDIO_CTL(11)
  39. /* Audio Device Types */
  40. #define AUDIO_TYPE_QUERY 0x00
  41. #define AUDIO_TYPE_INPUT 0x01
  42. #define AUDIO_TYPE_OUTPUT 0x02
  43. #define AUDIO_TYPE_MIXER 0x04
  44. #define AUDIO_TYPE_SELECTOR 0x08
  45. #define AUDIO_TYPE_EFFECT 0x10
  46. /* Audio Format Types */
  47. #define AUDIO_FMT_PCM_U8 0x0001
  48. #define AUDIO_FMT_PCM_S8 0x0002
  49. #define AUDIO_FMT_PCM_U16_LE 0x0010
  50. #define AUDIO_FMT_PCM_S16_BE 0x0020
  51. #define AUDIO_FMT_PCM_S16_LE 0x0040
  52. #define AUDIO_FMT_PCM_U16_BE 0x0080
  53. #define AUDIO_FMT_PCM_U24_LE 0x0100
  54. #define AUDIO_FMT_PCM_S24_BE 0x0200
  55. #define AUDIO_FMT_PCM_S24_LE 0x0400
  56. #define AUDIO_FMT_PCM_U24_BE 0x0800
  57. #define AUDIO_FMT_PCM_U32_LE 0x1000
  58. #define AUDIO_FMT_PCM_S32_BE 0x2000
  59. #define AUDIO_FMT_PCM_S32_LE 0x4000
  60. #define AUDIO_FMT_PCM_U32_BE 0x8000
  61. /* Supported Sampling Rates */
  62. #define AUDIO_SAMP_RATE_8K 0x0001
  63. #define AUDIO_SAMP_RATE_11K 0x0002
  64. #define AUDIO_SAMP_RATE_16K 0x0004
  65. #define AUDIO_SAMP_RATE_22K 0x0008
  66. #define AUDIO_SAMP_RATE_32K 0x0010
  67. #define AUDIO_SAMP_RATE_44K 0x0020
  68. #define AUDIO_SAMP_RATE_48K 0x0040
  69. #define AUDIO_SAMP_RATE_96K 0x0080
  70. #define AUDIO_SAMP_RATE_128K 0x0100
  71. #define AUDIO_SAMP_RATE_160K 0x0200
  72. #define AUDIO_SAMP_RATE_172K 0x0400
  73. #define AUDIO_SAMP_RATE_192K 0x0800
  74. /* Supported Bit Rates */
  75. #define AUDIO_BIT_RATE_22K 0x01
  76. #define AUDIO_BIT_RATE_44K 0x02
  77. #define AUDIO_BIT_RATE_48K 0x04
  78. #define AUDIO_BIT_RATE_96K 0x08
  79. #define AUDIO_BIT_RATE_128K 0x10
  80. #define AUDIO_BIT_RATE_160K 0x20
  81. #define AUDIO_BIT_RATE_172K 0x40
  82. #define AUDIO_BIT_RATE_192K 0x80
  83. /* Support Dsp(input/output) Units controls */
  84. #define AUDIO_DSP_PARAM 0 /* get/set all params */
  85. #define AUDIO_DSP_SAMPLERATE 1 /* ²ÉÑùƵÂÊ */
  86. #define AUDIO_DSP_FMT 2
  87. #define AUDIO_DSP_CHANNELS 3
  88. /* Supported Mixer Units controls */
  89. #define AUDIO_MIXER_QUERY 0x0000
  90. #define AUDIO_MIXER_MUTE 0x0001
  91. #define AUDIO_MIXER_VOLUME 0x0002
  92. #define AUDIO_MIXER_BASS 0x0004
  93. #define AUDIO_MIXER_MID 0x0008
  94. #define AUDIO_MIXER_TREBLE 0x0010
  95. #define AUDIO_MIXER_EQUALIZER 0x0020
  96. #define AUDIO_MIXER_LINE 0x0040
  97. #define AUDIO_MIXER_DIGITAL 0x0080
  98. #define AUDIO_MIXER_MIC 0x0100
  99. #define AUDIO_MIXER_EXTEND 0x8000 //extend mixer command
  100. #define CFG_AUDIO_REPLAY_QUEUE_COUNT 4
  101. #define CFG_AUDIO_RECORD_PIPE_SIZE (8 * 1024)
  102. #define AUDIO_DEVICE_MP_CNT (4)
  103. #define AUDIO_DEVICE_DECODE_MP_BLOCK_SZ (4352 * 4)
  104. #define AUDIO_DEVICE_DECODE_MP_SZ ((AUDIO_DEVICE_DECODE_MP_BLOCK_SZ*2 + 4)*AUDIO_DEVICE_MP_CNT)
  105. enum
  106. {
  107. AUDIO_STREAM_REPLAY = 0,
  108. AUDIO_STREAM_RECORD,
  109. AUDIO_STREAM_LAST = AUDIO_STREAM_RECORD,
  110. };
  111. /* the preferred number and size of audio pipeline buffer for the audio device */
  112. struct rt_audio_buf_info
  113. {
  114. rt_uint32_t buffer_size; /* Preferred qty of buffers */
  115. rt_uint32_t buffer_count; /* Preferred size of the buffers */
  116. };
  117. struct rt_audio_buf_desc
  118. {
  119. rt_uint8_t *data_ptr;
  120. rt_size_t data_size;
  121. };
  122. struct rt_audio_frame
  123. {
  124. const void *data_ptr;
  125. rt_size_t data_size;
  126. };
  127. struct rt_audio_device;
  128. struct rt_audio_caps;
  129. struct rt_audio_configure;
  130. struct rt_audio_ops
  131. {
  132. rt_err_t (*getcaps) (struct rt_audio_device *audio,struct rt_audio_caps *caps);
  133. rt_err_t (*configure) (struct rt_audio_device *audio,struct rt_audio_caps *caps);
  134. rt_err_t (*init) (struct rt_audio_device *audio);
  135. rt_err_t (*shutdown) (struct rt_audio_device *audio);
  136. rt_err_t (*start) (struct rt_audio_device *audio,int stream);
  137. rt_err_t (*stop) (struct rt_audio_device *audio,int stream);
  138. rt_err_t (*suspend) (struct rt_audio_device *audio,int stream);
  139. rt_err_t (*resume) (struct rt_audio_device *audio,int stream);
  140. rt_err_t (*control) (struct rt_audio_device *audio, int cmd, void *arg);
  141. rt_size_t (*transmit) (struct rt_audio_device *audio, const void *writeBuf,void *readBuf, rt_size_t size);
  142. //get page size of codec or private buffer's info
  143. void (*buffer_info) (struct rt_audio_device *audio,struct rt_audio_buf_info *info );
  144. };
  145. struct rt_audio_configure
  146. {
  147. rt_uint32_t channels;
  148. rt_uint32_t samplefmt;
  149. rt_uint32_t samplerate;
  150. rt_uint32_t samplefmts;
  151. };
  152. struct rt_audio_caps
  153. {
  154. int main_type;
  155. int sub_type;
  156. union
  157. {
  158. rt_uint32_t mask;
  159. int value;
  160. struct rt_audio_configure config;
  161. }udata;
  162. };
  163. struct rt_audio_replay
  164. {
  165. rt_bool_t activated;
  166. struct rt_data_queue queue;
  167. };
  168. struct rt_audio_record
  169. {
  170. rt_bool_t activated;
  171. };
  172. struct rt_audio_device
  173. {
  174. struct rt_device parent;
  175. struct rt_audio_ops *ops;
  176. struct rt_mempool mp;
  177. struct rt_audio_replay *replay;
  178. struct rt_audio_record *record;
  179. };
  180. rt_err_t rt_audio_register (struct rt_audio_device *audio, const char *name, rt_uint32_t flag, void *data);
  181. void rt_audio_tx_complete (struct rt_audio_device *audio,rt_uint8_t *pbuf);
  182. void rt_audio_rx_done (struct rt_audio_device *audio,rt_uint8_t *pbuf,rt_size_t len);
  183. rt_uint32_t rt_audio_format_to_bits (rt_uint32_t format);
  184. /* Device Control Commands */
  185. #define CODEC_CMD_RESET 0
  186. #define CODEC_CMD_SET_VOLUME 1
  187. #define CODEC_CMD_GET_VOLUME 2
  188. #define CODEC_CMD_SAMPLERATE 3
  189. #define CODEC_CMD_EQ 4
  190. #define CODEC_CMD_3D 5
  191. #define CODEC_VOLUME_MAX (63)
  192. #endif /* __AUDIO_H__ */