林尝试使用ALSA从USB音频设备获取用户输入并写入到磁盘的一系列signed short
值。 什么我结束了有什么似乎是用零的大块穿插有效的数据块。 我猜,我有我的缓冲区设置不正确,我不恰当地使用内存映射。
我试图:
- 采样率:8K(这是由该装置被迫)
- 缓冲区大小:2048
- 期大小:512
- 一个通道
该设备似乎被正确打开,并接受各种PARAMS。 一些设置后循环形式运行:
snd_pcm_avail_update
snd_pcm_mmap_begin
memcpy data from mmap buffer to array of short
snd_pcm_mmap_commit
所述的memcpy是指向的短阵列,并且通过返回的每个通帧的数量递增。
在此之后记录几秒钟我关闭它,写随后的缓冲到磁盘上每行一个短值。 我很期待是第二个或两个PCM数据1200和2300赫兹之间变化。 什么我得到一些数据,有很多零。
我想知道的是:是我的缓冲期和值合理? 有没有人成功地使用从ALSA映射输出的内存?
编辑:一些代码
const snd_pcm_channel_area_t *areas;
snd_pcm_uframes_t offset, frames, size;
short* pCID = (short*)malloc( 50000 * sizeof( short ));
short* ppCID = pCID;
while( size > 0 )
{
frames = size;
snd_pcm_mmap_begin (device, &areas, &offset, &frames);
short* pd = (short*)areas[0].addr;
memcpy( ppCID, (pd + (offset*sizeof(short))), frames * sizeof( short ));
ppCID += frames;
snd_pcm_mmap_commit(device, offset, frames);
size -= frames;
}
(为了清楚起见移除检查错误)
当一切都说过和做过通过PCID我环路和写入磁盘。 每行一个值。