pcm

结构体

struct  aos_pcm_hw_params_t
 
struct  aos_pcm_sw_params_t
 
struct  aos_pcm_t
 
struct  hint_list_t
 

宏定义

#define AOS_PCM_BLOCK   0x00000000
 
#define AOS_PCM_NONBLOCK   0x00000001
 
#define AOS_PCM_ASYNC   0x00000002
 
#define AOS_PCM_ABORT   0x00008000
 
#define AOS_PCM_NO_AUTO_RESAMPLE   0x00010000
 
#define AOS_PCM_NO_AUTO_CHANNELS   0x00020000
 
#define AOS_PCM_NO_AUTO_FORMAT   0x00040000
 
#define AOS_PCM_NO_SOFTVOL   0x00080000
 
#define AOS_PCM_EVT_WRITE   (1 << 0)
 
#define AOS_PCM_EVT_READ   (1 << 1)
 
#define AOS_PCM_EVT_XRUN   (1 << 2)
 

类型定义

typedef unsigned long aos_pcm_uframes_t
 
typedef signed long aos_pcm_sframes_t
 

枚举

enum  aos_pcm_stream_t { AOS_PCM_STREAM_PLAYBACK = 0 , AOS_PCM_STREAM_CAPTURE , AOS_PCM_STREAM_LAST = AOS_PCM_STREAM_CAPTURE }
 
enum  aos_pcm_state_t {
  AOS_PCM_STATE_IDLE = 0 , AOS_PCM_STATE_OPEN , AOS_PCM_STATE_PREPARED , AOS_PCM_STATE_RUNNING ,
  AOS_PCM_STATE_XRUN , AOS_PCM_STATE_DRAINING , AOS_PCM_STATE_PAUSED , AOS_PCM_STATE_SUSPENDED ,
  AOS_PCM_STATE_DISCONNECTED , AOS_PCM_STATE_LAST = AOS_PCM_STATE_DISCONNECTED , AOS_PCM_STATE_PRIVATE1 = 1024
}
 
enum  aos_pcm_format_t {
  AOSRV_PCM_FORMAT_S8 = 1 , AOSRV_PCM_FORMAT_S16_LE = 2 , AOSRV_PCM_FORMAT_S24_LE = 3 , AOSRV_PCM_FORMAT_S32_LE = 4 ,
  AOSRV_PCM_FORMAT_ALL
}
 
enum  aos_pcm_access_t { AOS_PCM_ACCESS_MMAP_INTERLEAVED = 0 , AOS_PCM_ACCESS_MMAP_NONINTERLEAVED , AOS_PCM_ACCESS_RW_INTERLEAVED , AOS_PCM_ACCESS_RW_NONINTERLEAVED }
 

函数

int aos_device_name_hint (int card, void *hints)
 
int aos_pcm_open (aos_pcm_t **pcm, const char *name, aos_pcm_stream_t stream, int mode)
 
int aos_pcm_prepare (aos_pcm_t *pcm)
 
int aos_pcm_start (aos_pcm_t *pcm)
 
int aos_pcm_wait (aos_pcm_t *pcm, int timeout)
 
int aos_pcm_stop (aos_pcm_t *pcm)
 
int aos_pcm_drain (aos_pcm_t *pcm)
 
int aos_pcm_pause (aos_pcm_t *pcm, int enable)
 
int aos_pcm_close (aos_pcm_t *pcm)
 
int aos_pcm_recover (aos_pcm_t *pcm)
 
int aos_pcm_hw_params_alloca (aos_pcm_hw_params_t **p)
 
int aos_pcm_hw_params_any (aos_pcm_hw_params_t *params)
 
int aos_pcm_hw_params (aos_pcm_t *pcm, aos_pcm_hw_params_t *p)
 
int aos_pcm_set_params (aos_pcm_t *pcm, aos_pcm_format_t format, aos_pcm_access_t access, unsigned int channels, unsigned int rate, int soft_resample, unsigned int latency)
 
int aos_pcm_sw_params_alloca (aos_pcm_sw_params_t **p)
 
int aos_pcm_sw_params_any (aos_pcm_sw_params_t *params)
 
int aos_pcm_sw_params (aos_pcm_t *pcm, aos_pcm_sw_params_t *params)
 
aos_pcm_sframes_t aos_pcm_writei (aos_pcm_t *pcm, const void *buffer, aos_pcm_uframes_t size)
 
aos_pcm_sframes_t aos_pcm_readi (aos_pcm_t *pcm, void *buffer, aos_pcm_uframes_t size)
 
aos_pcm_sframes_t aos_pcm_writen (aos_pcm_t *pcm, void **bufs, aos_pcm_uframes_t size)
 
