RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dev_audio.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2023, 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 * 2019-07-09 Zero-Free improve device ops interface and data flows
10 *
11 */
12
13#ifndef __DEV_AUDIO_H__
14#define __DEV_AUDIO_H__
15
16#include "dev_audio_pipe.h"
17
18/* AUDIO command */
19#define _AUDIO_CTL(a) (RT_DEVICE_CTRL_BASE(Sound) + a)
20
21#define AUDIO_CTL_GETCAPS _AUDIO_CTL(1)
22#define AUDIO_CTL_CONFIGURE _AUDIO_CTL(2)
23#define AUDIO_CTL_START _AUDIO_CTL(3)
24#define AUDIO_CTL_STOP _AUDIO_CTL(4)
25#define AUDIO_CTL_GETBUFFERINFO _AUDIO_CTL(5)
26
27/* Audio Device Types */
28#define AUDIO_TYPE_QUERY 0x00
29#define AUDIO_TYPE_INPUT 0x01
30#define AUDIO_TYPE_OUTPUT 0x02
31#define AUDIO_TYPE_MIXER 0x04
32
33/* Supported Sampling Rates */
34#define AUDIO_SAMP_RATE_8K 0x0001
35#define AUDIO_SAMP_RATE_11K 0x0002
36#define AUDIO_SAMP_RATE_16K 0x0004
37#define AUDIO_SAMP_RATE_22K 0x0008
38#define AUDIO_SAMP_RATE_32K 0x0010
39#define AUDIO_SAMP_RATE_44K 0x0020
40#define AUDIO_SAMP_RATE_48K 0x0040
41#define AUDIO_SAMP_RATE_96K 0x0080
42#define AUDIO_SAMP_RATE_128K 0x0100
43#define AUDIO_SAMP_RATE_160K 0x0200
44#define AUDIO_SAMP_RATE_172K 0x0400
45#define AUDIO_SAMP_RATE_192K 0x0800
46
47/* Supported Bit Rates */
48#define AUDIO_BIT_RATE_22K 0x01
49#define AUDIO_BIT_RATE_44K 0x02
50#define AUDIO_BIT_RATE_48K 0x04
51#define AUDIO_BIT_RATE_96K 0x08
52#define AUDIO_BIT_RATE_128K 0x10
53#define AUDIO_BIT_RATE_160K 0x20
54#define AUDIO_BIT_RATE_172K 0x40
55#define AUDIO_BIT_RATE_192K 0x80
56
57/* Support Dsp(input/output) Units controls */
58#define AUDIO_DSP_PARAM 0 /* get/set all params */
59#define AUDIO_DSP_SAMPLERATE 1 /* samplerate */
60#define AUDIO_DSP_CHANNELS 2 /* channels */
61#define AUDIO_DSP_SAMPLEBITS 3 /* sample bits width */
62
63/* Supported Mixer Units controls */
64#define AUDIO_MIXER_QUERY 0x0000
65#define AUDIO_MIXER_MUTE 0x0001
66#define AUDIO_MIXER_VOLUME 0x0002
67#define AUDIO_MIXER_BASS 0x0004
68#define AUDIO_MIXER_MID 0x0008
69#define AUDIO_MIXER_TREBLE 0x0010
70#define AUDIO_MIXER_EQUALIZER 0x0020
71#define AUDIO_MIXER_LINE 0x0040
72#define AUDIO_MIXER_DIGITAL 0x0080
73#define AUDIO_MIXER_MIC 0x0100
74#define AUDIO_MIXER_VITURAL 0x0200
75#define AUDIO_MIXER_EXTEND 0x8000 /* extend mixer command */
76
77#define AUDIO_VOLUME_MAX (100)
78#define AUDIO_VOLUME_MIN (0)
79
80#define CFG_AUDIO_REPLAY_QUEUE_COUNT 4
81
82enum
83{
87};
88
89/* the preferred number and size of audio pipeline buffer for the audio device */
97
98struct rt_audio_device;
99struct rt_audio_caps;
100struct rt_audio_configure;
102{
103 rt_err_t (*getcaps)(struct rt_audio_device *audio, struct rt_audio_caps *caps);
104 rt_err_t (*configure)(struct rt_audio_device *audio, struct rt_audio_caps *caps);
105 rt_err_t (*init)(struct rt_audio_device *audio);
106 rt_err_t (*start)(struct rt_audio_device *audio, int stream);
107 rt_err_t (*stop)(struct rt_audio_device *audio, int stream);
108 rt_ssize_t (*transmit)(struct rt_audio_device *audio, const void *writeBuf, void *readBuf, rt_size_t size);
109 /* get page size of codec or private buffer's info */
110 void (*buffer_info)(struct rt_audio_device *audio, struct rt_audio_buf_info *info);
111};
112
119
121{
124
125 union
126 {
128 int value;
131};
132
147
149{
150 struct rt_audio_pipe pipe;
152};
153
161
162rt_err_t rt_audio_register(struct rt_audio_device *audio, const char *name, rt_uint32_t flag, void *data);
164void rt_audio_rx_done(struct rt_audio_device *audio, rt_uint8_t *pbuf, rt_size_t len);
165
166/* Device Control Commands */
167#define CODEC_CMD_RESET 0
168#define CODEC_CMD_SET_VOLUME 1
169#define CODEC_CMD_GET_VOLUME 2
170#define CODEC_CMD_SAMPLERATE 3
171#define CODEC_CMD_EQ 4
172#define CODEC_CMD_3D 5
173
174#define CODEC_VOLUME_MAX (63)
175
176#endif /* __DEV_AUDIO_H__ */
rt_err_t rt_audio_register(struct rt_audio_device *audio, const char *name, rt_uint32_t flag, void *data)
@ AUDIO_STREAM_LAST
@ AUDIO_STREAM_REPLAY
@ AUDIO_STREAM_RECORD
void rt_audio_tx_complete(struct rt_audio_device *audio)
void rt_audio_rx_done(struct rt_audio_device *audio, rt_uint8_t *pbuf, rt_size_t len)
rt_base_t rt_ssize_t
int rt_bool_t
rt_base_t rt_err_t
unsigned char rt_uint8_t
unsigned short rt_uint16_t
rt_ubase_t rt_size_t
unsigned int rt_uint32_t
rt_uint8_t * buffer
rt_uint16_t block_size
rt_uint32_t total_size
rt_uint16_t block_count
struct rt_audio_configure config
union rt_audio_caps::@100157007125373205103010077341215021254332336214 udata
rt_uint32_t mask
struct rt_audio_ops * ops
struct rt_audio_replay * replay
struct rt_audio_record * record
struct rt_device parent
rt_ssize_t(* transmit)(struct rt_audio_device *audio, const void *writeBuf, void *readBuf, rt_size_t size)
rt_err_t(* configure)(struct rt_audio_device *audio, struct rt_audio_caps *caps)
rt_err_t(* stop)(struct rt_audio_device *audio, int stream)
rt_err_t(* init)(struct rt_audio_device *audio)
rt_err_t(* getcaps)(struct rt_audio_device *audio, struct rt_audio_caps *caps)
void(* buffer_info)(struct rt_audio_device *audio, struct rt_audio_buf_info *info)
rt_err_t(* start)(struct rt_audio_device *audio, int stream)
struct rt_audio_pipe pipe
struct rt_audio_buf_info buf_info
rt_uint8_t * write_data
struct rt_mempool * mp
struct rt_data_queue queue
struct rt_completion cmp
rt_uint16_t read_index
struct rt_mutex lock
rt_uint16_t write_index