Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
逝缘~
rt-thread
提交
e855fb85
R
rt-thread
项目概览
逝缘~
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e855fb85
编写于
8月 06, 2019
作者:
E
EvalZero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[components][audio]improve device ops interface and data flows.
上级
87267b41
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
440 addition
and
393 deletion
+440
-393
components/drivers/Kconfig
components/drivers/Kconfig
+14
-0
components/drivers/audio/audio.c
components/drivers/audio/audio.c
+355
-286
components/drivers/audio/audio_pipe.c
components/drivers/audio/audio_pipe.c
+18
-14
components/drivers/include/drivers/audio.h
components/drivers/include/drivers/audio.h
+53
-93
未找到文件。
components/drivers/Kconfig
浏览文件 @
e855fb85
...
...
@@ -238,6 +238,20 @@ config RT_USING_WDT
config RT_USING_AUDIO
bool "Using Audio device drivers"
default n
if RT_USING_AUDIO
config RT_AUDIO_REPLAY_MP_BLOCK_SIZE
int "Replay memmory pool block size"
default 4096
config RT_AUDIO_REPLAY_MP_BLOCK_COUNT
int "Replay memmory pool block count"
default 2
config RT_AUDIO_RECORD_PIPE_SIZE
int "Record pipe size"
default 2048
endif
config RT_USING_SENSOR
bool "Using Sensor device drivers"
...
...
components/drivers/audio/audio.c
浏览文件 @
e855fb85
此差异已折叠。
点击以展开。
components/drivers/audio/audio_pipe.c
浏览文件 @
e855fb85
...
...
@@ -24,8 +24,8 @@ static void _rt_pipe_resume_writer(struct rt_audio_pipe *pipe)
/* get suspended thread */
thread
=
rt_list_entry
(
pipe
->
suspended_write_list
.
next
,
struct
rt_thread
,
tlist
);
struct
rt_thread
,
tlist
);
/* resume the write thread */
rt_thread_resume
(
thread
);
...
...
@@ -66,7 +66,8 @@ static rt_size_t rt_pipe_read(rt_device_t dev,
/* current context checking */
RT_DEBUG_NOT_IN_INTERRUPT
;
do
{
do
{
level
=
rt_hw_interrupt_disable
();
read_nbytes
=
rt_ringbuffer_get
(
&
(
pipe
->
ringbuffer
),
(
rt_uint8_t
*
)
buffer
,
size
);
if
(
read_nbytes
==
0
)
...
...
@@ -85,7 +86,8 @@ static rt_size_t rt_pipe_read(rt_device_t dev,
rt_hw_interrupt_enable
(
level
);
break
;
}
}
while
(
read_nbytes
==
0
);
}
while
(
read_nbytes
==
0
);
return
read_nbytes
;
}
...
...
@@ -104,8 +106,8 @@ static void _rt_pipe_resume_reader(struct rt_audio_pipe *pipe)
/* get suspended thread */
thread
=
rt_list_entry
(
pipe
->
suspended_read_list
.
next
,
struct
rt_thread
,
tlist
);
struct
rt_thread
,
tlist
);
/* resume the read thread */
rt_thread_resume
(
thread
);
...
...
@@ -128,7 +130,7 @@ static rt_size_t rt_pipe_write(rt_device_t dev,
RT_ASSERT
(
pipe
!=
RT_NULL
);
if
((
pipe
->
flag
&
RT_PIPE_FLAG_FORCE_WR
)
||
!
(
pipe
->
flag
&
RT_PIPE_FLAG_BLOCK_WR
))
!
(
pipe
->
flag
&
RT_PIPE_FLAG_BLOCK_WR
))
{
level
=
rt_hw_interrupt_disable
();
...
...
@@ -151,7 +153,8 @@ static rt_size_t rt_pipe_write(rt_device_t dev,
/* current context checking */
RT_DEBUG_NOT_IN_INTERRUPT
;
do
{
do
{
level
=
rt_hw_interrupt_disable
();
write_nbytes
=
rt_ringbuffer_put
(
&
(
pipe
->
ringbuffer
),
(
const
rt_uint8_t
*
)
buffer
,
size
);
if
(
write_nbytes
==
0
)
...
...
@@ -171,7 +174,8 @@ static rt_size_t rt_pipe_write(rt_device_t dev,
rt_hw_interrupt_enable
(
level
);
break
;
}
}
while
(
write_nbytes
==
0
);
}
while
(
write_nbytes
==
0
);
return
write_nbytes
;
}
...
...
@@ -183,7 +187,7 @@ static rt_err_t rt_pipe_control(rt_device_t dev, int cmd, void *args)
pipe
=
(
struct
rt_audio_pipe
*
)
dev
;
if
(
cmd
==
PIPE_CTRL_GET_SPACE
&&
args
)
*
(
rt_size_t
*
)
args
=
rt_ringbuffer_space_len
(
&
pipe
->
ringbuffer
);
*
(
rt_size_t
*
)
args
=
rt_ringbuffer_space_len
(
&
pipe
->
ringbuffer
);
return
RT_EOK
;
}
...
...
@@ -212,10 +216,10 @@ const static struct rt_device_ops audio_pipe_ops =
* @return the operation status, RT_EOK on successful
*/
rt_err_t
rt_audio_pipe_init
(
struct
rt_audio_pipe
*
pipe
,
const
char
*
name
,
rt_int32_t
flag
,
rt_uint8_t
*
buf
,
rt_size_t
size
)
const
char
*
name
,
rt_int32_t
flag
,
rt_uint8_t
*
buf
,
rt_size_t
size
)
{
RT_ASSERT
(
pipe
);
RT_ASSERT
(
buf
);
...
...
components/drivers/include/drivers/audio.h
浏览文件 @
e855fb85
...
...
@@ -5,52 +5,30 @@
*
* Change Logs:
* Date Author Notes
* 2017-05-09 Urey first version
* 2017-05-09 Urey first version
* 2019-07-09 Zero-Free improve device ops interface and data flows
*
*/
#ifndef __AUDIO_H__
#define __AUDIO_H__
#include "audio_pipe.h"
/* AUDIO command */
#define _AUDIO_CTL(a) (0x10 + a)
#define AUDIO_CTL_GETCAPS _AUDIO_CTL(1)
#define AUDIO_CTL_CONFIGURE _AUDIO_CTL(2)
#define AUDIO_CTL_SHUTDOWN _AUDIO_CTL(3)
#define AUDIO_CTL_START _AUDIO_CTL(4)
#define AUDIO_CTL_STOP _AUDIO_CTL(5)
#define AUDIO_CTL_PAUSE _AUDIO_CTL(6)
#define AUDIO_CTL_RESUME _AUDIO_CTL(7)
#define AUDIO_CTL_GETBUFFERINFO _AUDIO_CTL(8)
#define AUDIO_CTL_ALLOCBUFFER _AUDIO_CTL(9)
#define AUDIO_CTL_FREEBUFFER _AUDIO_CTL(10)
#define AUDIO_CTL_HWRESET _AUDIO_CTL(11)
#define AUDIO_CTL_START _AUDIO_CTL(3)
#define AUDIO_CTL_STOP _AUDIO_CTL(4)
#define AUDIO_CTL_GETBUFFERINFO _AUDIO_CTL(5)
/* Audio Device Types */
#define AUDIO_TYPE_QUERY 0x00
#define AUDIO_TYPE_INPUT 0x01
#define AUDIO_TYPE_OUTPUT 0x02
#define AUDIO_TYPE_MIXER 0x04
#define AUDIO_TYPE_SELECTOR 0x08
#define AUDIO_TYPE_EFFECT 0x10
/* Audio Format Types */
#define AUDIO_FMT_PCM_U8 0x0001
#define AUDIO_FMT_PCM_S8 0x0002
#define AUDIO_FMT_PCM_U16_LE 0x0010
#define AUDIO_FMT_PCM_S16_BE 0x0020
#define AUDIO_FMT_PCM_S16_LE 0x0040
#define AUDIO_FMT_PCM_U16_BE 0x0080
#define AUDIO_FMT_PCM_U24_LE 0x0100
#define AUDIO_FMT_PCM_S24_BE 0x0200
#define AUDIO_FMT_PCM_S24_LE 0x0400
#define AUDIO_FMT_PCM_U24_BE 0x0800
#define AUDIO_FMT_PCM_U32_LE 0x1000
#define AUDIO_FMT_PCM_S32_BE 0x2000
#define AUDIO_FMT_PCM_S32_LE 0x4000
#define AUDIO_FMT_PCM_U32_BE 0x8000
/* Supported Sampling Rates */
#define AUDIO_SAMP_RATE_8K 0x0001
...
...
@@ -76,13 +54,11 @@
#define AUDIO_BIT_RATE_172K 0x40
#define AUDIO_BIT_RATE_192K 0x80
/* Support Dsp(input/output) Units controls */
#define AUDIO_DSP_PARAM 0
/* get/set all params */
#define AUDIO_DSP_SAMPLERATE 1
/* 采样频率
*/
#define AUDIO_DSP_
FMT 2
#define AUDIO_DSP_
CHANNELS 3
#define AUDIO_DSP_SAMPLERATE 1
/* samplerate
*/
#define AUDIO_DSP_
CHANNELS 2
/* channels */
#define AUDIO_DSP_
SAMPLEBITS 3
/* sample bits width */
/* Supported Mixer Units controls */
#define AUDIO_MIXER_QUERY 0x0000
...
...
@@ -95,15 +71,13 @@
#define AUDIO_MIXER_LINE 0x0040
#define AUDIO_MIXER_DIGITAL 0x0080
#define AUDIO_MIXER_MIC 0x0100
#define AUDIO_MIXER_VITURAL 0x0200
#define AUDIO_MIXER_EXTEND 0x8000
/* extend mixer command */
#define AUDIO_MIXER_EXTEND 0x8000 //extend mixer command
#define AUDIO_VOLUME_MAX (100)
#define AUDIO_VOLUME_MIN (0)
#define CFG_AUDIO_REPLAY_QUEUE_COUNT 4
#define CFG_AUDIO_RECORD_PIPE_SIZE (8 * 1024)
#define AUDIO_DEVICE_MP_CNT (4)
#define AUDIO_DEVICE_DECODE_MP_BLOCK_SZ (4352 * 4)
#define AUDIO_DEVICE_DECODE_MP_SZ ((AUDIO_DEVICE_DECODE_MP_BLOCK_SZ*2 + 4)*AUDIO_DEVICE_MP_CNT)
enum
{
...
...
@@ -115,19 +89,10 @@ enum
/* the preferred number and size of audio pipeline buffer for the audio device */
struct
rt_audio_buf_info
{
rt_uint32_t
buffer_size
;
/* Preferred qty of buffers */
rt_uint32_t
buffer_count
;
/* Preferred size of the buffers */
};
struct
rt_audio_buf_desc
{
rt_uint8_t
*
data_ptr
;
rt_size_t
data_size
;
};
struct
rt_audio_frame
{
const
void
*
data_ptr
;
rt_size_t
data_size
;
rt_uint8_t
*
buffer
;
rt_uint16_t
block_size
;
rt_uint16_t
block_count
;
rt_uint32_t
total_size
;
};
struct
rt_audio_device
;
...
...
@@ -135,73 +100,68 @@ struct rt_audio_caps;
struct
rt_audio_configure
;
struct
rt_audio_ops
{
rt_err_t
(
*
getcaps
)
(
struct
rt_audio_device
*
audio
,
struct
rt_audio_caps
*
caps
);
rt_err_t
(
*
configure
)
(
struct
rt_audio_device
*
audio
,
struct
rt_audio_caps
*
caps
);
rt_err_t
(
*
init
)
(
struct
rt_audio_device
*
audio
);
rt_err_t
(
*
shutdown
)
(
struct
rt_audio_device
*
audio
);
rt_err_t
(
*
start
)
(
struct
rt_audio_device
*
audio
,
int
stream
);
rt_err_t
(
*
stop
)
(
struct
rt_audio_device
*
audio
,
int
stream
);
rt_err_t
(
*
suspend
)
(
struct
rt_audio_device
*
audio
,
int
stream
);
rt_err_t
(
*
resume
)
(
struct
rt_audio_device
*
audio
,
int
stream
);
rt_err_t
(
*
control
)
(
struct
rt_audio_device
*
audio
,
int
cmd
,
void
*
arg
);
rt_size_t
(
*
transmit
)
(
struct
rt_audio_device
*
audio
,
const
void
*
writeBuf
,
void
*
readBuf
,
rt_size_t
size
);
//get page size of codec or private buffer's info
void
(
*
buffer_info
)
(
struct
rt_audio_device
*
audio
,
struct
rt_audio_buf_info
*
info
);
rt_err_t
(
*
getcaps
)(
struct
rt_audio_device
*
audio
,
struct
rt_audio_caps
*
caps
);
rt_err_t
(
*
configure
)(
struct
rt_audio_device
*
audio
,
struct
rt_audio_caps
*
caps
);
rt_err_t
(
*
init
)(
struct
rt_audio_device
*
audio
);
rt_err_t
(
*
start
)(
struct
rt_audio_device
*
audio
,
int
stream
);
rt_err_t
(
*
stop
)(
struct
rt_audio_device
*
audio
,
int
stream
);
rt_size_t
(
*
transmit
)(
struct
rt_audio_device
*
audio
,
const
void
*
writeBuf
,
void
*
readBuf
,
rt_size_t
size
);
/* get page size of codec or private buffer's info */
void
(
*
buffer_info
)(
struct
rt_audio_device
*
audio
,
struct
rt_audio_buf_info
*
info
);
};
struct
rt_audio_configure
{
rt_uint32_t
channels
;
rt_uint32_t
samplefmt
;
rt_uint32_t
samplerate
;
rt_uint32_t
samplefmts
;
rt_uint16_t
channels
;
rt_uint16_t
samplebits
;
};
struct
rt_audio_caps
{
int
main_type
;
int
sub_type
;
union
{
rt_uint32_t
mask
;
int
value
;
struct
rt_audio_configure
config
;
}
udata
;
int
main_type
;
int
sub_type
;
union
{
rt_uint32_t
mask
;
int
value
;
struct
rt_audio_configure
config
;
}
udata
;
};
struct
rt_audio_replay
{
rt_bool_t
activated
;
struct
rt_mempool
*
mp
;
struct
rt_data_queue
queue
;
struct
rt_mutex
lock
;
struct
rt_completion
cmp
;
struct
rt_audio_buf_info
buf_info
;
rt_uint8_t
*
write_data
;
rt_uint16_t
write_index
;
rt_uint16_t
read_index
;
rt_uint32_t
pos
;
rt_uint8_t
event
;
rt_bool_t
activated
;
};
struct
rt_audio_record
{
struct
rt_audio_pipe
pipe
;
rt_bool_t
activated
;
};
struct
rt_audio_device
{
struct
rt_device
parent
;
struct
rt_device
parent
;
struct
rt_audio_ops
*
ops
;
struct
rt_mempool
mp
;
struct
rt_audio_replay
*
replay
;
struct
rt_audio_record
*
record
;
};
rt_err_t
rt_audio_register
(
struct
rt_audio_device
*
audio
,
const
char
*
name
,
rt_uint32_t
flag
,
void
*
data
);
void
rt_audio_tx_complete
(
struct
rt_audio_device
*
audio
,
rt_uint8_t
*
pbuf
);
void
rt_audio_rx_done
(
struct
rt_audio_device
*
audio
,
rt_uint8_t
*
pbuf
,
rt_size_t
len
);
rt_uint32_t
rt_audio_format_to_bits
(
rt_uint32_t
format
);
rt_err_t
rt_audio_register
(
struct
rt_audio_device
*
audio
,
const
char
*
name
,
rt_uint32_t
flag
,
void
*
data
);
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
);
/* Device Control Commands */
#define CODEC_CMD_RESET 0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录