使用ALSA 查询麦克风数据

我试图从Linux中的多个麦克风(Ubuntu 14.04)读取数据。 我有一个特定的限制,即麦克风的读数应该通过轮询(所以不要等到有数据,尽pipe数据频率很高)。 我想知道这在Linux中是否可行? 不幸的是audio捕捉不是我的专长领域,我想知道使用Alsa的select是否合适。 为了更好地理解这个问题,我想到了一个伪代码:

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倍:

  1. Alsa是一个不错的select吗?
  2. 它可以做某种库给我一个文件描述符,以便我可以使用它与selectfunction? 如果是这样,这是最佳的,因为还有其他非audio设备也与select工作。

感谢您的关注。

要阻止snd_pcm_read*()调用阻塞,请使用snd_pcm_nonblock()启用非阻塞模式。

要获得可轮询的文件描述符,请调用snd_pcm_poll_descriptors_count()和snd_pcm_poll_descriptors() 。 有可能有多个描述符,因为一些插件可能实现不同的通知。 要将这些描述符上poll()的结果转换回POLLIN / POLLOUT值,请调用snd_pcm_poll_descriptors_revents() 。