加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 查找我可以使用ALSA播放PCM的所有设备

发布时间:2020-12-14 01:22:02 所属栏目:Linux 来源:网络整理
导读:我使用ALSA播放PCM样本.我用这个函数打开PCM流: int snd_pcm_open(snd_pcm_t** pcmp,const char* name,snd_pcm_stream_t stream,int mode); 我目前正在使用“default”作为名称参数.我希望能够选择其他设备.我无法理解的是如何确定其他可用设备的名称. 我将
我使用ALSA播放PCM样本.我用这个函数打开PCM流:

int snd_pcm_open(snd_pcm_t** pcmp,const char* name,snd_pcm_stream_t stream,int mode);

我目前正在使用“default”作为名称参数.我希望能够选择其他设备.我无法理解的是如何确定其他可用设备的名称.

我将USB麦克风连接到我的系统,aplay和amixer似乎检测到了新设备.如何确定该设备的名称?是否有任何ALSA功能可以获取具有各自名称的可用设备列表?

解决方法

我认为您可以使用 snd_device_name_hint来枚举设备.
这是一个例子.请注意,我还没有编译它!

char **hints;
/* Enumerate sound devices */
int err = snd_device_name_hint(-1,"pcm",(void***)&hints);
if (err != 0)
   return;//Error! Just return

char** n = hints;
while (*n != NULL) {

    char *name = snd_device_name_get_hint(*n,"NAME");

    if (name != NULL && 0 != strcmp("null",name)) {
        //Copy name to another buffer and then free it
        free(name);
    }
    n++;
}//End of while

//Free hint buffer too
snd_device_name_free_hint((void**)hints);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读