Linux系统查声卡ID,以编程方式在Linux上查找可用的声卡

您可以使用snd_card_next迭代卡片,从值-1开始以获得第0张卡片.

这是示例代码;用gcc -o countcards countcards.c -lasound编译它:

#include

#include

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();

}

这是从cardnames.c减少的代码(也打开每张卡以读取其名称).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值