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