77 * Date Author Notes
88 * 2017-05-09 Urey first version
99 * 2019-07-09 Zero-Free improve device ops interface and data flows
10- *
10+ * 2025-03-04 wumingzi add doxygen comments.
1111 */
1212
1313#ifndef __DEV_AUDIO_H__
5454#define AUDIO_CTL_STOP _AUDIO_CTL(4) /**< Stop audio device */
5555#define AUDIO_CTL_GETBUFFERINFO _AUDIO_CTL(5) /**< Get audio device buffer information */
5656
57- /** @} */ /* End of audio_control*/
57+ /** @} */ /* End of audio_control */
5858
5959/**
6060 * @defgroup audio_type AUDIO_TYPE
7070#define AUDIO_TYPE_INPUT 0x01 /**< Set audio device type to input type */
7171#define AUDIO_TYPE_OUTPUT 0x02 /**< Set audio device type to output type */
7272#define AUDIO_TYPE_MIXER 0x04 /**< Set audio device type to mixer type */
73- /** @} */ /* End of audio_type*/
73+ /** @} */ /* End of audio_type */
7474
7575/**
7676 * @defgroup audio_samp_rates AUDIO_SAMP_RATES
9494#define AUDIO_SAMP_RATE_160K 0x0200 /**< Set audio device sample rate to 160K */
9595#define AUDIO_SAMP_RATE_172K 0x0400 /**< Set audio device sample rate to 172K */
9696#define AUDIO_SAMP_RATE_192K 0x0800 /**< Set audio device sample rate to 192K */
97- /** @} */ /* End of audio_samp_rates*/
97+ /** @} */ /* End of audio_samp_rates */
9898
9999/**
100100 * @defgroup audio_bit_rates AUDIO_BIT_RATES
114114#define AUDIO_BIT_RATE_160K 0x20 /**< Set audio device bit rates to 160K */
115115#define AUDIO_BIT_RATE_172K 0x40 /**< Set audio device bit rates to 172K */
116116#define AUDIO_BIT_RATE_192K 0x80 /**< Set audio device bit rates to 192K */
117- /** @} */ /* End of audio_bit_rates*/
117+ /** @} */ /* End of audio_bit_rates */
118118
119119
120120/**
121121 * @defgroup audio_dsp AUDIO_DSP
122122 *
123- * @brief Support Dsp(input/output) Units controls
123+ * @brief Support Dsp(input/output) Units controls. The macro group from application level, can
124+ * set audio mixer parameters including samplerate, channels etc.
124125 */
125126
126127/**
131132#define AUDIO_DSP_SAMPLERATE 1 /**< samplerate */
132133#define AUDIO_DSP_CHANNELS 2 /**< channels */
133134#define AUDIO_DSP_SAMPLEBITS 3 /**< sample bits width */
134- /** @} */ /* End of audio_dsp*/
135+ /** @} */ /* End of audio_dsp */
135136
136137/**
137138 * @defgroup audio_mixer AUDIO_MIXER
138139 *
139- * @brief Supported Mixer Units controls
140+ * @brief Supported Mixer Units controls. The macro group from driver level, can set audio mixer
141+ * parameters including volume, frequence db, microphone etc.
140142 */
141143
142144/**
147149#define AUDIO_MIXER_MUTE 0x0001 /**< Mute audio device */
148150#define AUDIO_MIXER_VOLUME 0x0002 /**< Set mixer volume */
149151#define AUDIO_MIXER_BASS 0x0004 /**< Set the low-frequency section of the mixer */
150- #define AUDIO_MIXER_MID 0x0008 /**< Set the mid-frequency section of the mixer*/
152+ #define AUDIO_MIXER_MID 0x0008 /**< Set the mid-frequency section of the mixer */
151153#define AUDIO_MIXER_TREBLE 0x0010 /**< Set the high-frequency section of the mixer */
152154#define AUDIO_MIXER_EQUALIZER 0x0020 /**< Set equalizer option */
153155#define AUDIO_MIXER_LINE 0x0040 /**< Set line control option */
154156#define AUDIO_MIXER_DIGITAL 0x0080 /**< Set digital source */
155157#define AUDIO_MIXER_MIC 0x0100 /**< Set microphone option */
156158#define AUDIO_MIXER_VITURAL 0x0200 /**< Set virtual audio option */
157159#define AUDIO_MIXER_EXTEND 0x8000 /**< Extend mixer command */
158- /** @} */ /* End of audio_mixer*/
160+ /** @} */ /* End of audio_mixer */
159161
160162#define AUDIO_VOLUME_MAX (100)
161163#define AUDIO_VOLUME_MIN (0)
@@ -181,24 +183,35 @@ enum
181183 */
182184struct rt_audio_buf_info
183185{
184- rt_uint8_t * buffer ;
185- rt_uint16_t block_size ;
186- rt_uint16_t block_count ;
187- rt_uint32_t total_size ;
186+ rt_uint8_t * buffer ; /**< Audio buffer information */
187+ rt_uint16_t block_size ; /**< Audio block_size information for replay function */
188+ rt_uint16_t block_count ; /**< Audio block_count information for replay function */
189+ rt_uint32_t total_size ; /**< Audio total_size which is equal to block_size multiplying
190+ block_count information for replay function */
188191};
189192
190193struct rt_audio_device ;
191194struct rt_audio_caps ;
192195struct rt_audio_configure ;
196+
197+ /**
198+ * @brief Aduio device operators
199+ */
193200struct rt_audio_ops
194201{
202+ /** Get audio capabilities information */
195203 rt_err_t (* getcaps )(struct rt_audio_device * audio , struct rt_audio_caps * caps );
204+ /** Configure audio devices */
196205 rt_err_t (* configure )(struct rt_audio_device * audio , struct rt_audio_caps * caps );
206+ /** Initialize audio device */
197207 rt_err_t (* init )(struct rt_audio_device * audio );
208+ /** Turn on the audio device */
198209 rt_err_t (* start )(struct rt_audio_device * audio , int stream );
210+ /** Turn off the audio device */
199211 rt_err_t (* stop )(struct rt_audio_device * audio , int stream );
212+ /** Transmit data between application and device */
200213 rt_ssize_t (* transmit )(struct rt_audio_device * audio , const void * writeBuf , void * readBuf , rt_size_t size );
201- /* get page size of codec or private buffer's info */
214+ /** Get page size of codec or private buffer's info */
202215 void (* buffer_info )(struct rt_audio_device * audio , struct rt_audio_buf_info * info );
203216};
204217
@@ -211,43 +224,45 @@ struct rt_audio_ops
211224 */
212225struct rt_audio_configure
213226{
214- rt_uint32_t samplerate ;
215- rt_uint16_t channels ;
216- rt_uint16_t samplebits ;
227+ rt_uint32_t samplerate ; /**< Audio samplerate information */
228+ rt_uint16_t channels ; /**< Audio channels information */
229+ rt_uint16_t samplebits ; /**< Audio samplebits information */
217230};
218231
219232/**
220233 * @brief Audio capabilities
221234 */
222235struct rt_audio_caps
223236{
224- int main_type ;
225- int sub_type ;
237+ int main_type ; /**< Audio main type, one value of @ref audio_type */
238+ int sub_type ; /**< Audio sub type, one value of @ref audio_dsp @ref audio_mixer */
226239
227240 union
228241 {
229- rt_uint32_t mask ;
230- int value ;
231- struct rt_audio_configure config ;
232- } udata ;
242+ rt_uint32_t mask ; /**< Capabilities mask */
243+ int value ; /**< Capabilities value */
244+ struct rt_audio_configure config ; /**< Audio samplebits information */
245+ } udata ; /**< User data */
233246};
234247
235248/**
236249 * @brief Audio replay
237250 */
238251struct rt_audio_replay
239252{
240- struct rt_mempool * mp ;
241- struct rt_data_queue queue ;
242- struct rt_mutex lock ;
243- struct rt_completion cmp ;
244- struct rt_audio_buf_info buf_info ;
245- rt_uint8_t * write_data ;
246- rt_uint16_t write_index ;
247- rt_uint16_t read_index ;
248- rt_uint32_t pos ;
249- rt_uint8_t event ;
250- rt_bool_t activated ;
253+ struct rt_mempool * mp ; /**< Memory pool for audio replay */
254+ struct rt_data_queue queue ; /**< Replay data queue */
255+ struct rt_mutex lock ; /**< Replay mutex lock */
256+ struct rt_completion cmp ; /**< Replay completion, it will be */
257+ struct rt_audio_buf_info buf_info ; /**< Replay buffer information */
258+ rt_uint8_t * write_data ; /**< Pointer to the data to be written into data queue */
259+ rt_uint16_t write_index ; /**< Index of pointer write_data.It records how much data
260+ has been written in currently being played block */
261+ rt_uint16_t read_index ; /**< Index of replaying data for audio device, it indicates index
262+ of replay in the blocks which is currently being played */
263+ rt_uint32_t pos ; /**< Global position of audio replay */
264+ rt_uint8_t event ; /**< Event flag */
265+ rt_bool_t activated ; /**< Activaty flag */
251266};
252267
253268/**
@@ -264,10 +279,10 @@ struct rt_audio_record
264279 */
265280struct rt_audio_device
266281{
267- struct rt_device parent ;
268- struct rt_audio_ops * ops ;
269- struct rt_audio_replay * replay ;
270- struct rt_audio_record * record ;
282+ struct rt_device parent ; /**< Audio device parents */
283+ struct rt_audio_ops * ops ; /**< Audio device operator */
284+ struct rt_audio_replay * replay ; /**< Pointer to audio replay structure */
285+ struct rt_audio_record * record ; /**< Pointer to audio record structure */
271286};
272287
273288rt_err_t rt_audio_register (struct rt_audio_device * audio , const char * name , rt_uint32_t flag , void * data );
@@ -277,7 +292,8 @@ void rt_audio_rx_done(struct rt_audio_device *audio, rt_uint8_t *pbuf, rt
277292/**
278293 * @defgroup audio_codec_cmd CODEC_CMD
279294 *
280- * @brief Device Control Commands
295+ * @brief Device Control Commands. The macro group from hardware level, can set codec
296+ * parametes including volume, EQ and 3D etc.
281297 */
282298
283299/**
@@ -292,7 +308,7 @@ void rt_audio_rx_done(struct rt_audio_device *audio, rt_uint8_t *pbuf, rt
292308#define CODEC_CMD_3D 5 /**< Set 3D effect by codec */
293309
294310#define CODEC_VOLUME_MAX (63)
295- /** @} */ /* End of audio_codec_cmd*/
311+ /** @} */ /* End of audio_codec_cmd */
296312
297313/** @} group_Audio */
298314
0 commit comments