我是 alsa 的新手,pulsAudio,需要帮助解决这个问题。
这是我的系统 pacmd list-sources 上 pacmd 命令的截断输出:
name: <alsa_input.pci-0000_00_1f.3.analog-stereo>
properties:
alsa.resolution_bits = "16"
device.profile.name = "analog-stereo"
device.profile.description = "Analog Stereo"
device.description = "Built-in Audio Analog Stereo"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-pci"
我想获取字段:device.description = "Built-in Audio Analog Stereo"使用一个简单的 C++ 程序
当我尝试使用获取描述时,
desc = snd_device_name_get_hint(*n, "DESC");
我得到同一设备的以下输出
Name of device: hw:CARD=PCH,DEV=0
Description of device: HDA Intel PCH, ALC3235 Analog
Direct hardware device without any conversions
I/O type of device: (null)
有没有办法可以获取类似于 pacmd 输出的描述?
如果不可能,是否有人知道如何从 pacmd 输出中获取名称: <alsa_input.pci-0000_00_1f.3.analog-stereo>字段。
我从官方页面尝试了一堆 pf API: https ://www.alsa-project.org/alsa-doc/alsa-lib/group___control.html 但没有运气
我目前正在运行的代码:
#include <alsa/asoundlib.h>
void listdev(char *devname)
{
char** hints;
int err;
char** n;
char* name;
char* desc;
char* ioid;
/* Enumerate sound devices */
err = snd_device_name_hint(-1, devname, (void***)&hints);
if (err != 0) {
fprintf(stderr, "*** Cannot get device names\n");
exit(1);
}
n = hints;
while (*n != NULL) {
name = snd_device_name_get_hint(*n, "NAME");
desc = snd_device_name_get_hint(*n, "DESC");
ioid = snd_device_name_get_hint(*n, "IOID");
printf("Name of device: %s\n", name);
printf("Description of device: %s\n", desc);
printf("I/O type of device: %s\n", ioid);
printf("\n");
if (name && strcmp("null", name)) free(name);
if (desc && strcmp("null", desc)) free(desc);
if (ioid && strcmp("null", ioid)) free(ioid);
n++;
}
//Free hint buffer too
snd_device_name_free_hint((void**)hints);
}