码迷,mamicode.com
首页 > 其他好文 > 详细

alsa接口

时间:2020-06-05 00:47:51      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:play   str   ams   inter   channel   channels   设备   and   hand   

■ 基本流程

打开设备

设置参数

获取fd

poll

写入数据/读取数据

关闭

 

■ 写入数据

snd_pcm_open(&u->pcm_handle, dev = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)

snd_pcm_hw_params_malloc(&hwparams)
snd_pcm_hw_params_any(pcm_handle, hwparams)
snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)
snd_pcm_hw_params_set_format(pcm_handle, hwparams, format_trans[ss->format])
snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &ss->rate, NULL)
snd_pcm_hw_params_set_channels(pcm_handle, hwparams, ss->channels)
snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, periods, NULL)
snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, buffer_size)
snd_pcm_hw_params(pcm_handle, hwparams)
snd_pcm_hw_params_free(hwparams)

*n_io_sources = snd_pcm_poll_descriptors_count(pcm_handle)
snd_pcm_poll_descriptors(pcm_handle, pfds, *n_io_sources)

poll

snd_pcm_prepare(u->pcm_handle)
snd_pcm_writei(u->pcm_handle, memchunk->memblock->data + memchunk->index, memchunk->length / u->frame_size)

snd_pcm_drop(u->pcm_handle)
snd_pcm_close(u->pcm_handle)

 

■ 读取数据

snd_pcm_open(&u->pcm_handle, dev = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK) < 0) {


snd_pcm_hw_params_malloc(&hwparams)
snd_pcm_hw_params_any(pcm_handle, hwparams)
snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)
snd_pcm_hw_params_set_format(pcm_handle, hwparams, format_trans[ss->format])
snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &ss->rate, NULL)
snd_pcm_hw_params_set_channels(pcm_handle, hwparams, ss->channels)
snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, periods, NULL)
snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, buffer_size)
snd_pcm_hw_params(pcm_handle, hwparams)
snd_pcm_hw_params_free(hwparams)


snd_pcm_poll_descriptors_count(pcm_handle)
snd_pcm_poll_descriptors(pcm_handle, pfds, *n_io_sources)


poll

snd_pcm_state(u->pcm_handle)
snd_pcm_prepare(u->pcm_handle)

snd_pcm_readi(u->pcm_handle, u->memchunk.memblock->data + u->memchunk.index, u->memchunk.length / u->frame_size))

snd_pcm_drop(u->pcm_handle);
snd_pcm_close(u->pcm_handle);

alsa接口

标签:play   str   ams   inter   channel   channels   设备   and   hand   

原文地址:https://www.cnblogs.com/renhl/p/13047309.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!