gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:04:25 36 4
gpt4 key购买 nike

我正在尝试从 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/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com