aos_pcm_sframes_t aos_pcm_readn (aos_pcm_t *pcm, void **bufs, aos_pcm_uframes_t size)
 
int aos_pcm_suspend (aos_pcm_t *pcm)
 
int aos_pcm_resume (aos_pcm_t *pcm)
 
aos_pcm_sframes_t aos_pcm_bytes_to_frames (aos_pcm_t *pcm, int bytes)
 
int aos_pcm_frames_to_bytes (aos_pcm_t *pcm, aos_pcm_sframes_t frames)
 

详细描述

宏定义说明

◆ AOS_PCM_ABORT

#define AOS_PCM_ABORT   0x00008000

In an abort state (internal, not allowed for open)

在文件 sound_pcm.h38 行定义.

◆ AOS_PCM_ASYNC

#define AOS_PCM_ASYNC   0x00000002

Async notification (flag for open mode)

在文件 sound_pcm.h37 行定义.

◆ AOS_PCM_BLOCK

#define AOS_PCM_BLOCK   0x00000000

Blocking mode (flag for open mode)

在文件 sound_pcm.h35 行定义.

◆ AOS_PCM_EVT_READ

#define AOS_PCM_EVT_READ   (1 << 1)

capture data available event

在文件 sound_pcm.h44 行定义.

◆ AOS_PCM_EVT_WRITE

#define AOS_PCM_EVT_WRITE   (1 << 0)

playback resource available event

在文件 sound_pcm.h43 行定义.

◆ AOS_PCM_EVT_XRUN

#define AOS_PCM_EVT_XRUN   (1 << 2)

underrun (playback) or overrun (capture) detected

在文件 sound_pcm.h45 行定义.

◆ AOS_PCM_NO_AUTO_CHANNELS

#define AOS_PCM_NO_AUTO_CHANNELS   0x00020000

Disable automatic (but not forced!) channel conversion

在文件 sound_pcm.h40 行定义.

◆ AOS_PCM_NO_AUTO_FORMAT

#define AOS_PCM_NO_AUTO_FORMAT   0x00040000

Disable automatic (but not forced!) format conversion

在文件 sound_pcm.h41 行定义.

◆ AOS_PCM_NO_AUTO_RESAMPLE

#define AOS_PCM_NO_AUTO_RESAMPLE   0x00010000

Disable automatic (but not forced!) rate resamplinig

在文件 sound_pcm.h39 行定义.

◆ AOS_PCM_NO_SOFTVOL

#define AOS_PCM_NO_SOFTVOL   0x00080000

Disable soft volume control

在文件 sound_pcm.h42 行定义.

◆ AOS_PCM_NONBLOCK

#define AOS_PCM_NONBLOCK   0x00000001

Non blocking mode (flag for open mode)

在文件 sound_pcm.h36 行定义.

类型定义说明

◆ aos_pcm_sframes_t

typedef signed long aos_pcm_sframes_t

在文件 sound_pcm.h32 行定义.

◆ aos_pcm_uframes_t

typedef unsigned long aos_pcm_uframes_t

在文件 sound_pcm.h31 行定义.

枚举类型说明

◆ aos_pcm_access_t

枚举值
AOS_PCM_ACCESS_MMAP_INTERLEAVED 

MMAP RW interleaved access

AOS_PCM_ACCESS_MMAP_NONINTERLEAVED 

MMAP RW non-interleaved access

AOS_PCM_ACCESS_RW_INTERLEAVED 

RW interleaved access, e.g. writei/readi

AOS_PCM_ACCESS_RW_NONINTERLEAVED 

RW non-interleaved access, e.g. writen/readn

在文件 sound_pcm.h79 行定义.

◆ aos_pcm_format_t

枚举值
AOSRV_PCM_FORMAT_S8 

Signed 8-bit

AOSRV_PCM_FORMAT_S16_LE 

Signed 16-bit, little endian

AOSRV_PCM_FORMAT_S24_LE 

Signed 24-bit, little endian

AOSRV_PCM_FORMAT_S32_LE 

Signed 32-bit, little endian

AOSRV_PCM_FORMAT_ALL 

在文件 sound_pcm.h70 行定义.

◆ aos_pcm_state_t

枚举值
AOS_PCM_STATE_IDLE 

IDLE

AOS_PCM_STATE_OPEN 

Open

AOS_PCM_STATE_PREPARED 

Ready to start

AOS_PCM_STATE_RUNNING 

Running

AOS_PCM_STATE_XRUN 

Stopped: underrun (playback) or overrun (capture) detected

AOS_PCM_STATE_DRAINING 

Draining: running (playback) or stopped (capture)

AOS_PCM_STATE_PAUSED 

Paused

AOS_PCM_STATE_SUSPENDED 

Hardware is suspended

