我正在尝试从Linux中的多个麦克风读取数据(ubuntu 14.04)。我有一个特定的约束条件,即麦克风的读数应该通过轮询(所以不要等到有数据,尽管数据频率很高)。我想知道这在Linux中是否可行?不幸的是,音频捕获不是我的专业领域,我想知道使用Alsa的选择是否合适。为了更好地理解这个问题,这里有一个我想到的伪代码:
open_the_audio_device();
set_the_parameters_of_the_audio_device();
while (!done)
{
poll_result=poll_the_devices(); //other non-audio devices are also polled here preferably, something like using select on all different file descriptors of audio, video, socket, etc.
if(poll_success_for_audio_device)
receive_audio_from_the_device_that_has_data();
else
do_some_other_very_fast_stuff_and_start_loop_again();
}
close_the_device();
我的问题是2折:
感谢您的关注。
答案 0 :(得分:1)
要阻止snd_pcm_read*()
来电阻止,请使用snd_pcm_nonblock()启用非阻止模式。
要获取可轮询文件描述符,请致电snd_pcm_poll_descriptors_count()和snd_pcm_poll_descriptors()。
可能有多个描述符,因为某些插件可能以不同方式实现通知。
要将这些描述符上poll()
的结果转换回POLLIN
/ POLLOUT
值,请致电snd_pcm_poll_descriptors_revents()。