I am trying to read data from multiple microphones in Linux (ubuntu 14.04). I have a specific constraint that the reading from microphones should be via polling(so no waiting until there is data, although the data comes in high frequency). I wanted to know if that is possible in Linux? Unfortunately audio capture is not the area of my expertise and I would like to know if the choice of using Alsa is a good one. To better understand the problem, here is a pseudo-code that I had in mind:
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();
My questions are 2 fold:
- Is Alsa a good choice for this?
- Can it be done somehow with some library that gives me a file descriptor so that I can use it with select function? if so this is optimal because there are other non-audio devices also working with select.
Thank you for your attention.
To prevent the
snd_pcm_read*()
calls from blocking, enable non-blocking mode with snd_pcm_nonblock().To get pollable file descriptors, call snd_pcm_poll_descriptors_count() and snd_pcm_poll_descriptors(). It is possible to have multiple descriptors because some plugins might implement notifications differently. To translate the result of a
poll()
on those descriptors back into aPOLLIN
/POLLOUT
value, call snd_pcm_poll_descriptors_revents().