AOS_PCM_STATE_DISCONNECTED 

Hardware is disconnected

AOS_PCM_STATE_LAST 

Last state

AOS_PCM_STATE_PRIVATE1 

Private - used internally in the library - do not use

在文件 sound_pcm.h55 行定义.

◆ aos_pcm_stream_t

枚举值
AOS_PCM_STREAM_PLAYBACK 

Playback stream

AOS_PCM_STREAM_CAPTURE 

Capture stream

AOS_PCM_STREAM_LAST 

在文件 sound_pcm.h48 行定义.

函数说明

◆ aos_device_name_hint()

int aos_device_name_hint ( int  card,
void *  hints 
)

获取声卡card下属所有的PCM Stream

参数
[in]card声卡ID
[out]hintshint_list_t类型列表
返回
0 on success, negative error on failure.

◆ aos_pcm_bytes_to_frames()

aos_pcm_sframes_t aos_pcm_bytes_to_frames ( aos_pcm_t pcm,
int  bytes 
)

根据pcm stream的参数配置计算bytes个字节对应的frame帧数

参数
[in]<em>pcmaos_pcm_t 类型
[in]bytes字节数
返回
aos_pcm_sframes_t on success, negative error on failure.

◆ aos_pcm_close()

int aos_pcm_close ( aos_pcm_t pcm)

关闭 PCM Stream

参数
[in]*pcmaos_pcm_t 句柄
返回
0 on success, negative error on failure.

◆ aos_pcm_drain()

int aos_pcm_drain ( aos_pcm_t pcm)

等待Playback PCM Stream buffer中的数据播放完成

参数
[in]*pcmaos_pcm_t 句柄
返回
0 on success, negative error on failure.

◆ aos_pcm_frames_to_bytes()

int aos_pcm_frames_to_bytes ( aos_pcm_t pcm,
aos_pcm_sframes_t  frames 
)

根据pcm stream的参数配置计算frame帧数对应的bytes字节数

参数
[in]<em>pcmaos_pcm_t 类型
[in]*frames帧数
返回
unsigned int on success, negative error on failure.

◆ aos_pcm_hw_params()

int aos_pcm_hw_params ( aos_pcm_t pcm,
aos_pcm_hw_params_t p 
)

设置pcm stream的硬件参数为 *p 指向的参数

参数
[in]<em>pcmaos_pcm_t 类型
[in]<em>paos_pcm_hw_params_t 类型
返回
0 on success, negative error on failure.

◆ aos_pcm_hw_params_alloca()

int aos_pcm_hw_params_alloca ( aos_pcm_hw_params_t **  p)

分配 aos_pcm_hw_params_t 类型缓存区

参数
[out]**paos_pcm_hw_params_t 类型2级指针
返回
0 on success, negative error on failure.

◆ aos_pcm_hw_params_any()

int aos_pcm_hw_params_any ( aos_pcm_hw_params_t params)

设置aos_pcm_hw_params_t 类型参数为默认参数

参数
[in]<em>paramsaos_pcm_hw_params_t 类型
返回
0 on success, negative error on failure.

◆ aos_pcm_open()

int aos_pcm_open ( aos_pcm_t **  pcm,
const char *  name,
aos_pcm_stream_t  stream,
int  mode 
)

获取声卡card下属所有的PCM Stream

参数
[out]**pcmaos_pcm_t 句柄指针
[in]*namepcm stream name
[in]streamaos_pcm_stream_t 类型
[in]modeAOS_PCM_BLOCK 或者 AOS_PCM_NONBLOCK
返回
0 on success, negative error on failure.

◆ aos_pcm_pause()

int aos_pcm_pause ( aos_pcm_t pcm,
int  enable 
)

暂停 PCM Stream

参数
[in]*pcmaos_pcm_t 句柄
返回
0 on success, negative error on failure.

◆ aos_pcm_prepare()

int aos_pcm_prepare ( aos_pcm_t pcm)

设置PCM Stream为prepared状态

参数
[in]*pcmaos_pcm_t 句柄
返回
0 on success, negative error on failure.

◆ aos_pcm_readi()

aos_pcm_sframes_t aos_pcm_readi ( aos_pcm_t pcm,
void *  buffer,
aos_pcm_uframes_t  size 
)

以interleave格式从pcm stream读数据(e.g. CH0 -> CH1 -> CH2 -> CH0 ...)

参数
[in]<em>pcmaos_pcm_t 类型
[in]*buffer存储读出数据的buffer
[in]*size待读出的数据大小,以字节为单位
返回
read bytes number on success, negative error on failure.

◆ aos_pcm_readn()

aos_pcm_sframes_t aos_pcm_readn ( aos_pcm_t pcm,
void **  bufs,
aos_pcm_uframes_t  size 
)

