linux - 使用 ALSA [或 V4L2] 通过轮询读取麦克风数据

标签 linux alsa multimedia v4l2

我正在尝试从 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();

我的问题有两个:

  1. Alsa 是一个不错的选择吗?
  2. 是否可以通过某种库来完成,给我一个文件描述符,以便我可以将它与 select 函数一起使用?如果是这样,这是最佳选择,因为还有其他非音频设备也可以使用 select。

感谢您的关注。

最佳答案

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

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

关于linux - 使用 ALSA [或 V4L2] 通过轮询读取麦克风数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25822195/

相关文章:

java - 检索视频的缩略图

silverlight - 为什么 Silverlight 在没有任何编码 API 的情况下提供网络摄像头和麦克风支持?

actionscript-3 - 如何从 Actionscript 3.0 使多个视频剪辑同时播放

linux - ngserve 无法在 Ubuntu 上启动 Anguiar

linux - makefile 在其依赖项中两次替换目标模式

c - Alsa 库 32 位

google-chrome - Chromium --alsa-output-device 标志不起作用

linux - 从文本文件进入一行并编辑它

linux - 无法在 RHEL 上打开显示

python - 如何以编程方式更改 Ubuntu 中的音量