Reading Microphone Data by Polling using ALSA [or V4L2]

有些话、适合烂在心里 提交于 2020-01-25 11:03:25

问题


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:

  1. Is Alsa a good choice for this?
  2. 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.


回答1:


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 a POLLIN/POLLOUT value, call snd_pcm_poll_descriptors_revents().



来源:https://stackoverflow.com/questions/25822195/reading-microphone-data-by-polling-using-alsa-or-v4l2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!