以non-interleave格式从pcm stream读数据(e.g. CH0 -> CH0 ...-> CH0 (size 单位数据全部读完) -> CH1 -> CH1 ...)

参数
[in]<em>pcmaos_pcm_t 类型
[in]*buffer存储读出数据的buffer
[in]*size待读出的数据大小,以字节为单位
返回
read bytes number on success, negative error on failure.

◆ aos_pcm_recover()

int aos_pcm_recover ( aos_pcm_t pcm)

恢复 PCM Stream 底层硬件状态(可选)

参数
[in]*pcmaos_pcm_t 句柄
返回
0 on success, negative error on failure.

◆ aos_pcm_resume()

int aos_pcm_resume ( aos_pcm_t pcm)

恢复pcm stream,buffer中遗留的数据继续读写

参数
[in]<em>pcmaos_pcm_t 类型
返回
0 on success, negative error on failure.

◆ aos_pcm_set_params()

int aos_pcm_set_params ( aos_pcm_t pcm,
aos_pcm_format_t  format,
aos_pcm_access_t  access,
unsigned int  channels,
unsigned int  rate,
int  soft_resample,
unsigned int  latency 
)

根据输入参数设置pcm stream的硬件参数

参数
[in]<em>pcmaos_pcm_t 类型
[in]formataos_pcm_format_t 类型
[in]accessaos_pcm_access_t 类型
[in]channelsunsigned int 类型, 通道数
[in]rateunsigned int 类型, 采样率
[in]soft_resampleint 类型
[in]latencyunsigned int 类型
返回
0 on success, negative error on failure.

◆ aos_pcm_start()

int aos_pcm_start ( aos_pcm_t pcm)

设置PCM Stream为START状态

参数
[in]*pcmaos_pcm_t 句柄
返回
0 on success, negative error on failure.

◆ aos_pcm_stop()

int aos_pcm_stop ( aos_pcm_t pcm)

停止PCM Stream

参数
[in]*pcmaos_pcm_t 句柄
返回
0 on success, negative error on failure.

◆ aos_pcm_suspend()

int aos_pcm_suspend ( aos_pcm_t pcm)

暂停pcm stream,buffer中的数据仍然保留

参数
[in]<em>pcmaos_pcm_t 类型
返回
0 on success, negative error on failure.

◆ aos_pcm_sw_params()

int aos_pcm_sw_params ( aos_pcm_t pcm,
aos_pcm_sw_params_t params 
)

设置pcm stream的软件参数为 *params 指向的参数

参数
[in]<em>pcmaos_pcm_t 类型
[in]<em>paramsaos_pcm_sw_params_t 类型
返回
0 on success, negative error on failure.

◆ aos_pcm_sw_params_alloca()

int aos_pcm_sw_params_alloca ( aos_pcm_sw_params_t **  p)

分配 aos_pcm_sw_params_t 类型缓存区

参数
[in]**paos_pcm_sw_params_t* 类型
返回
0 on success, negative error on failure.

◆ aos_pcm_sw_params_any()

int aos_pcm_sw_params_any ( aos_pcm_sw_params_t params)

设置 aos_pcm_sw_params_t 类型参数为默认参数

参数
[in]<em>paramsaos_pcm_sw_params_t 类型
返回
0 on success, negative error on failure.

◆ aos_pcm_wait()

int aos_pcm_wait ( aos_pcm_t pcm,
int  timeout 
)

设置PCM Stream为wait状态, 最大超时时间timeout milisecond

参数
[in]*pcmaos_pcm_t 句柄
[in]timeout超时时间,毫秒为单位
返回
0 on success, negative error on failure.

◆ aos_pcm_writei()

aos_pcm_sframes_t aos_pcm_writei ( aos_pcm_t pcm,
const void *  buffer,
aos_pcm_uframes_t  size 
)

以interleave格式往pcm stream写数据(e.g. CH0 -> CH1 -> CH2 -> CH0 ...)

参数
[in]<em>pcmaos_pcm_t 类型
[in]*buffer待写入的数据buffer
[in]*size待写入的数据buffer大小,以字节为单位
返回
writen bytes number on success, negative error on failure.

◆ aos_pcm_writen()

aos_pcm_sframes_t aos_pcm_writen ( aos_pcm_t pcm,
void **  bufs,
aos_pcm_uframes_t  size 
)

以non-interleave格式往pcm stream写数据(e.g. CH0 -> CH0 ...-> CH0 (size 单位数据全部写完) -> CH1 -> CH1 ...)

参数
[in]<em>pcmaos_pcm_t 类型
[in]*buffer待写入的数据buffer
[in]*size待写入的数据buffer大小,以字节为单位
返回
writen bytes number on success, negative error on failure.