有没有办法使用 asoundlib 和 C 以编程方式获取系统上可用声卡的列表?我想要它具有相同的信息/proc/asound/cards
.
您可以使用迭代卡片snd_card_next
,从值-1开始获得第0张牌。
这是示例代码;编译它gcc -o countcards countcards.c -lasound
:
#include <alsa/asoundlib.h>
#include <stdio.h>
int main()
{
int totalCards = 0; // No cards found yet
int cardNum = -1; // Start with first card
int err;
for (;;) {
// Get next sound card's card number.
if ((err = snd_card_next(&cardNum)) < 0) {
fprintf(stderr, "Can't get the next card number: %s\n",
snd_strerror(err));
break;
}
if (cardNum < 0)
// No more cards
break;
++totalCards; // Another card found, so bump the count
}
printf("ALSA found %i card(s)\n", totalCards);
// ALSA allocates some memory to load its config file when we call
// snd_card_next. Now that we're done getting the info, tell ALSA
// to unload the info and release the memory.
snd_config_update_free_global();
}
这是代码减少自卡名.c https://gist.github.com/dontknowmyname/4536535(这也会打开每张卡片以读取其名称)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)